starknet 2.4.0 → 2.7.1
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 +43 -0
- package/__tests__/account.test.ts +3 -3
- package/__tests__/provider.test.ts +28 -13
- package/__tests__/utils/ellipticalCurve.test.ts +1 -1
- package/__tests__/utils/typedData.test.ts +72 -0
- package/contract.d.ts +2 -2
- package/dist/contract.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/provider/default.d.ts +23 -19
- package/dist/provider/default.js +58 -41
- package/dist/provider/interface.d.ts +22 -18
- package/dist/provider/utils.d.ts +27 -0
- package/dist/provider/utils.js +37 -0
- package/dist/signer/default.d.ts +18 -1
- package/dist/signer/default.js +43 -7
- package/dist/signer/interface.d.ts +20 -1
- package/dist/types.d.ts +7 -6
- package/dist/utils/ellipticCurve.d.ts +8 -1
- package/dist/utils/ellipticCurve.js +48 -9
- 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/index.d.ts +1 -0
- package/index.js +3 -1
- package/package.json +2 -1
- package/provider/default.d.ts +34 -18
- package/provider/default.js +75 -45
- package/provider/interface.d.ts +33 -17
- package/provider/utils.d.ts +30 -0
- package/provider/utils.js +39 -0
- package/signer/default.d.ts +18 -1
- package/signer/default.js +44 -7
- package/signer/interface.d.ts +20 -1
- package/src/contract.ts +2 -2
- package/src/index.ts +1 -0
- package/src/provider/default.ts +55 -32
- package/src/provider/interface.ts +32 -17
- package/src/provider/utils.ts +38 -0
- package/src/signer/default.ts +26 -3
- package/src/signer/interface.ts +22 -1
- package/src/types.ts +13 -6
- package/src/utils/ellipticCurve.ts +31 -9
- 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/types.d.ts +9 -7
- package/utils/ellipticCurve.d.ts +12 -1
- package/utils/ellipticCurve.js +72 -23
- 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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
+
## [2.7.1](https://github.com/seanjameshan/starknet.js/compare/v2.7.0...v2.7.1) (2022-01-04)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- **types:** add block_number property to GetBlockResponse interface ([696cf5a](https://github.com/seanjameshan/starknet.js/commit/696cf5ae565bd16365045cc1f20e9fa55184d054))
|
|
6
|
+
|
|
7
|
+
# [2.7.0](https://github.com/seanjameshan/starknet.js/compare/v2.6.0...v2.7.0) (2022-01-03)
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
- add response to the waitForTx error ([e25bdfd](https://github.com/seanjameshan/starknet.js/commit/e25bdfd428fd36e105ed272ea39462845bae5805))
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
- **blockHash:** add blockHash and fix test cases ([4e107eb](https://github.com/seanjameshan/starknet.js/commit/4e107eb7e97a9b8d2efd74b2074a7d82365c932e))
|
|
16
|
+
|
|
17
|
+
# [2.6.0](https://github.com/seanjameshan/starknet.js/compare/v2.5.0...v2.6.0) (2021-12-29)
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
- correct network name ([66e14c9](https://github.com/seanjameshan/starknet.js/commit/66e14c926f015a2dfbd50d3e54ba4e008fb43aa8))
|
|
22
|
+
- network name ([965f215](https://github.com/seanjameshan/starknet.js/commit/965f21580ef68bf84c105e93bfb3b98f75b31f93))
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
|
|
26
|
+
- introduce blockNumber ([657dac1](https://github.com/seanjameshan/starknet.js/commit/657dac1d77e840a7fc663d3a180515443a7e834f))
|
|
27
|
+
|
|
28
|
+
# [2.5.0](https://github.com/seanjameshan/starknet.js/compare/v2.4.0...v2.5.0) (2021-12-13)
|
|
29
|
+
|
|
30
|
+
### Bug Fixes
|
|
31
|
+
|
|
32
|
+
- add jsdoc comment ([4cd969f](https://github.com/seanjameshan/starknet.js/commit/4cd969f82eb4a5d8c08feb59c42fb3e7195af50e))
|
|
33
|
+
- remove eip712 reference ([039a360](https://github.com/seanjameshan/starknet.js/commit/039a360873f9a1cdedc7a498b6e1732183957143))
|
|
34
|
+
- remove unused types ([e528f7d](https://github.com/seanjameshan/starknet.js/commit/e528f7d75f4560d2affe3ca99426e01fbee6dfb5))
|
|
35
|
+
- review ([a3813c9](https://github.com/seanjameshan/starknet.js/commit/a3813c9931c178d58c2521b926fb3fdff6944635))
|
|
36
|
+
|
|
37
|
+
### Features
|
|
38
|
+
|
|
39
|
+
- add `getKeyPairFromPublicKey` method ([66d543d](https://github.com/seanjameshan/starknet.js/commit/66d543dca1bb302654f0f1588a27f7794bfa49be))
|
|
40
|
+
- add tests ([b414a83](https://github.com/seanjameshan/starknet.js/commit/b414a839a1fdd56084a58d6efb4747e8f5455628))
|
|
41
|
+
- allow multi sig ([fc1e086](https://github.com/seanjameshan/starknet.js/commit/fc1e0866154d2bf29f26374639a34fec438bae5e))
|
|
42
|
+
- support eip712 for starknet ([d597082](https://github.com/seanjameshan/starknet.js/commit/d59708211fc497d801699a7168dad1a5cc9648fd))
|
|
43
|
+
|
|
1
44
|
# [2.4.0](https://github.com/seanjameshan/starknet.js/compare/v2.3.1...v2.4.0) (2021-12-09)
|
|
2
45
|
|
|
3
46
|
### Features
|
|
@@ -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
|
);
|
|
@@ -13,38 +13,53 @@ describe('defaultProvider', () => {
|
|
|
13
13
|
expect(typeof GpsStatementVerifier).toBe('string');
|
|
14
14
|
expect(typeof Starknet).toBe('string');
|
|
15
15
|
});
|
|
16
|
-
test('getBlock()', () => {
|
|
17
|
-
return expect(
|
|
16
|
+
test('getBlock(blockHash=0x3bca19c3d5983e21e9537669b15f951f0664f0747a083dc714e0b9648b8575d, blockNumber=undefined)', () => {
|
|
17
|
+
return expect(
|
|
18
|
+
defaultProvider.getBlock(
|
|
19
|
+
'0x3bca19c3d5983e21e9537669b15f951f0664f0747a083dc714e0b9648b8575d'
|
|
20
|
+
)
|
|
21
|
+
).resolves.not.toThrow();
|
|
22
|
+
});
|
|
23
|
+
test('getBlock(blockHash=undefined, blockNumber=36657)', () => {
|
|
24
|
+
return expect(defaultProvider.getBlock(undefined, 36657)).resolves.not.toThrow();
|
|
18
25
|
});
|
|
19
|
-
test('getBlock(
|
|
26
|
+
test('getBlock(blockHash=undefined, blockNumber=null)', () => {
|
|
20
27
|
return expect(defaultProvider.getBlock()).resolves.not.toThrow();
|
|
21
28
|
});
|
|
29
|
+
test('getBlock() -> { blockNumber }', async () => {
|
|
30
|
+
const block = await defaultProvider.getBlock();
|
|
31
|
+
return expect(block).toHaveProperty('block_number');
|
|
32
|
+
});
|
|
22
33
|
test('getCode()', () => {
|
|
23
34
|
return expect(
|
|
24
35
|
defaultProvider.getCode(
|
|
25
|
-
'
|
|
26
|
-
|
|
36
|
+
'0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
|
|
37
|
+
undefined,
|
|
38
|
+
36663
|
|
27
39
|
)
|
|
28
40
|
).resolves.not.toThrow();
|
|
29
41
|
});
|
|
30
|
-
test('getCode(
|
|
42
|
+
test('getCode(blockHash=undefined, blockNumber=null)', () => {
|
|
31
43
|
return expect(
|
|
32
|
-
defaultProvider.getCode(
|
|
44
|
+
defaultProvider.getCode(
|
|
45
|
+
'0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166'
|
|
46
|
+
)
|
|
33
47
|
).resolves.not.toThrow();
|
|
34
48
|
});
|
|
35
49
|
test('getStorageAt()', () => {
|
|
36
50
|
return expect(
|
|
37
51
|
defaultProvider.getStorageAt(
|
|
38
|
-
'
|
|
52
|
+
'0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
|
|
39
53
|
0,
|
|
40
|
-
|
|
54
|
+
undefined,
|
|
55
|
+
36663
|
|
41
56
|
)
|
|
42
57
|
).resolves.not.toThrow();
|
|
43
58
|
});
|
|
44
|
-
test('getStorageAt(
|
|
59
|
+
test('getStorageAt(blockHash=undefined, blockNumber=null)', () => {
|
|
45
60
|
return expect(
|
|
46
61
|
defaultProvider.getStorageAt(
|
|
47
|
-
'
|
|
62
|
+
'0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
|
|
48
63
|
0
|
|
49
64
|
)
|
|
50
65
|
).resolves.not.toThrow();
|
|
@@ -52,14 +67,14 @@ describe('defaultProvider', () => {
|
|
|
52
67
|
test('getTransactionStatus()', async () => {
|
|
53
68
|
return expect(
|
|
54
69
|
defaultProvider.getTransactionStatus(
|
|
55
|
-
'
|
|
70
|
+
'0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
|
|
56
71
|
)
|
|
57
72
|
).resolves.not.toThrow();
|
|
58
73
|
});
|
|
59
74
|
test('getTransaction()', async () => {
|
|
60
75
|
return expect(
|
|
61
76
|
defaultProvider.getTransaction(
|
|
62
|
-
'
|
|
77
|
+
'0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
|
|
63
78
|
)
|
|
64
79
|
).resolves.not.toThrow();
|
|
65
80
|
});
|
|
@@ -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,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
|
+
});
|
package/contract.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
5
|
[inputName: string]:
|
|
@@ -33,7 +33,7 @@ export declare class Contract {
|
|
|
33
33
|
invoke(
|
|
34
34
|
method: string,
|
|
35
35
|
args?: Args,
|
|
36
|
-
signature?:
|
|
36
|
+
signature?: Signature
|
|
37
37
|
): Promise<import('./types').AddTransactionResponse>;
|
|
38
38
|
call(method: string, args?: Args): Promise<Args>;
|
|
39
39
|
}
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
5
|
[inputName: string]: string | string[] | {
|
|
@@ -27,6 +27,6 @@ export declare class Contract {
|
|
|
27
27
|
private validateMethodAndArgs;
|
|
28
28
|
private parseResponseField;
|
|
29
29
|
private parseResponse;
|
|
30
|
-
invoke(method: string, args?: Args, signature?:
|
|
30
|
+
invoke(method: string, args?: Args, signature?: Signature): Promise<import("./types").AddTransactionResponse>;
|
|
31
31
|
call(method: string, args?: Args): Promise<Args>;
|
|
32
32
|
}
|
package/dist/index.d.ts
CHANGED
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.shortString = exports.uint256 = 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
|
*/
|
|
@@ -42,3 +42,4 @@ exports.stark = __importStar(require("./utils/stark"));
|
|
|
42
42
|
exports.ec = __importStar(require("./utils/ellipticCurve"));
|
|
43
43
|
exports.uint256 = __importStar(require("./utils/uint256"));
|
|
44
44
|
exports.shortString = __importStar(require("./utils/shortString"));
|
|
45
|
+
exports.typedData = __importStar(require("./utils/typedData"));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AddTransactionResponse, CallContractResponse, CallContractTransaction, CompiledContract, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Transaction } from '../types';
|
|
1
|
+
import { AddTransactionResponse, BlockNumber, 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
|
-
declare type NetworkName = 'mainnet-alpha' | '
|
|
4
|
+
declare type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
|
|
5
5
|
declare type ProviderOptions = {
|
|
6
6
|
network: NetworkName;
|
|
7
7
|
} | {
|
|
@@ -23,50 +23,54 @@ export declare class Provider implements ProviderInterface {
|
|
|
23
23
|
/**
|
|
24
24
|
* Calls a function on the StarkNet contract.
|
|
25
25
|
*
|
|
26
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
26
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
|
|
27
27
|
*
|
|
28
28
|
* @param invokeTransaction - transaction to be invoked
|
|
29
|
-
* @param
|
|
29
|
+
* @param blockHash
|
|
30
|
+
* @param blockNumber
|
|
30
31
|
* @returns the result of the function on the smart contract.
|
|
31
32
|
*/
|
|
32
|
-
callContract(invokeTransaction: CallContractTransaction,
|
|
33
|
+
callContract(invokeTransaction: CallContractTransaction, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<CallContractResponse>;
|
|
33
34
|
/**
|
|
34
|
-
* Gets the block information
|
|
35
|
+
* Gets the block information
|
|
35
36
|
*
|
|
36
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
37
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
|
|
37
38
|
*
|
|
38
|
-
* @param
|
|
39
|
-
* @
|
|
39
|
+
* @param blockHash
|
|
40
|
+
* @param blockNumber
|
|
41
|
+
* @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
|
|
40
42
|
*/
|
|
41
|
-
getBlock(
|
|
43
|
+
getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
|
|
42
44
|
/**
|
|
43
45
|
* Gets the code of the deployed contract.
|
|
44
46
|
*
|
|
45
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
47
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
|
|
46
48
|
*
|
|
47
49
|
* @param contractAddress
|
|
48
|
-
* @param
|
|
50
|
+
* @param blockHash
|
|
51
|
+
* @param blockNumber
|
|
49
52
|
* @returns Bytecode and ABI of compiled contract
|
|
50
53
|
*/
|
|
51
|
-
getCode(contractAddress: string,
|
|
54
|
+
getCode(contractAddress: string, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
|
|
52
55
|
/**
|
|
53
56
|
* Gets the contract's storage variable at a specific key.
|
|
54
57
|
*
|
|
55
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
58
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
|
|
56
59
|
*
|
|
57
60
|
* @param contractAddress
|
|
58
61
|
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
|
|
59
|
-
* @param
|
|
62
|
+
* @param blockHash
|
|
63
|
+
* @param blockNumber
|
|
60
64
|
* @returns the value of the storage variable
|
|
61
65
|
*/
|
|
62
|
-
getStorageAt(contractAddress: string, key: number,
|
|
66
|
+
getStorageAt(contractAddress: string, key: number, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<object>;
|
|
63
67
|
/**
|
|
64
68
|
* Gets the status of a transaction.
|
|
65
69
|
*
|
|
66
70
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
|
|
67
71
|
*
|
|
68
72
|
* @param txHash
|
|
69
|
-
* @returns the transaction status object {
|
|
73
|
+
* @returns the transaction status object { block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
|
|
70
74
|
*/
|
|
71
75
|
getTransactionStatus(txHash: BigNumberish): Promise<GetTransactionStatusResponse>;
|
|
72
76
|
/**
|
|
@@ -75,7 +79,7 @@ export declare class Provider implements ProviderInterface {
|
|
|
75
79
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
|
|
76
80
|
*
|
|
77
81
|
* @param txHash
|
|
78
|
-
* @returns the transacton object { transaction_id, status, transaction,
|
|
82
|
+
* @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
79
83
|
*/
|
|
80
84
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
81
85
|
/**
|
|
@@ -104,7 +108,7 @@ export declare class Provider implements ProviderInterface {
|
|
|
104
108
|
* @param signature - (optional) signature to send along
|
|
105
109
|
* @returns response from addTransaction
|
|
106
110
|
*/
|
|
107
|
-
invokeFunction(contractAddress: string, entrypointSelector: string, calldata?: string[], signature?:
|
|
111
|
+
invokeFunction(contractAddress: string, entrypointSelector: string, calldata?: string[], signature?: Signature): Promise<AddTransactionResponse>;
|
|
108
112
|
waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
109
113
|
}
|
|
110
114
|
export {};
|
package/dist/provider/default.js
CHANGED
|
@@ -56,12 +56,13 @@ var url_join_1 = __importDefault(require("url-join"));
|
|
|
56
56
|
var json_1 = require("../utils/json");
|
|
57
57
|
var number_1 = require("../utils/number");
|
|
58
58
|
var stark_1 = require("../utils/stark");
|
|
59
|
+
var utils_1 = require("./utils");
|
|
59
60
|
function wait(delay) {
|
|
60
61
|
return new Promise(function (res) { return setTimeout(res, delay); });
|
|
61
62
|
}
|
|
62
63
|
var Provider = /** @class */ (function () {
|
|
63
64
|
function Provider(optionsOrProvider) {
|
|
64
|
-
if (optionsOrProvider === void 0) { optionsOrProvider = { network: '
|
|
65
|
+
if (optionsOrProvider === void 0) { optionsOrProvider = { network: 'goerli-alpha' }; }
|
|
65
66
|
if (optionsOrProvider instanceof Provider) {
|
|
66
67
|
this.baseUrl = optionsOrProvider.baseUrl;
|
|
67
68
|
this.feederGatewayUrl = optionsOrProvider.feederGatewayUrl;
|
|
@@ -80,7 +81,7 @@ var Provider = /** @class */ (function () {
|
|
|
80
81
|
switch (name) {
|
|
81
82
|
case 'mainnet-alpha':
|
|
82
83
|
return 'https://alpha-mainnet.starknet.io';
|
|
83
|
-
case '
|
|
84
|
+
case 'goerli-alpha':
|
|
84
85
|
default:
|
|
85
86
|
return 'https://alpha4.starknet.io';
|
|
86
87
|
}
|
|
@@ -107,18 +108,22 @@ var Provider = /** @class */ (function () {
|
|
|
107
108
|
/**
|
|
108
109
|
* Calls a function on the StarkNet contract.
|
|
109
110
|
*
|
|
110
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
111
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
|
|
111
112
|
*
|
|
112
113
|
* @param invokeTransaction - transaction to be invoked
|
|
113
|
-
* @param
|
|
114
|
+
* @param blockHash
|
|
115
|
+
* @param blockNumber
|
|
114
116
|
* @returns the result of the function on the smart contract.
|
|
115
117
|
*/
|
|
116
|
-
Provider.prototype.callContract = function (invokeTransaction,
|
|
118
|
+
Provider.prototype.callContract = function (invokeTransaction, blockHash, blockNumber) {
|
|
119
|
+
if (blockNumber === void 0) { blockNumber = null; }
|
|
117
120
|
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
-
var data;
|
|
121
|
+
var formattedBlockIdentifier, data;
|
|
119
122
|
return __generator(this, function (_a) {
|
|
120
123
|
switch (_a.label) {
|
|
121
|
-
case 0:
|
|
124
|
+
case 0:
|
|
125
|
+
formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
|
|
126
|
+
return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.feederGatewayUrl, 'call_contract', formattedBlockIdentifier), __assign({ signature: [], calldata: [] }, invokeTransaction))];
|
|
122
127
|
case 1:
|
|
123
128
|
data = (_a.sent()).data;
|
|
124
129
|
return [2 /*return*/, data];
|
|
@@ -127,19 +132,23 @@ var Provider = /** @class */ (function () {
|
|
|
127
132
|
});
|
|
128
133
|
};
|
|
129
134
|
/**
|
|
130
|
-
* Gets the block information
|
|
135
|
+
* Gets the block information
|
|
131
136
|
*
|
|
132
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
137
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
|
|
133
138
|
*
|
|
134
|
-
* @param
|
|
135
|
-
* @
|
|
139
|
+
* @param blockHash
|
|
140
|
+
* @param blockNumber
|
|
141
|
+
* @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
|
|
136
142
|
*/
|
|
137
|
-
Provider.prototype.getBlock = function (
|
|
143
|
+
Provider.prototype.getBlock = function (blockHash, blockNumber) {
|
|
144
|
+
if (blockNumber === void 0) { blockNumber = null; }
|
|
138
145
|
return __awaiter(this, void 0, void 0, function () {
|
|
139
|
-
var data;
|
|
146
|
+
var formattedBlockIdentifier, data;
|
|
140
147
|
return __generator(this, function (_a) {
|
|
141
148
|
switch (_a.label) {
|
|
142
|
-
case 0:
|
|
149
|
+
case 0:
|
|
150
|
+
formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
|
|
151
|
+
return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_block', formattedBlockIdentifier))];
|
|
143
152
|
case 1:
|
|
144
153
|
data = (_a.sent()).data;
|
|
145
154
|
return [2 /*return*/, data];
|
|
@@ -150,18 +159,22 @@ var Provider = /** @class */ (function () {
|
|
|
150
159
|
/**
|
|
151
160
|
* Gets the code of the deployed contract.
|
|
152
161
|
*
|
|
153
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
162
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
|
|
154
163
|
*
|
|
155
164
|
* @param contractAddress
|
|
156
|
-
* @param
|
|
165
|
+
* @param blockHash
|
|
166
|
+
* @param blockNumber
|
|
157
167
|
* @returns Bytecode and ABI of compiled contract
|
|
158
168
|
*/
|
|
159
|
-
Provider.prototype.getCode = function (contractAddress,
|
|
169
|
+
Provider.prototype.getCode = function (contractAddress, blockHash, blockNumber) {
|
|
170
|
+
if (blockNumber === void 0) { blockNumber = null; }
|
|
160
171
|
return __awaiter(this, void 0, void 0, function () {
|
|
161
|
-
var data;
|
|
172
|
+
var formattedBlockIdentifier, data;
|
|
162
173
|
return __generator(this, function (_a) {
|
|
163
174
|
switch (_a.label) {
|
|
164
|
-
case 0:
|
|
175
|
+
case 0:
|
|
176
|
+
formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
|
|
177
|
+
return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_code', "?contractAddress=" + contractAddress + "&" + formattedBlockIdentifier))];
|
|
165
178
|
case 1:
|
|
166
179
|
data = (_a.sent()).data;
|
|
167
180
|
return [2 /*return*/, data];
|
|
@@ -173,19 +186,23 @@ var Provider = /** @class */ (function () {
|
|
|
173
186
|
/**
|
|
174
187
|
* Gets the contract's storage variable at a specific key.
|
|
175
188
|
*
|
|
176
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
189
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
|
|
177
190
|
*
|
|
178
191
|
* @param contractAddress
|
|
179
192
|
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
|
|
180
|
-
* @param
|
|
193
|
+
* @param blockHash
|
|
194
|
+
* @param blockNumber
|
|
181
195
|
* @returns the value of the storage variable
|
|
182
196
|
*/
|
|
183
|
-
Provider.prototype.getStorageAt = function (contractAddress, key,
|
|
197
|
+
Provider.prototype.getStorageAt = function (contractAddress, key, blockHash, blockNumber) {
|
|
198
|
+
if (blockNumber === void 0) { blockNumber = null; }
|
|
184
199
|
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
-
var data;
|
|
200
|
+
var formattedBlockIdentifier, data;
|
|
186
201
|
return __generator(this, function (_a) {
|
|
187
202
|
switch (_a.label) {
|
|
188
|
-
case 0:
|
|
203
|
+
case 0:
|
|
204
|
+
formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
|
|
205
|
+
return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_storage_at', "?contractAddress=" + contractAddress + "&key=" + key + "&" + formattedBlockIdentifier))];
|
|
189
206
|
case 1:
|
|
190
207
|
data = (_a.sent()).data;
|
|
191
208
|
return [2 /*return*/, data];
|
|
@@ -199,7 +216,7 @@ var Provider = /** @class */ (function () {
|
|
|
199
216
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
|
|
200
217
|
*
|
|
201
218
|
* @param txHash
|
|
202
|
-
* @returns the transaction status object {
|
|
219
|
+
* @returns the transaction status object { block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
|
|
203
220
|
*/
|
|
204
221
|
Provider.prototype.getTransactionStatus = function (txHash) {
|
|
205
222
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -222,7 +239,7 @@ var Provider = /** @class */ (function () {
|
|
|
222
239
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
|
|
223
240
|
*
|
|
224
241
|
* @param txHash
|
|
225
|
-
* @returns the transacton object { transaction_id, status, transaction,
|
|
242
|
+
* @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
226
243
|
*/
|
|
227
244
|
Provider.prototype.getTransaction = function (txHash) {
|
|
228
245
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -303,35 +320,35 @@ var Provider = /** @class */ (function () {
|
|
|
303
320
|
Provider.prototype.waitForTx = function (txHash, retryInterval) {
|
|
304
321
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
305
322
|
return __awaiter(this, void 0, void 0, function () {
|
|
306
|
-
var onchain, res;
|
|
323
|
+
var onchain, res, error;
|
|
307
324
|
return __generator(this, function (_a) {
|
|
308
325
|
switch (_a.label) {
|
|
309
326
|
case 0:
|
|
310
327
|
onchain = false;
|
|
311
|
-
|
|
328
|
+
return [4 /*yield*/, wait(retryInterval)];
|
|
312
329
|
case 1:
|
|
313
|
-
|
|
330
|
+
_a.sent();
|
|
331
|
+
_a.label = 2;
|
|
332
|
+
case 2:
|
|
333
|
+
if (!!onchain) return [3 /*break*/, 5];
|
|
314
334
|
// eslint-disable-next-line no-await-in-loop
|
|
315
335
|
return [4 /*yield*/, wait(retryInterval)];
|
|
316
|
-
case
|
|
336
|
+
case 3:
|
|
317
337
|
// eslint-disable-next-line no-await-in-loop
|
|
318
338
|
_a.sent();
|
|
319
339
|
return [4 /*yield*/, this.getTransactionStatus(txHash)];
|
|
320
|
-
case
|
|
340
|
+
case 4:
|
|
321
341
|
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
|
-
) {
|
|
342
|
+
if (res.tx_status === 'ACCEPTED_ON_L1' || res.tx_status === 'ACCEPTED_ON_L2') {
|
|
325
343
|
onchain = true;
|
|
326
344
|
}
|
|
327
|
-
else if (res.tx_status === 'REJECTED') {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
throw Error('NOT_RECEIVED');
|
|
345
|
+
else if (res.tx_status === 'REJECTED' || res.tx_status === 'NOT_RECEIVED') {
|
|
346
|
+
error = Error(res.tx_status);
|
|
347
|
+
error.response = res;
|
|
348
|
+
throw error;
|
|
332
349
|
}
|
|
333
|
-
return [3 /*break*/,
|
|
334
|
-
case
|
|
350
|
+
return [3 /*break*/, 2];
|
|
351
|
+
case 5: return [2 /*return*/];
|
|
335
352
|
}
|
|
336
353
|
});
|
|
337
354
|
});
|