Socket
Socket
Sign inDemoInstall

starknet

Package Overview
Dependencies
Maintainers
1
Versions
220
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

starknet - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

__tests__/__snapshots__/ellipticalCurve.test.ts.snap

23

__tests__/contracts.test.ts

@@ -1,13 +0,12 @@

import { BigNumber } from '@ethersproject/bignumber';
import fs from 'fs';
import {
CompiledContract,
Contract,
deployContract,
JsonParser,
randomAddress,
waitForTx,
} from '../src';
const compiledERC20: CompiledContract = JsonParser.parse(
import { CompiledContract, Contract, deployContract, utils, waitForTx } from '../src';
const {
json: { parse },
number: { toBN },
starknet: { randomAddress },
} = utils;
const compiledERC20: CompiledContract = parse(
fs.readFileSync('./__mocks__/ERC20.json').toString('ascii')

@@ -32,3 +31,3 @@ );

});
expect(BigNumber.from(response.res)).toStrictEqual(BigNumber.from(0));
expect(toBN(response.res as string).toString()).toStrictEqual(toBN(0).toString());
});

@@ -52,4 +51,4 @@ test('add 10 test ERC20 to account', async () => {

expect(BigNumber.from(response.res)).toStrictEqual(BigNumber.from(10));
expect(toBN(response.res as string).toString()).toStrictEqual(toBN(10).toString());
});
});

@@ -6,5 +6,12 @@ /**

import fs from 'fs';
import { compressProgram, isBrowser, JsonParser } from '../src';
const compiledArgentAccount = JsonParser.parse(
import { constants, utils } from '../src';
const { IS_BROWSER } = constants;
const {
json: { parse, stringify },
starknet: { compressProgram },
} = utils;
const compiledArgentAccount = parse(
fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')

@@ -14,3 +21,3 @@ );

test('isBrowser', () => {
expect(isBrowser).toBe(true);
expect(IS_BROWSER).toBe(true);
});

@@ -26,3 +33,3 @@ describe('compressProgram()', () => {

test('works with strings', () => {
const inputProgram = JsonParser.stringify(compiledArgentAccount.program);
const inputProgram = stringify(compiledArgentAccount.program);

@@ -29,0 +36,0 @@ const compressed = compressProgram(inputProgram);

import fs from 'fs';
import { compressProgram, makeAddress, isBrowser, JsonParser, getSelectorFromName } from '../src';
const compiledArgentAccount = JsonParser.parse(
import { constants, utils } from '../src';
const { IS_BROWSER } = constants;
const {
json: { parse, stringify },
starknet: { compressProgram, getSelectorFromName, makeAddress },
number: { hexToDecimalString },
} = utils;
const compiledArgentAccount = parse(
fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')

@@ -9,3 +17,3 @@ );

test('isNode', () => {
expect(isBrowser).toBe(false);
expect(IS_BROWSER).toBe(false);
});

@@ -21,3 +29,3 @@ describe('compressProgram()', () => {

test('works with strings', () => {
const inputProgram = JsonParser.stringify(compiledArgentAccount.program);
const inputProgram = stringify(compiledArgentAccount.program);

@@ -29,2 +37,8 @@ const compressed = compressProgram(inputProgram);

});
describe('hexToDecimalString()', () => {
test('parse 0xa23', () => {
expect(hexToDecimalString('0xa23')).toBe('2595');
});
});
describe('makeAddress()', () => {

@@ -39,3 +53,3 @@ test('test on eth address', () => {

});
describe('starknetKeccak()', () => {
describe('getSelectorFromName()', () => {
test('hash works for value="test"', () => {

@@ -53,5 +67,5 @@ expect(getSelectorFromName('test')).toBe(

expect(getSelectorFromName('mint')).toBe(
'0x02f0b3c5710379609eb5495f1ecd348cb28167711b73609fe565a72734550354'
'0x2f0b3c5710379609eb5495f1ecd348cb28167711b73609fe565a72734550354'
);
});
});

@@ -0,1 +1,18 @@

# [1.4.0](https://github.com/seanjameshan/starknet.js/compare/v1.3.0...v1.4.0) (2021-10-29)
### Bug Fixes
- cleanup ([82aa438](https://github.com/seanjameshan/starknet.js/commit/82aa438ea08f1d3577ee23ea083f58caf42cbdba))
- keep tests files consistent ([e343b55](https://github.com/seanjameshan/starknet.js/commit/e343b551fb422a0d337f905eca981dbabf1ae097))
- push renamed snapshot ([643cd40](https://github.com/seanjameshan/starknet.js/commit/643cd40a0f0b996424517d71cdf6c5d70857a7c3))
- remove enc-utils to remove buffer dep ([e08e4b5](https://github.com/seanjameshan/starknet.js/commit/e08e4b53bfbdece3f824fedf96101405219da4b5))
- rename tests ([b4d15a7](https://github.com/seanjameshan/starknet.js/commit/b4d15a7e32abf5eb90f1efbf9e1773b42574be49))
- update argent wallet implementation ([63cc278](https://github.com/seanjameshan/starknet.js/commit/63cc2780eb44347d42ccf50dc917633eee975c5b))
- update snapshots after contract upgrade ([2a1dcde](https://github.com/seanjameshan/starknet.js/commit/2a1dcde6bcaff09a45e091d194840bd66a568c67))
- use function consistently ([67617d7](https://github.com/seanjameshan/starknet.js/commit/67617d73bb414b950ad8d2e347ade6a49d6fc595))
### Features
- wip ([42a8ab1](https://github.com/seanjameshan/starknet.js/commit/42a8ab1b0f998d88d8fc7349b33d5287c017d4b5))
# [1.3.0](https://github.com/seanjameshan/starknet.js/compare/v1.2.0...v1.3.0) (2021-10-28)

@@ -2,0 +19,0 @@

@@ -1,3 +0,19 @@

export declare const CONTRACT_ADDRESS_BITS = 251;
export declare const CONTRACT_ADDRESS_LOWER_BOUND = 1;
export declare const CONTRACT_ADDRESS_UPPER_BOUND: number;
/// <reference types="bn.js" />
export { IS_BROWSER } from './utils/encode';
export declare const ZERO: import('bn.js');
export declare const ONE: import('bn.js');
export declare const TWO: import('bn.js');
export declare const MASK_250: import('bn.js');
/**
* The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
* Please do not edit until the JSON changes.
*/
export declare const FIELD_PRIME =
'800000000000011000000000000000000000000000000000000000000000001';
export declare const FIELD_GEN = '3';
export declare const EC_ORDER = '800000000000010FFFFFFFFFFFFFFFFB781126DCAE7B2321E66A241ADC64D2F';
export declare const ALPHA = '1';
export declare const BETA = '6F21413EFBE40DE150E596D72F7A8C5609AD26C15C915C1F4CDFCB99CEE9E89';
export declare const MAX_ECDSA_VAL =
'800000000000000000000000000000000000000000000000000000000000000';
export declare const CONSTANT_POINTS: string[][];

