starknet 2.2.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/__tests__/account.test.ts +3 -3
- package/__tests__/signer.test.ts +17 -0
- package/__tests__/utils/ellipticalCurve.test.ts +1 -1
- package/__tests__/utils/shortString.test.ts +22 -0
- package/__tests__/utils/typedData.test.ts +72 -0
- package/__tests__/utils/uint256.test.ts +32 -0
- package/constants.d.ts +5 -5
- package/contract.d.ts +9 -3
- package/contract.js +23 -5
- package/dist/constants.d.ts +5 -5
- package/dist/contract.d.ts +6 -3
- package/dist/contract.js +19 -5
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -1
- package/dist/provider/default.d.ts +6 -6
- package/dist/provider/default.js +18 -17
- package/dist/provider/interface.d.ts +6 -6
- package/dist/signer/default.d.ts +20 -3
- package/dist/signer/default.js +61 -20
- package/dist/signer/interface.d.ts +22 -3
- package/dist/types.d.ts +7 -5
- package/dist/utils/ellipticCurve.d.ts +8 -1
- package/dist/utils/ellipticCurve.js +48 -9
- package/dist/utils/shortString.d.ts +4 -0
- package/dist/utils/shortString.js +26 -0
- package/dist/utils/stark.d.ts +2 -3
- package/dist/utils/typedData/index.d.ts +91 -0
- package/dist/utils/typedData/index.js +183 -0
- package/dist/utils/typedData/types.d.ts +82 -0
- package/dist/utils/typedData/types.js +47 -0
- package/dist/utils/typedData/utils.d.ts +24 -0
- package/dist/utils/typedData/utils.js +15 -0
- package/dist/utils/uint256.d.ts +11 -0
- package/dist/utils/uint256.js +28 -0
- package/index.d.ts +3 -0
- package/index.js +7 -1
- package/package.json +3 -1
- package/provider/default.d.ts +9 -5
- package/provider/default.js +21 -19
- package/provider/interface.d.ts +6 -5
- package/signer/default.d.ts +20 -3
- package/signer/default.js +60 -17
- package/signer/interface.d.ts +22 -3
- package/src/constants.ts +4 -6
- package/src/contract.ts +17 -14
- package/src/index.ts +3 -0
- package/src/provider/default.ts +15 -13
- package/src/provider/interface.ts +6 -5
- package/src/signer/default.ts +49 -17
- package/src/signer/interface.ts +26 -3
- package/src/types.ts +13 -5
- package/src/utils/ellipticCurve.ts +31 -9
- package/src/utils/shortString.ts +21 -0
- package/src/utils/stark.ts +4 -4
- package/src/utils/typedData/index.ts +176 -0
- package/src/utils/typedData/types.ts +82 -0
- package/src/utils/typedData/utils.ts +13 -0
- package/src/utils/uint256.ts +32 -0
- package/types.d.ts +9 -6
- package/utils/ellipticCurve.d.ts +12 -1
- package/utils/ellipticCurve.js +72 -23
- package/utils/shortString.d.ts +4 -0
- package/utils/shortString.js +34 -0
- package/utils/stark.d.ts +2 -3
- package/utils/typedData/index.d.ts +113 -0
- package/utils/typedData/index.js +247 -0
- package/utils/typedData/types.d.ts +103 -0
- package/utils/typedData/types.js +57 -0
- package/utils/typedData/utils.d.ts +27 -0
- package/utils/typedData/utils.js +15 -0
- package/utils/uint256.d.ts +11 -0
- package/utils/uint256.js +38 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
# [2.5.0](https://github.com/seanjameshan/starknet.js/compare/v2.4.0...v2.5.0) (2021-12-13)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- add jsdoc comment ([4cd969f](https://github.com/seanjameshan/starknet.js/commit/4cd969f82eb4a5d8c08feb59c42fb3e7195af50e))
|
|
6
|
+
- remove eip712 reference ([039a360](https://github.com/seanjameshan/starknet.js/commit/039a360873f9a1cdedc7a498b6e1732183957143))
|
|
7
|
+
- remove unused types ([e528f7d](https://github.com/seanjameshan/starknet.js/commit/e528f7d75f4560d2affe3ca99426e01fbee6dfb5))
|
|
8
|
+
- review ([a3813c9](https://github.com/seanjameshan/starknet.js/commit/a3813c9931c178d58c2521b926fb3fdff6944635))
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
- add `getKeyPairFromPublicKey` method ([66d543d](https://github.com/seanjameshan/starknet.js/commit/66d543dca1bb302654f0f1588a27f7794bfa49be))
|
|
13
|
+
- add tests ([b414a83](https://github.com/seanjameshan/starknet.js/commit/b414a839a1fdd56084a58d6efb4747e8f5455628))
|
|
14
|
+
- allow multi sig ([fc1e086](https://github.com/seanjameshan/starknet.js/commit/fc1e0866154d2bf29f26374639a34fec438bae5e))
|
|
15
|
+
- support eip712 for starknet ([d597082](https://github.com/seanjameshan/starknet.js/commit/d59708211fc497d801699a7168dad1a5cc9648fd))
|
|
16
|
+
|
|
17
|
+
# [2.4.0](https://github.com/seanjameshan/starknet.js/compare/v2.3.1...v2.4.0) (2021-12-09)
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
- allow custom nonce ([17666de](https://github.com/seanjameshan/starknet.js/commit/17666de94db6875bbf8e88555773b8862a4a32cf))
|
|
22
|
+
|
|
23
|
+
## [2.3.1](https://github.com/seanjameshan/starknet.js/compare/v2.3.0...v2.3.1) (2021-12-01)
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
- allow structs in calldata ([fd2bdc0](https://github.com/seanjameshan/starknet.js/commit/fd2bdc0a1756544e4162fa5baaa7d3aec6f97bee))
|
|
28
|
+
- struct compiling ([84617ae](https://github.com/seanjameshan/starknet.js/commit/84617aefe1218f421ca446b2a3c9959252d326e6))
|
|
29
|
+
- struct data ([313dff5](https://github.com/seanjameshan/starknet.js/commit/313dff57f54050747c65b32b3378762c349d9c8c))
|
|
30
|
+
- uint256 type ([2e05902](https://github.com/seanjameshan/starknet.js/commit/2e05902268f76bda2ae9b4e75782fa78876c2f00))
|
|
31
|
+
|
|
32
|
+
# [2.3.0](https://github.com/seanjameshan/starknet.js/compare/v2.2.0...v2.3.0) (2021-12-01)
|
|
33
|
+
|
|
34
|
+
### Features
|
|
35
|
+
|
|
36
|
+
- add compileStructToCalldata ([e5bdb18](https://github.com/seanjameshan/starknet.js/commit/e5bdb1890e0bc53b03d4b145069cf7fbc639e830))
|
|
37
|
+
- **utils:** support shortstring and uint256 ([f7ff057](https://github.com/seanjameshan/starknet.js/commit/f7ff05753d9bc39b31bdd4e7f893ee04cab77823))
|
|
38
|
+
|
|
1
39
|
# [2.2.0](https://github.com/seanjameshan/starknet.js/compare/v2.1.0...v2.2.0) (2021-11-30)
|
|
2
40
|
|
|
3
41
|
### Bug Fixes
|
|
@@ -104,7 +104,7 @@ describe('deploy and test Wallet', () => {
|
|
|
104
104
|
)
|
|
105
105
|
);
|
|
106
106
|
|
|
107
|
-
const
|
|
107
|
+
const signature = ec.sign(starkKeyPair, msgHash);
|
|
108
108
|
const { code, transaction_hash } = await wallet.invoke(
|
|
109
109
|
'execute',
|
|
110
110
|
{
|
|
@@ -113,7 +113,7 @@ describe('deploy and test Wallet', () => {
|
|
|
113
113
|
calldata: [erc20Address, '10'],
|
|
114
114
|
nonce: nonce.toString(),
|
|
115
115
|
},
|
|
116
|
-
|
|
116
|
+
signature
|
|
117
117
|
);
|
|
118
118
|
|
|
119
119
|
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
@@ -151,7 +151,7 @@ test('build tx', async () => {
|
|
|
151
151
|
.toString()
|
|
152
152
|
);
|
|
153
153
|
|
|
154
|
-
const
|
|
154
|
+
const [r, s] = ec.sign(keyPair, msgHash);
|
|
155
155
|
expect(r.toString()).toBe(
|
|
156
156
|
'706800951915233622090196542158919402159816118214143837213294331713137614072'
|
|
157
157
|
);
|
package/__tests__/signer.test.ts
CHANGED
|
@@ -99,4 +99,21 @@ describe('deploy and test Wallet', () => {
|
|
|
99
99
|
|
|
100
100
|
expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(990).toString());
|
|
101
101
|
});
|
|
102
|
+
test('execute with custom nonce', async () => {
|
|
103
|
+
const { result } = await signer.callContract({
|
|
104
|
+
contract_address: signer.address,
|
|
105
|
+
entry_point_selector: stark.getSelectorFromName('get_nonce'),
|
|
106
|
+
});
|
|
107
|
+
const nonce = parseInt(result[0], 10);
|
|
108
|
+
const { code, transaction_hash } = await signer.addTransaction({
|
|
109
|
+
type: 'INVOKE_FUNCTION',
|
|
110
|
+
contract_address: erc20Address,
|
|
111
|
+
entry_point_selector: stark.getSelectorFromName('transfer'),
|
|
112
|
+
calldata: [erc20Address, '10'],
|
|
113
|
+
nonce,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
117
|
+
await defaultProvider.waitForTx(transaction_hash);
|
|
118
|
+
});
|
|
102
119
|
});
|
|
@@ -40,7 +40,7 @@ test('hashMessage()', () => {
|
|
|
40
40
|
);
|
|
41
41
|
expect(hashMsg).toBe('0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbddd');
|
|
42
42
|
const keyPair = getKeyPair(privateKey);
|
|
43
|
-
const
|
|
43
|
+
const [r, s] = sign(keyPair, removeHexPrefix(hashMsg));
|
|
44
44
|
expect(r.toString()).toStrictEqual(
|
|
45
45
|
toBN('2458502865976494910213617956670505342647705497324144349552978333078363662855').toString()
|
|
46
46
|
);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { decodeShortString, encodeShortString } from '../../src/utils/shortString';
|
|
2
|
+
|
|
3
|
+
describe('shortString', () => {
|
|
4
|
+
test('should convert string to number', () => {
|
|
5
|
+
expect(encodeShortString('hello')).toMatchInlineSnapshot(`"0x68656c6c6f"`);
|
|
6
|
+
});
|
|
7
|
+
test('should convert number to string', () => {
|
|
8
|
+
expect(decodeShortString('0x68656c6c6f')).toMatchInlineSnapshot(`"hello"`);
|
|
9
|
+
});
|
|
10
|
+
test('should throw if string is too long', () => {
|
|
11
|
+
expect(() =>
|
|
12
|
+
encodeShortString('hello world hello world hello world hello world hello world hello world')
|
|
13
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
14
|
+
`"hello world hello world hello world hello world hello world hello world is too long"`
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
test('should throw if string contains non ascii chars', () => {
|
|
18
|
+
expect(() => encodeShortString('hello\uD83D\uDE00')).toThrowErrorMatchingInlineSnapshot(
|
|
19
|
+
`"hello😀 is not an ASCII string"`
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { encodeType, getMessageHash, getStructHash, getTypeHash } from '../../src/utils/typedData';
|
|
2
|
+
|
|
3
|
+
const typedDataExample = {
|
|
4
|
+
types: {
|
|
5
|
+
StarkNetDomain: [
|
|
6
|
+
{ name: 'name', type: 'felt' },
|
|
7
|
+
{ name: 'version', type: 'felt' },
|
|
8
|
+
{ name: 'chainId', type: 'felt' },
|
|
9
|
+
],
|
|
10
|
+
Person: [
|
|
11
|
+
{ name: 'name', type: 'felt' },
|
|
12
|
+
{ name: 'wallet', type: 'felt' },
|
|
13
|
+
],
|
|
14
|
+
Mail: [
|
|
15
|
+
{ name: 'from', type: 'Person' },
|
|
16
|
+
{ name: 'to', type: 'Person' },
|
|
17
|
+
{ name: 'contents', type: 'felt' },
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
primaryType: 'Mail',
|
|
21
|
+
domain: {
|
|
22
|
+
name: 'StarkNet Mail',
|
|
23
|
+
version: '1',
|
|
24
|
+
chainId: 1,
|
|
25
|
+
},
|
|
26
|
+
message: {
|
|
27
|
+
from: {
|
|
28
|
+
name: 'Cow',
|
|
29
|
+
wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
|
|
30
|
+
},
|
|
31
|
+
to: {
|
|
32
|
+
name: 'Bob',
|
|
33
|
+
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
|
34
|
+
},
|
|
35
|
+
contents: 'Hello, Bob!',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
describe('typedData', () => {
|
|
40
|
+
test('should get right type encoding', () => {
|
|
41
|
+
const typeEncoding = encodeType(typedDataExample, 'Mail');
|
|
42
|
+
expect(typeEncoding).toMatchInlineSnapshot(
|
|
43
|
+
`"Mail(from:Person,to:Person,contents:felt)Person(name:felt,wallet:felt)"`
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
test('should get right type hash', () => {
|
|
47
|
+
const typeHashDomain = getTypeHash(typedDataExample, 'StarkNetDomain');
|
|
48
|
+
expect(typeHashDomain).toMatchInlineSnapshot(
|
|
49
|
+
`"0x1bfc207425a47a5dfa1a50a4f5241203f50624ca5fdf5e18755765416b8e288"`
|
|
50
|
+
);
|
|
51
|
+
const typeHashPerson = getTypeHash(typedDataExample, 'Person');
|
|
52
|
+
expect(typeHashPerson).toMatchInlineSnapshot(
|
|
53
|
+
`"0x2896dbe4b96a67110f454c01e5336edc5bbc3635537efd690f122f4809cc855"`
|
|
54
|
+
);
|
|
55
|
+
const typeHashMail = getTypeHash(typedDataExample, 'Mail');
|
|
56
|
+
expect(typeHashMail).toMatchInlineSnapshot(
|
|
57
|
+
`"0x13d89452df9512bf750f539ba3001b945576243288137ddb6c788457d4b2f79"`
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
test('should get right hash for StarkNetDomain', () => {
|
|
61
|
+
const hash = getStructHash(typedDataExample, 'StarkNetDomain', typedDataExample.domain as any);
|
|
62
|
+
expect(hash).toMatchInlineSnapshot(
|
|
63
|
+
`"0x54833b121883a3e3aebff48ec08a962f5742e5f7b973469c1f8f4f55d470b07"`
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
test('should get right hash for entire message', () => {
|
|
67
|
+
const hash = getMessageHash(typedDataExample, '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826');
|
|
68
|
+
expect(hash).toMatchInlineSnapshot(
|
|
69
|
+
`"0x6fcff244f63e38b9d88b9e3378d44757710d1b244282b435cb472053c8d78d0"`
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ONE } from '../../src/constants';
|
|
2
|
+
import { toBN } from '../../src/utils/number';
|
|
3
|
+
import { UINT_128_MAX, UINT_256_MAX, bnToUint256, uint256ToBN } from '../../src/utils/uint256';
|
|
4
|
+
|
|
5
|
+
describe('cairo uint256', () => {
|
|
6
|
+
test('should convert 0 from BN to uint256 struct', () => {
|
|
7
|
+
const uint256 = bnToUint256('0');
|
|
8
|
+
expect(uint256).toMatchInlineSnapshot(`
|
|
9
|
+
Object {
|
|
10
|
+
"high": "0x0",
|
|
11
|
+
"low": "0x0",
|
|
12
|
+
}
|
|
13
|
+
`);
|
|
14
|
+
});
|
|
15
|
+
test('should convert 0 from uint256 to BN', () => {
|
|
16
|
+
expect(uint256ToBN({ low: '0x0', high: '0x0' }).toString()).toMatchInlineSnapshot(`"0"`);
|
|
17
|
+
});
|
|
18
|
+
test('should convert BN over 2^128 to uint256 struct', () => {
|
|
19
|
+
const uint256 = bnToUint256(UINT_128_MAX.add(ONE));
|
|
20
|
+
expect(uint256).toMatchInlineSnapshot(`
|
|
21
|
+
Object {
|
|
22
|
+
"high": "0x1",
|
|
23
|
+
"low": "0x0",
|
|
24
|
+
}
|
|
25
|
+
`);
|
|
26
|
+
});
|
|
27
|
+
test('should throw if BN over uint256 range', () => {
|
|
28
|
+
expect(() => bnToUint256(UINT_256_MAX.add(toBN(1)))).toThrowErrorMatchingInlineSnapshot(
|
|
29
|
+
`"Number is too large"`
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
});
|
package/constants.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
2
|
export { IS_BROWSER } from './utils/encode';
|
|
3
|
-
export declare const ZERO:
|
|
4
|
-
export declare const ONE:
|
|
5
|
-
export declare const TWO:
|
|
6
|
-
export declare const MASK_250:
|
|
3
|
+
export declare const ZERO: import('bn.js');
|
|
4
|
+
export declare const ONE: import('bn.js');
|
|
5
|
+
export declare const TWO: import('bn.js');
|
|
6
|
+
export declare const MASK_250: import('bn.js');
|
|
7
7
|
/**
|
|
8
8
|
* 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
|
|
9
9
|
* Please do not edit until the JSON changes.
|
package/contract.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { Provider } from './provider';
|
|
2
|
-
import { Abi, StructAbi } from './types';
|
|
2
|
+
import { Abi, Signature, StructAbi } from './types';
|
|
3
3
|
import { BigNumberish } from './utils/number';
|
|
4
4
|
export declare type Args = {
|
|
5
|
-
[inputName: string]:
|
|
5
|
+
[inputName: string]:
|
|
6
|
+
| string
|
|
7
|
+
| string[]
|
|
8
|
+
| {
|
|
9
|
+
type: 'struct';
|
|
10
|
+
[k: string]: BigNumberish;
|
|
11
|
+
};
|
|
6
12
|
};
|
|
7
13
|
export declare type Calldata = string[];
|
|
8
14
|
export declare function compileCalldata(args: Args): Calldata;
|
|
@@ -27,7 +33,7 @@ export declare class Contract {
|
|
|
27
33
|
invoke(
|
|
28
34
|
method: string,
|
|
29
35
|
args?: Args,
|
|
30
|
-
signature?:
|
|
36
|
+
signature?: Signature
|
|
31
37
|
): Promise<import('./types').AddTransactionResponse>;
|
|
32
38
|
call(method: string, args?: Args): Promise<Args>;
|
|
33
39
|
}
|
package/contract.js
CHANGED
|
@@ -216,6 +216,18 @@ function compileCalldata(args) {
|
|
|
216
216
|
),
|
|
217
217
|
false
|
|
218
218
|
);
|
|
219
|
+
if (typeof value === 'object' && 'type' in value)
|
|
220
|
+
return Object.entries(value)
|
|
221
|
+
.filter(function (_a) {
|
|
222
|
+
var _b = __read(_a, 1),
|
|
223
|
+
k = _b[0];
|
|
224
|
+
return k !== 'type';
|
|
225
|
+
})
|
|
226
|
+
.map(function (_a) {
|
|
227
|
+
var _b = __read(_a, 2),
|
|
228
|
+
v = _b[1];
|
|
229
|
+
return (0, number_1.toBN)(v).toString();
|
|
230
|
+
});
|
|
219
231
|
return (0, number_1.toBN)(value).toString();
|
|
220
232
|
});
|
|
221
233
|
}
|
|
@@ -274,22 +286,28 @@ var Contract = /** @class */ (function () {
|
|
|
274
286
|
return abi.name === method && abi.type === 'function';
|
|
275
287
|
});
|
|
276
288
|
methodAbi.inputs.forEach(function (input) {
|
|
277
|
-
|
|
289
|
+
var arg = args[input.name];
|
|
290
|
+
if (arg !== undefined) {
|
|
278
291
|
if (input.type === 'felt') {
|
|
279
292
|
(0, minimalistic_assert_1.default)(
|
|
280
|
-
typeof
|
|
293
|
+
typeof arg === 'string',
|
|
281
294
|
'arg ' + input.name + ' should be a felt (string)'
|
|
282
295
|
);
|
|
283
296
|
(0, minimalistic_assert_1.default)(
|
|
284
|
-
isFelt(
|
|
297
|
+
isFelt(arg),
|
|
285
298
|
'arg ' + input.name + ' should be decimal or hexadecimal'
|
|
286
299
|
);
|
|
300
|
+
} else if (typeof arg === 'object' && 'type' in arg) {
|
|
301
|
+
(0, minimalistic_assert_1.default)(
|
|
302
|
+
arg.type === 'struct',
|
|
303
|
+
'arg ' + input.name + ' should be a struct'
|
|
304
|
+
);
|
|
287
305
|
} else {
|
|
288
306
|
(0, minimalistic_assert_1.default)(
|
|
289
|
-
Array.isArray(
|
|
307
|
+
Array.isArray(arg),
|
|
290
308
|
'arg ' + input.name + ' should be a felt* (string[])'
|
|
291
309
|
);
|
|
292
|
-
|
|
310
|
+
arg.forEach(function (felt, i) {
|
|
293
311
|
(0,
|
|
294
312
|
minimalistic_assert_1.default)(typeof felt === 'string', 'arg ' + input.name + '[' + i + '] should be a felt (string) as part of a felt* (string[])');
|
|
295
313
|
(0,
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
2
|
export { IS_BROWSER } from './utils/encode';
|
|
3
|
-
export declare const ZERO:
|
|
4
|
-
export declare const ONE:
|
|
5
|
-
export declare const TWO:
|
|
6
|
-
export declare const MASK_250:
|
|
3
|
+
export declare const ZERO: import("bn.js");
|
|
4
|
+
export declare const ONE: import("bn.js");
|
|
5
|
+
export declare const TWO: import("bn.js");
|
|
6
|
+
export declare const MASK_250: import("bn.js");
|
|
7
7
|
/**
|
|
8
8
|
* 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
|
|
9
9
|
* Please do not edit until the JSON changes.
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Provider } from './provider';
|
|
2
|
-
import { Abi, StructAbi } from './types';
|
|
2
|
+
import { Abi, Signature, StructAbi } from './types';
|
|
3
3
|
import { BigNumberish } from './utils/number';
|
|
4
4
|
export declare type Args = {
|
|
5
|
-
[inputName: string]: string | string[]
|
|
5
|
+
[inputName: string]: string | string[] | {
|
|
6
|
+
type: 'struct';
|
|
7
|
+
[k: string]: BigNumberish;
|
|
8
|
+
};
|
|
6
9
|
};
|
|
7
10
|
export declare type Calldata = string[];
|
|
8
11
|
export declare function compileCalldata(args: Args): Calldata;
|
|
@@ -24,6 +27,6 @@ export declare class Contract {
|
|
|
24
27
|
private validateMethodAndArgs;
|
|
25
28
|
private parseResponseField;
|
|
26
29
|
private parseResponse;
|
|
27
|
-
invoke(method: string, args?: Args, signature?:
|
|
30
|
+
invoke(method: string, args?: Args, signature?: Signature): Promise<import("./types").AddTransactionResponse>;
|
|
28
31
|
call(method: string, args?: Args): Promise<Args>;
|
|
29
32
|
}
|
package/dist/contract.js
CHANGED
|
@@ -101,6 +101,16 @@ function compileCalldata(args) {
|
|
|
101
101
|
return Object.values(args).flatMap(function (value) {
|
|
102
102
|
if (Array.isArray(value))
|
|
103
103
|
return __spreadArray([(0, number_1.toBN)(value.length).toString()], __read(value.map(function (x) { return (0, number_1.toBN)(x).toString(); })), false);
|
|
104
|
+
if (typeof value === 'object' && 'type' in value)
|
|
105
|
+
return Object.entries(value)
|
|
106
|
+
.filter(function (_a) {
|
|
107
|
+
var _b = __read(_a, 1), k = _b[0];
|
|
108
|
+
return k !== 'type';
|
|
109
|
+
})
|
|
110
|
+
.map(function (_a) {
|
|
111
|
+
var _b = __read(_a, 2), v = _b[1];
|
|
112
|
+
return (0, number_1.toBN)(v).toString();
|
|
113
|
+
});
|
|
104
114
|
return (0, number_1.toBN)(value).toString();
|
|
105
115
|
});
|
|
106
116
|
}
|
|
@@ -145,14 +155,18 @@ var Contract = /** @class */ (function () {
|
|
|
145
155
|
// ensure args match abi type
|
|
146
156
|
var methodAbi = this.abi.find(function (abi) { return abi.name === method && abi.type === 'function'; });
|
|
147
157
|
methodAbi.inputs.forEach(function (input) {
|
|
148
|
-
|
|
158
|
+
var arg = args[input.name];
|
|
159
|
+
if (arg !== undefined) {
|
|
149
160
|
if (input.type === 'felt') {
|
|
150
|
-
(0, minimalistic_assert_1.default)(typeof
|
|
151
|
-
(0, minimalistic_assert_1.default)(isFelt(
|
|
161
|
+
(0, minimalistic_assert_1.default)(typeof arg === 'string', "arg " + input.name + " should be a felt (string)");
|
|
162
|
+
(0, minimalistic_assert_1.default)(isFelt(arg), "arg " + input.name + " should be decimal or hexadecimal");
|
|
163
|
+
}
|
|
164
|
+
else if (typeof arg === 'object' && 'type' in arg) {
|
|
165
|
+
(0, minimalistic_assert_1.default)(arg.type === 'struct', "arg " + input.name + " should be a struct");
|
|
152
166
|
}
|
|
153
167
|
else {
|
|
154
|
-
(0, minimalistic_assert_1.default)(Array.isArray(
|
|
155
|
-
|
|
168
|
+
(0, minimalistic_assert_1.default)(Array.isArray(arg), "arg " + input.name + " should be a felt* (string[])");
|
|
169
|
+
arg.forEach(function (felt, i) {
|
|
156
170
|
(0, minimalistic_assert_1.default)(typeof felt === 'string', "arg " + input.name + "[" + i + "] should be a felt (string) as part of a felt* (string[])");
|
|
157
171
|
(0, minimalistic_assert_1.default)(isFelt(felt), "arg " + input.name + "[" + i + "] should be decimal or hexadecimal as part of a felt* (string[])");
|
|
158
172
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -15,3 +15,6 @@ export * as json from './utils/json';
|
|
|
15
15
|
export * as number from './utils/number';
|
|
16
16
|
export * as stark from './utils/stark';
|
|
17
17
|
export * as ec from './utils/ellipticCurve';
|
|
18
|
+
export * as uint256 from './utils/uint256';
|
|
19
|
+
export * as shortString from './utils/shortString';
|
|
20
|
+
export * as typedData from './utils/typedData';
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
return result;
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.ec = exports.stark = exports.number = exports.json = exports.hash = exports.encode = exports.constants = void 0;
|
|
25
|
+
exports.typedData = exports.shortString = exports.uint256 = exports.ec = exports.stark = exports.number = exports.json = exports.hash = exports.encode = exports.constants = void 0;
|
|
26
26
|
/**
|
|
27
27
|
* Main
|
|
28
28
|
*/
|
|
@@ -40,3 +40,6 @@ exports.json = __importStar(require("./utils/json"));
|
|
|
40
40
|
exports.number = __importStar(require("./utils/number"));
|
|
41
41
|
exports.stark = __importStar(require("./utils/stark"));
|
|
42
42
|
exports.ec = __importStar(require("./utils/ellipticCurve"));
|
|
43
|
+
exports.uint256 = __importStar(require("./utils/uint256"));
|
|
44
|
+
exports.shortString = __importStar(require("./utils/shortString"));
|
|
45
|
+
exports.typedData = __importStar(require("./utils/typedData"));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AddTransactionResponse, CallContractResponse, CallContractTransaction, CompiledContract, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Transaction } from '../types';
|
|
1
|
+
import { AddTransactionResponse, CallContractResponse, CallContractTransaction, CompiledContract, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Signature, Transaction } from '../types';
|
|
2
2
|
import { BigNumberish } from '../utils/number';
|
|
3
3
|
import { ProviderInterface } from './interface';
|
|
4
4
|
declare type NetworkName = 'mainnet-alpha' | 'georli-alpha';
|
|
@@ -25,11 +25,11 @@ export declare class Provider implements ProviderInterface {
|
|
|
25
25
|
*
|
|
26
26
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
|
|
27
27
|
*
|
|
28
|
-
* @param
|
|
28
|
+
* @param invokeTransaction - transaction to be invoked
|
|
29
29
|
* @param blockId
|
|
30
30
|
* @returns the result of the function on the smart contract.
|
|
31
31
|
*/
|
|
32
|
-
callContract(
|
|
32
|
+
callContract(invokeTransaction: CallContractTransaction, blockId?: number): Promise<CallContractResponse>;
|
|
33
33
|
/**
|
|
34
34
|
* Gets the block information from a block ID.
|
|
35
35
|
*
|
|
@@ -83,10 +83,10 @@ export declare class Provider implements ProviderInterface {
|
|
|
83
83
|
*
|
|
84
84
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
85
85
|
*
|
|
86
|
-
* @param
|
|
86
|
+
* @param transaction - transaction to be invoked
|
|
87
87
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
88
88
|
*/
|
|
89
|
-
addTransaction(
|
|
89
|
+
addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
90
90
|
/**
|
|
91
91
|
* Deploys a given compiled contract (json) to starknet
|
|
92
92
|
*
|
|
@@ -104,7 +104,7 @@ export declare class Provider implements ProviderInterface {
|
|
|
104
104
|
* @param signature - (optional) signature to send along
|
|
105
105
|
* @returns response from addTransaction
|
|
106
106
|
*/
|
|
107
|
-
invokeFunction(contractAddress: string, entrypointSelector: string, calldata?: string[], signature?:
|
|
107
|
+
invokeFunction(contractAddress: string, entrypointSelector: string, calldata?: string[], signature?: Signature): Promise<AddTransactionResponse>;
|
|
108
108
|
waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
109
109
|
}
|
|
110
110
|
export {};
|
package/dist/provider/default.js
CHANGED
|
@@ -109,16 +109,16 @@ var Provider = /** @class */ (function () {
|
|
|
109
109
|
*
|
|
110
110
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
|
|
111
111
|
*
|
|
112
|
-
* @param
|
|
112
|
+
* @param invokeTransaction - transaction to be invoked
|
|
113
113
|
* @param blockId
|
|
114
114
|
* @returns the result of the function on the smart contract.
|
|
115
115
|
*/
|
|
116
|
-
Provider.prototype.callContract = function (
|
|
116
|
+
Provider.prototype.callContract = function (invokeTransaction, blockId) {
|
|
117
117
|
return __awaiter(this, void 0, void 0, function () {
|
|
118
118
|
var data;
|
|
119
119
|
return __generator(this, function (_a) {
|
|
120
120
|
switch (_a.label) {
|
|
121
|
-
case 0: return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.feederGatewayUrl, 'call_contract', "?blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null')), __assign({ signature: [], calldata: [] },
|
|
121
|
+
case 0: return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.feederGatewayUrl, 'call_contract', "?blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null')), __assign({ signature: [], calldata: [] }, invokeTransaction))];
|
|
122
122
|
case 1:
|
|
123
123
|
data = (_a.sent()).data;
|
|
124
124
|
return [2 /*return*/, data];
|
|
@@ -244,18 +244,18 @@ var Provider = /** @class */ (function () {
|
|
|
244
244
|
*
|
|
245
245
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
246
246
|
*
|
|
247
|
-
* @param
|
|
247
|
+
* @param transaction - transaction to be invoked
|
|
248
248
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
249
249
|
*/
|
|
250
|
-
Provider.prototype.addTransaction = function (
|
|
250
|
+
Provider.prototype.addTransaction = function (transaction) {
|
|
251
251
|
return __awaiter(this, void 0, void 0, function () {
|
|
252
252
|
var signature, contract_address_salt, data;
|
|
253
253
|
return __generator(this, function (_a) {
|
|
254
254
|
switch (_a.label) {
|
|
255
255
|
case 0:
|
|
256
|
-
signature =
|
|
257
|
-
contract_address_salt =
|
|
258
|
-
return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.gatewayUrl, 'add_transaction'), (0, json_1.stringify)(__assign(__assign(__assign({},
|
|
256
|
+
signature = transaction.type === 'INVOKE_FUNCTION' && (0, stark_1.formatSignature)(transaction.signature);
|
|
257
|
+
contract_address_salt = transaction.type === 'DEPLOY' && (0, number_1.toHex)((0, number_1.toBN)(transaction.contract_address_salt));
|
|
258
|
+
return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.gatewayUrl, 'add_transaction'), (0, json_1.stringify)(__assign(__assign(__assign({}, transaction), (Array.isArray(signature) && { signature: signature })), (contract_address_salt && { contract_address_salt: contract_address_salt }))), { headers: { 'Content-Type': 'application/json' } })];
|
|
259
259
|
case 1:
|
|
260
260
|
data = (_a.sent()).data;
|
|
261
261
|
return [2 /*return*/, data];
|
|
@@ -308,20 +308,21 @@ var Provider = /** @class */ (function () {
|
|
|
308
308
|
switch (_a.label) {
|
|
309
309
|
case 0:
|
|
310
310
|
onchain = false;
|
|
311
|
-
|
|
311
|
+
return [4 /*yield*/, wait(retryInterval)];
|
|
312
312
|
case 1:
|
|
313
|
-
|
|
313
|
+
_a.sent();
|
|
314
|
+
_a.label = 2;
|
|
315
|
+
case 2:
|
|
316
|
+
if (!!onchain) return [3 /*break*/, 5];
|
|
314
317
|
// eslint-disable-next-line no-await-in-loop
|
|
315
318
|
return [4 /*yield*/, wait(retryInterval)];
|
|
316
|
-
case
|
|
319
|
+
case 3:
|
|
317
320
|
// eslint-disable-next-line no-await-in-loop
|
|
318
321
|
_a.sent();
|
|
319
322
|
return [4 /*yield*/, this.getTransactionStatus(txHash)];
|
|
320
|
-
case
|
|
323
|
+
case 4:
|
|
321
324
|
res = _a.sent();
|
|
322
|
-
if (res.tx_status === '
|
|
323
|
-
(res.tx_status === 'PENDING' && res.block_hash !== 'pending') // This is needed as of today. In the future there will be a different status for pending transactions.
|
|
324
|
-
) {
|
|
325
|
+
if (res.tx_status === 'ACCEPTED_ON_L1' || res.tx_status === 'ACCEPTED_ON_L2') {
|
|
325
326
|
onchain = true;
|
|
326
327
|
}
|
|
327
328
|
else if (res.tx_status === 'REJECTED') {
|
|
@@ -330,8 +331,8 @@ var Provider = /** @class */ (function () {
|
|
|
330
331
|
else if (res.tx_status === 'NOT_RECEIVED') {
|
|
331
332
|
throw Error('NOT_RECEIVED');
|
|
332
333
|
}
|
|
333
|
-
return [3 /*break*/,
|
|
334
|
-
case
|
|
334
|
+
return [3 /*break*/, 2];
|
|
335
|
+
case 5: return [2 /*return*/];
|
|
335
336
|
}
|
|
336
337
|
});
|
|
337
338
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AddTransactionResponse, CallContractResponse, CallContractTransaction, CompiledContract, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Transaction } from '../types';
|
|
1
|
+
import type { AddTransactionResponse, CallContractResponse, CallContractTransaction, CompiledContract, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Signature, Transaction } from '../types';
|
|
2
2
|
import type { BigNumberish } from '../utils/number';
|
|
3
3
|
export declare abstract class ProviderInterface {
|
|
4
4
|
abstract baseUrl: string;
|
|
@@ -16,11 +16,11 @@ export declare abstract class ProviderInterface {
|
|
|
16
16
|
*
|
|
17
17
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
|
|
18
18
|
*
|
|
19
|
-
* @param
|
|
19
|
+
* @param invokeTransaction - transaction to be invoked
|
|
20
20
|
* @param blockId
|
|
21
21
|
* @returns the result of the function on the smart contract.
|
|
22
22
|
*/
|
|
23
|
-
abstract callContract(
|
|
23
|
+
abstract callContract(invokeTransaction: CallContractTransaction, blockId?: number): Promise<CallContractResponse>;
|
|
24
24
|
/**
|
|
25
25
|
* Gets the block information from a block ID.
|
|
26
26
|
*
|
|
@@ -74,10 +74,10 @@ export declare abstract class ProviderInterface {
|
|
|
74
74
|
*
|
|
75
75
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
76
76
|
*
|
|
77
|
-
* @param
|
|
77
|
+
* @param transaction - transaction to be invoked
|
|
78
78
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
79
79
|
*/
|
|
80
|
-
abstract addTransaction(
|
|
80
|
+
abstract addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
81
81
|
/**
|
|
82
82
|
* Deploys a given compiled contract (json) to starknet
|
|
83
83
|
*
|
|
@@ -95,6 +95,6 @@ export declare abstract class ProviderInterface {
|
|
|
95
95
|
* @param signature - (optional) signature to send along
|
|
96
96
|
* @returns response from addTransaction
|
|
97
97
|
*/
|
|
98
|
-
abstract invokeFunction(contractAddress: string, entrypointSelector: string, calldata?: string[], signature?:
|
|
98
|
+
abstract invokeFunction(contractAddress: string, entrypointSelector: string, calldata?: string[], signature?: Signature): Promise<AddTransactionResponse>;
|
|
99
99
|
abstract waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
100
100
|
}
|
package/dist/signer/default.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Provider } from '../provider';
|
|
2
|
-
import { AddTransactionResponse, KeyPair, Transaction } from '../types';
|
|
2
|
+
import { AddTransactionResponse, KeyPair, Signature, Transaction } from '../types';
|
|
3
|
+
import { TypedData } from '../utils/typedData';
|
|
3
4
|
import { SignerInterface } from './interface';
|
|
4
5
|
export declare class Signer extends Provider implements SignerInterface {
|
|
5
6
|
address: string;
|
|
@@ -10,8 +11,24 @@ export declare class Signer extends Provider implements SignerInterface {
|
|
|
10
11
|
*
|
|
11
12
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
12
13
|
*
|
|
13
|
-
* @param
|
|
14
|
+
* @param transaction - transaction to be invoked
|
|
14
15
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
15
16
|
*/
|
|
16
|
-
addTransaction(
|
|
17
|
+
addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Sign an JSON object with the starknet private key and return the signature
|
|
20
|
+
*
|
|
21
|
+
* @param json - JSON object to be signed
|
|
22
|
+
* @returns the signature of the JSON object
|
|
23
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
24
|
+
*/
|
|
25
|
+
signMessage(typedData: TypedData): Promise<Signature>;
|
|
26
|
+
/**
|
|
27
|
+
* Hash a JSON object with pederson hash and return the hash
|
|
28
|
+
*
|
|
29
|
+
* @param json - JSON object to be hashed
|
|
30
|
+
* @returns the hash of the JSON object
|
|
31
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
32
|
+
*/
|
|
33
|
+
hashMessage(typedData: TypedData): Promise<string>;
|
|
17
34
|
}
|