@@ -5,2 +5,3 @@ import { Abi } from './types';

};
declare type Calldata = string[];
export declare class Contract {

@@ -17,3 +18,3 @@ connectedTo: string | null;

connect(address: string): Contract;
private static compileCalldata;
static compileCalldata(args: Args): Calldata;
private validateMethodAndArgs;

@@ -20,0 +21,0 @@ private parseResponse;

@@ -188,14 +188,14 @@ 'use strict';

exports.Contract = void 0;
var assert_1 = __importDefault(require('assert'));
var bignumber_1 = require('@ethersproject/bignumber');
var utils_1 = require('./utils');
var minimalistic_assert_1 = __importDefault(require('minimalistic-assert'));
var starknet_1 = require('./starknet');
var parseFelt = function (candidate) {
var number_1 = require('./utils/number');
var starknet_2 = require('./utils/starknet');
function parseFelt(candidate) {
try {
return bignumber_1.BigNumber.from(candidate);
return (0, number_1.toBN)(candidate);
} catch (e) {
throw Error('Couldnt parse felt');
}
};
var isFelt = function (candidate) {
}
function isFelt(candidate) {
try {

@@ -207,3 +207,3 @@ parseFelt(candidate);

}
};
}
var Contract = /** @class */ (function () {

@@ -232,6 +232,6 @@ /**

return __spreadArray(
[bignumber_1.BigNumber.from(value.length).toString()],
[(0, number_1.toBN)(value.length).toString()],
__read(
value.map(function (x) {
return bignumber_1.BigNumber.from(x).toString();
return (0, number_1.toBN)(x).toString();
})

@@ -241,3 +241,3 @@ ),

);
return bignumber_1.BigNumber.from(value).toString();
return (0, number_1.toBN)(value).toString();
});

@@ -259,3 +259,3 @@ };

});
(0, assert_1.default)(
(0, minimalistic_assert_1.default)(
invokeableFunctionNames.includes(method),

@@ -269,24 +269,24 @@ (type === 'INVOKE' ? 'invokeable' : 'viewable') + ' method not found in abi'

methodAbi.inputs.forEach(function (input) {
(0,
assert_1.default)(args[input.name] !== undefined, 'no arg for "' + input.name + '" provided');
if (input.type === 'felt') {
(0, assert_1.default)(
typeof args[input.name] === 'string',
'arg ' + input.name + ' should be a felt (string)'
);
(0, assert_1.default)(
isFelt(args[input.name]),
'arg ' + input.name + ' should be decimal or hexadecimal'
);
} else {
(0, assert_1.default)(
Array.isArray(args[input.name]),
'arg ' + input.name + ' should be a felt* (string[])'
);
args[input.name].forEach(function (felt, i) {
(0,
assert_1.default)(typeof felt === 'string', 'arg ' + input.name + '[' + i + '] should be a felt (string) as part of a felt* (string[])');
(0,
assert_1.default)(isFelt(felt), 'arg ' + input.name + '[' + i + '] should be decimal or hexadecimal as part of a felt* (string[])');
});
if (args[input.name] !== undefined) {
if (input.type === 'felt') {
(0, minimalistic_assert_1.default)(
typeof args[input.name] === 'string',
'arg ' + input.name + ' should be a felt (string)'
);
(0, minimalistic_assert_1.default)(
isFelt(args[input.name]),
'arg ' + input.name + ' should be decimal or hexadecimal'
);
} else {
(0, minimalistic_assert_1.default)(
Array.isArray(args[input.name]),
'arg ' + input.name + ' should be a felt* (string[])'
);
args[input.name].forEach(function (felt, i) {
(0,
minimalistic_assert_1.default)(typeof felt === 'string', 'arg ' + input.name + '[' + i + '] should be a felt (string) as part of a felt* (string[])');
(0,
minimalistic_assert_1.default)(isFelt(felt), 'arg ' + input.name + '[' + i + '] should be decimal or hexadecimal as part of a felt* (string[])');
});
}
}

@@ -309,7 +309,10 @@ });

// ensure contract is connected
(0, assert_1.default)(this.connectedTo !== null, 'contract isnt connected to an address');
(0, minimalistic_assert_1.default)(
this.connectedTo !== null,
'contract isnt connected to an address'
);
// validate method and args
this.validateMethodAndArgs('INVOKE', method, args);
// compile calldata
var entrypointSelector = (0, utils_1.getSelectorFromName)(method);
var entrypointSelector = (0, starknet_2.getSelectorFromName)(method);
var calldata = Contract.compileCalldata(args);

@@ -332,6 +335,7 @@ return (0, starknet_1.addTransaction)({

// ensure contract is connected
(0, assert_1.default)(this.connectedTo !== null, 'contract isnt connected to an address');
(0,
minimalistic_assert_1.default)(this.connectedTo !== null, 'contract isnt connected to an address');
// validate method and args
this.validateMethodAndArgs('CALL', method, args);
entrypointSelector = (0, utils_1.getSelectorFromName)(method);
entrypointSelector = (0, starknet_2.getSelectorFromName)(method);
calldata = Contract.compileCalldata(args);

@@ -338,0 +342,0 @@ return [

@@ -1,3 +0,17 @@

export declare const CONTRACT_ADDRESS_BITS = 251;
export declare const CONTRACT_ADDRESS_LOWER_BOUND = 1;
export declare const CONTRACT_ADDRESS_UPPER_BOUND: number;
/// <reference types="bn.js" />
export { IS_BROWSER } from './utils/encode';
export declare const ZERO: import("bn.js");
export declare const ONE: import("bn.js");
export declare const TWO: import("bn.js");
export declare const MASK_250: import("bn.js");
/**
* The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
* Please do not edit until the JSON changes.
*/
export declare const FIELD_PRIME = "800000000000011000000000000000000000000000000000000000000000001";
export declare const FIELD_GEN = "3";
export declare const EC_ORDER = "800000000000010FFFFFFFFFFFFFFFFB781126DCAE7B2321E66A241ADC64D2F";
export declare const ALPHA = "1";
export declare const BETA = "6F21413EFBE40DE150E596D72F7A8C5609AD26C15C915C1F4CDFCB99CEE9E89";
export declare const MAX_ECDSA_VAL = "800000000000000000000000000000000000000000000000000000000000000";
export declare const CONSTANT_POINTS: string[][];

@@ -5,2 +5,3 @@ import { Abi } from './types';

};
declare type Calldata = string[];
export declare class Contract {

@@ -17,3 +18,3 @@ connectedTo: string | null;

connect(address: string): Contract;
private static compileCalldata;
static compileCalldata(args: Args): Calldata;
private validateMethodAndArgs;

@@ -20,0 +21,0 @@ private parseResponse;

@@ -79,9 +79,9 @@ "use strict";

exports.Contract = void 0;
var assert_1 = __importDefault(require("assert"));
var bignumber_1 = require("@ethersproject/bignumber");
var utils_1 = require("./utils");
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
var starknet_1 = require("./starknet");
var parseFelt = function (candidate) {
var number_1 = require("./utils/number");
var starknet_2 = require("./utils/starknet");
function parseFelt(candidate) {
try {
return bignumber_1.BigNumber.from(candidate);
return (0, number_1.toBN)(candidate);
}

@@ -91,4 +91,4 @@ catch (e) {

}
};
var isFelt = function (candidate) {
}
function isFelt(candidate) {
try {

@@ -101,3 +101,3 @@ parseFelt(candidate);

}
};
}
var Contract = /** @class */ (function () {

@@ -123,6 +123,4 @@ /**

if (Array.isArray(value))
return __spreadArray([
bignumber_1.BigNumber.from(value.length).toString()
], __read(value.map(function (x) { return bignumber_1.BigNumber.from(x).toString(); })), false);
return bignumber_1.BigNumber.from(value).toString();
return __spreadArray([(0, number_1.toBN)(value.length).toString()], __read(value.map(function (x) { return (0, number_1.toBN)(x).toString(); })), false);
return (0, number_1.toBN)(value).toString();
});

@@ -140,18 +138,19 @@ };

.map(function (abi) { return abi.name; });
(0, assert_1.default)(invokeableFunctionNames.includes(method), (type === 'INVOKE' ? 'invokeable' : 'viewable') + " method not found in abi");
(0, minimalistic_assert_1.default)(invokeableFunctionNames.includes(method), (type === 'INVOKE' ? 'invokeable' : 'viewable') + " method not found in abi");
// ensure args match abi type
var methodAbi = this.abi.find(function (abi) { return abi.name === method; });
methodAbi.inputs.forEach(function (input) {
(0, assert_1.default)(args[input.name] !== undefined, "no arg for \"" + input.name + "\" provided");
if (input.type === 'felt') {
(0, assert_1.default)(typeof args[input.name] === 'string', "arg " + input.name + " should be a felt (string)");
(0, assert_1.default)(isFelt(args[input.name]), "arg " + input.name + " should be decimal or hexadecimal");
if (args[input.name] !== undefined) {
if (input.type === 'felt') {
(0, minimalistic_assert_1.default)(typeof args[input.name] === 'string', "arg " + input.name + " should be a felt (string)");
(0, minimalistic_assert_1.default)(isFelt(args[input.name]), "arg " + input.name + " should be decimal or hexadecimal");
}
else {
(0, minimalistic_assert_1.default)(Array.isArray(args[input.name]), "arg " + input.name + " should be a felt* (string[])");
args[input.name].forEach(function (felt, i) {
(0, minimalistic_assert_1.default)(typeof felt === 'string', "arg " + input.name + "[" + i + "] should be a felt (string) as part of a felt* (string[])");
(0, minimalistic_assert_1.default)(isFelt(felt), "arg " + input.name + "[" + i + "] should be decimal or hexadecimal as part of a felt* (string[])");
});
}
}
else {
(0, assert_1.default)(Array.isArray(args[input.name]), "arg " + input.name + " should be a felt* (string[])");
args[input.name].forEach(function (felt, i) {
(0, assert_1.default)(typeof felt === 'string', "arg " + input.name + "[" + i + "] should be a felt (string) as part of a felt* (string[])");
(0, assert_1.default)(isFelt(felt), "arg " + input.name + "[" + i + "] should be decimal or hexadecimal as part of a felt* (string[])");
});
}
});

@@ -169,7 +168,7 @@ };

// ensure contract is connected
(0, assert_1.default)(this.connectedTo !== null, 'contract isnt connected to an address');
(0, minimalistic_assert_1.default)(this.connectedTo !== null, 'contract isnt connected to an address');
// validate method and args
this.validateMethodAndArgs('INVOKE', method, args);
// compile calldata
var entrypointSelector = (0, utils_1.getSelectorFromName)(method);
var entrypointSelector = (0, starknet_2.getSelectorFromName)(method);
var calldata = Contract.compileCalldata(args);

@@ -190,6 +189,6 @@ return (0, starknet_1.addTransaction)({

// ensure contract is connected
(0, assert_1.default)(this.connectedTo !== null, 'contract isnt connected to an address');
(0, minimalistic_assert_1.default)(this.connectedTo !== null, 'contract isnt connected to an address');
// validate method and args
this.validateMethodAndArgs('CALL', method, args);
entrypointSelector = (0, utils_1.getSelectorFromName)(method);
entrypointSelector = (0, starknet_2.getSelectorFromName)(method);
calldata = Contract.compileCalldata(args);

@@ -196,0 +195,0 @@ return [2 /*return*/, (0, starknet_1.callContract)({

@@ -1,4 +0,7 @@

export * from './utils';
export * from './types';
export * from './contract';
export * from './wallet';
export * from './starknet';
export { pedersen } from './utils/hash';
export * as constants from './constants';
export * as utils from './utils';

@@ -9,9 +9,26 @@ "use strict";

}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./utils"), exports);
exports.utils = exports.constants = exports.pedersen = void 0;
__exportStar(require("./types"), exports);
__exportStar(require("./contract"), exports);
__exportStar(require("./wallet"), exports);
__exportStar(require("./starknet"), exports);
var hash_1 = require("./utils/hash");
Object.defineProperty(exports, "pedersen", { enumerable: true, get: function () { return hash_1.pedersen; } });
exports.constants = __importStar(require("./constants"));
exports.utils = __importStar(require("./utils"));

@@ -1,3 +0,3 @@

import { compressProgram } from './utils';
import type { GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Transaction, AddTransactionResponse, CompiledContract, Call, CallContractResponse } from './types';
import type { AddTransactionResponse, Call, CallContractResponse, CompiledContract, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Transaction } from './types';
import { compressProgram } from './utils/starknet';
/**

@@ -4,0 +4,0 @@ * Gets the smart contract address on the goerli testnet.

@@ -55,3 +55,4 @@ "use strict";

var axios_1 = __importDefault(require("axios"));
var utils_1 = require("./utils");
var json_1 = require("./utils/json");
var starknet_1 = require("./utils/starknet");
var API_URL = 'https://alpha2.starknet.io';

@@ -223,5 +224,5 @@ var FEEDER_GATEWAY_URL = API_URL + "/feeder_gateway";

function deployContract(contract, address) {
if (address === void 0) { address = (0, utils_1.randomAddress)(); }
var parsedContract = typeof contract === 'string' ? utils_1.JsonParser.parse(contract) : contract;
var contractDefinition = __assign(__assign({}, parsedContract), { program: (0, utils_1.compressProgram)(parsedContract.program) });
if (address === void 0) { address = (0, starknet_1.randomAddress)(); }
var parsedContract = typeof contract === 'string' ? (0, json_1.parse)(contract) : contract;
var contractDefinition = __assign(__assign({}, parsedContract), { program: (0, starknet_1.compressProgram)(parsedContract.program) });
return addTransaction({

@@ -234,3 +235,5 @@ type: 'DEPLOY',

exports.deployContract = deployContract;
var wait = function (delay) { return new Promise(function (res) { return setTimeout(res, delay); }); };
function wait(delay) {
return new Promise(function (res) { return setTimeout(res, delay); });
}
function waitForTx(txId, retryInterval) {

@@ -283,4 +286,4 @@ if (retryInterval === void 0) { retryInterval = 2000; }

addTransaction: addTransaction,
compressProgram: utils_1.compressProgram,
compressProgram: starknet_1.compressProgram,
deployContract: deployContract,
};

@@ -1,4 +0,7 @@

export * from './utils';
export * from './types';
export * from './contract';
export * from './wallet';
export * from './starknet';
export { pedersen } from './utils/hash';
export * as constants from './constants';
export * as utils from './utils';

@@ -18,2 +18,11 @@ 'use strict';

});
var __setModuleDefault =
(this && this.__setModuleDefault) ||
(Object.create
? function (o, v) {
Object.defineProperty(o, 'default', { enumerable: true, value: v });
}
: function (o, v) {
o['default'] = v;
});
var __exportStar =

@@ -26,6 +35,28 @@ (this && this.__exportStar) ||

};
var __importStar =
(this && this.__importStar) ||
function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, '__esModule', { value: true });
__exportStar(require('./utils'), exports);
exports.utils = exports.constants = exports.pedersen = void 0;
__exportStar(require('./types'), exports);
__exportStar(require('./contract'), exports);
__exportStar(require('./wallet'), exports);
__exportStar(require('./starknet'), exports);
var hash_1 = require('./utils/hash');
Object.defineProperty(exports, 'pedersen', {
enumerable: true,
get: function () {
return hash_1.pedersen;
},
});
exports.constants = __importStar(require('./constants'));
exports.utils = __importStar(require('./utils'));
{
"name": "starknet",
"version": "1.3.0",
"version": "1.4.0",
"description": "JavaScript library for StarkNet",

@@ -38,4 +38,6 @@ "main": "dist/index.js",

"@semantic-release/release-notes-generator": "^10.0.2",
"@types/elliptic": "^6.4.13",
"@types/jest": "^27.0.2",
"@types/json-bigint": "^1.0.1",
"@types/minimalistic-assert": "^1.0.1",
"@types/pako": "^1.0.2",

@@ -51,5 +53,7 @@ "@typescript-eslint/eslint-plugin": "^5.0.0",

"husky": "^7.0.2",
"import-sort-style-module": "^6.0.0",
"jest": "^27.3.0",
"lint-staged": "^11.2.3",
"prettier": "^2.4.1",
"prettier-plugin-import-sort": "^0.0.7",
"typedoc": "^0.22.6",

@@ -59,6 +63,9 @@ "typescript": "^4.4.4"

"dependencies": {
"@ethersproject/bignumber": "^5.5.0",
"axios": "^0.23.0",
"bn.js": "^5.2.0",
"elliptic": "^6.5.4",
"ethereum-cryptography": "^0.2.0",
"hash.js": "^1.1.7",
"json-bigint": "^1.0.0",
"minimalistic-assert": "^1.0.1",
"pako": "^2.0.4"

@@ -72,3 +79,9 @@ },

"testTimeout": 300000
},
"importSort": {
".js, .jsx, .ts, .tsx": {
"style": "module",
"parser": "typescript"
}
}
}

@@ -1,6 +0,8 @@

import assert from 'assert';
import { BigNumber } from '@ethersproject/bignumber';
import BN from 'bn.js';
import assert from 'minimalistic-assert';
import { addTransaction, callContract } from './starknet';
import { Abi } from './types';
import { getSelectorFromName } from './utils';
import { addTransaction, callContract } from './starknet';
import { toBN } from './utils/number';
import { getSelectorFromName } from './utils/starknet';

@@ -10,11 +12,11 @@ type Args = { [inputName: string]: string | string[] };

const parseFelt = (candidate: string): BigNumber => {
function parseFelt(candidate: string): BN {
try {
return BigNumber.from(candidate);
return toBN(candidate);
} catch (e) {
throw Error('Couldnt parse felt');
}
};
}
const isFelt = (candidate: string): boolean => {
function isFelt(candidate: string): boolean {
try {

@@ -26,3 +28,3 @@ parseFelt(candidate);

}
};
}

@@ -50,10 +52,7 @@ export class Contract {

private static compileCalldata(args: Args): Calldata {
public static compileCalldata(args: Args): Calldata {
return Object.values(args).flatMap((value) => {
if (Array.isArray(value))
return [
BigNumber.from(value.length).toString(),
...value.map((x) => BigNumber.from(x).toString()),
];
return BigNumber.from(value).toString();
return [toBN(value.length).toString(), ...value.map((x) => toBN(x).toString())];
return toBN(value).toString();
});

@@ -79,21 +78,25 @@ }

methodAbi.inputs.forEach((input) => {
assert(args[input.name] !== undefined, `no arg for "${input.name}" provided`);
if (input.type === 'felt') {
assert(typeof args[input.name] === 'string', `arg ${input.name} should be a felt (string)`);
assert(
isFelt(args[input.name] as string),
`arg ${input.name} should be decimal or hexadecimal`
);
} else {
assert(Array.isArray(args[input.name]), `arg ${input.name} should be a felt* (string[])`);
(args[input.name] as string[]).forEach((felt, i) => {
if (args[input.name] !== undefined) {
if (input.type === 'felt') {
assert(
typeof felt === 'string',
`arg ${input.name}[${i}] should be a felt (string) as part of a felt* (string[])`
typeof args[input.name] === 'string',
`arg ${input.name} should be a felt (string)`
);
assert(
isFelt(felt),
`arg ${input.name}[${i}] should be decimal or hexadecimal as part of a felt* (string[])`
isFelt(args[input.name] as string),
`arg ${input.name} should be decimal or hexadecimal`
);
});
} else {
assert(Array.isArray(args[input.name]), `arg ${input.name} should be a felt* (string[])`);
(args[input.name] as string[]).forEach((felt, i) => {
assert(
typeof felt === 'string',
`arg ${input.name}[${i}] should be a felt (string) as part of a felt* (string[])`
);
assert(
isFelt(felt),
`arg ${input.name}[${i}] should be decimal or hexadecimal as part of a felt* (string[])`
);
});
}
}

@@ -100,0 +103,0 @@ });

@@ -1,4 +0,9 @@

export * from './utils';
export * from './types';
export * from './contract';
export * from './wallet';
export * from './starknet';
export { pedersen } from './utils/hash';
export * as constants from './constants';
export * as utils from './utils';
import axios from 'axios';
import { randomAddress, compressProgram, JsonParser } from './utils';
import type {
AddTransactionResponse,
Call,
CallContractResponse,
CompiledContract,
GetBlockResponse,

@@ -10,7 +14,5 @@ GetCodeResponse,

Transaction,
AddTransactionResponse,
CompiledContract,
Call,
CallContractResponse,
} from './types';
import { parse } from './utils/json';
import { compressProgram, randomAddress } from './utils/starknet';

@@ -202,3 +204,3 @@ const API_URL = 'https://alpha2.starknet.io';

const parsedContract =
typeof contract === 'string' ? (JsonParser.parse(contract) as CompiledContract) : contract;
typeof contract === 'string' ? (parse(contract) as CompiledContract) : contract;
const contractDefinition = {

@@ -216,3 +218,5 @@ ...parsedContract,

const wait = (delay: number) => new Promise((res) => setTimeout(res, delay));
function wait(delay: number) {
return new Promise((res) => setTimeout(res, delay));
}
export async function waitForTx(txId: number, retryInterval: number = 2000) {

@@ -219,0 +223,0 @@ let onchain = false;

@@ -1,3 +0,6 @@

import { compressProgram } from './utils';
import type {
AddTransactionResponse,
Call,
CallContractResponse,
CompiledContract,
GetBlockResponse,

@@ -9,7 +12,4 @@ GetCodeResponse,

Transaction,
AddTransactionResponse,
CompiledContract,
Call,
CallContractResponse,
} from './types';
import { compressProgram } from './utils/starknet';
/**

@@ -16,0 +16,0 @@ * Gets the smart contract address on the goerli testnet.

@@ -165,3 +165,4 @@ 'use strict';

var axios_1 = __importDefault(require('axios'));
var utils_1 = require('./utils');
var json_1 = require('./utils/json');
var starknet_1 = require('./utils/starknet');
var API_URL = 'https://alpha2.starknet.io';

@@ -357,7 +358,7 @@ var FEEDER_GATEWAY_URL = API_URL + '/feeder_gateway';

if (address === void 0) {
address = (0, utils_1.randomAddress)();
address = (0, starknet_1.randomAddress)();
}
var parsedContract = typeof contract === 'string' ? utils_1.JsonParser.parse(contract) : contract;
var parsedContract = typeof contract === 'string' ? (0, json_1.parse)(contract) : contract;
var contractDefinition = __assign(__assign({}, parsedContract), {
program: (0, utils_1.compressProgram)(parsedContract.program),
program: (0, starknet_1.compressProgram)(parsedContract.program),
});

@@ -371,7 +372,7 @@ return addTransaction({

exports.deployContract = deployContract;
var wait = function (delay) {
function wait(delay) {
return new Promise(function (res) {
return setTimeout(res, delay);
});
};
}
function waitForTx(txId, retryInterval) {

@@ -429,4 +430,4 @@ if (retryInterval === void 0) {

addTransaction: addTransaction,
compressProgram: utils_1.compressProgram,
compressProgram: starknet_1.compressProgram,
deployContract: deployContract,
};

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc