starknet 2.7.2 → 3.1.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/.eslintrc +3 -1
- package/CHANGELOG.md +54 -0
- package/README.md +16 -14
- package/__mocks__/contract.json +33191 -0
- package/__mocks__/multicall.json +8139 -0
- package/__mocks__/typedDataExample.json +35 -0
- package/__tests__/account.test.ts +53 -87
- package/__tests__/accountContract.test.ts +161 -0
- package/__tests__/contract.test.ts +167 -30
- package/__tests__/jest.setup.ts +9 -0
- package/__tests__/provider.test.ts +19 -34
- package/__tests__/utils/address.test.ts +16 -0
- package/__tests__/utils/typedData.test.ts +1 -36
- package/account/default.d.ts +66 -0
- package/account/default.js +439 -0
- package/account/index.d.ts +2 -0
- package/account/index.js +27 -0
- package/account/interface.d.ts +83 -0
- package/account/interface.js +37 -0
- package/constants.d.ts +2 -0
- package/constants.js +4 -0
- package/contract.d.ts +71 -12
- package/contract.js +243 -89
- package/dist/account/default.d.ts +55 -0
- package/dist/account/default.js +271 -0
- package/dist/account/index.d.ts +2 -0
- package/dist/account/index.js +14 -0
- package/dist/account/interface.d.ts +69 -0
- package/dist/account/interface.js +27 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +3 -1
- package/dist/contract.d.ts +71 -9
- package/dist/contract.js +214 -65
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/provider/default.d.ts +27 -16
- package/dist/provider/default.js +157 -100
- package/dist/provider/interface.d.ts +29 -32
- package/dist/provider/utils.d.ts +21 -5
- package/dist/provider/utils.js +53 -10
- package/dist/signer/default.d.ts +7 -31
- package/dist/signer/default.js +25 -121
- package/dist/signer/index.d.ts +1 -1
- package/dist/signer/index.js +1 -1
- package/dist/signer/interface.d.ts +17 -18
- package/dist/signer/interface.js +2 -20
- package/dist/types/api.d.ts +147 -0
- package/dist/{types.js → types/api.js} +0 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +15 -0
- package/dist/types/lib.d.ts +57 -0
- package/dist/types/lib.js +2 -0
- package/dist/types/signer.d.ts +4 -0
- package/dist/types/signer.js +2 -0
- package/dist/utils/address.d.ts +2 -0
- package/dist/utils/address.js +22 -0
- package/dist/utils/number.d.ts +2 -0
- package/dist/utils/number.js +32 -2
- package/dist/utils/stark.d.ts +2 -1
- package/dist/utils/stark.js +44 -1
- package/index.d.ts +2 -1
- package/index.js +2 -1
- package/package.json +9 -3
- package/provider/default.d.ts +45 -36
- package/provider/default.js +216 -201
- package/provider/interface.d.ts +36 -49
- package/provider/utils.d.ts +23 -8
- package/provider/utils.js +57 -11
- package/signer/default.d.ts +11 -31
- package/signer/default.js +52 -169
- package/signer/index.d.ts +1 -1
- package/signer/index.js +1 -1
- package/signer/interface.d.ts +21 -18
- package/signer/interface.js +3 -32
- package/src/account/default.ts +151 -0
- package/src/account/index.ts +2 -0
- package/src/account/interface.ts +91 -0
- package/src/constants.ts +2 -0
- package/src/contract.ts +246 -77
- package/src/index.ts +2 -1
- package/src/provider/default.ts +141 -110
- package/src/provider/interface.ts +36 -52
- package/src/provider/utils.ts +60 -13
- package/src/signer/default.ts +33 -76
- package/src/signer/index.ts +1 -1
- package/src/signer/interface.ts +21 -20
- package/src/types/api.ts +171 -0
- package/src/types/index.ts +3 -0
- package/src/types/lib.ts +73 -0
- package/src/types/signer.ts +5 -0
- package/src/utils/address.ts +23 -0
- package/src/utils/number.ts +12 -1
- package/src/utils/stark.ts +13 -1
- package/types/api.d.ts +162 -0
- package/{types.js → types/api.js} +0 -0
- package/types/index.d.ts +3 -0
- package/types/index.js +28 -0
- package/types/lib.d.ts +64 -0
- package/types/lib.js +2 -0
- package/types/signer.d.ts +4 -0
- package/types/signer.js +2 -0
- package/utils/address.d.ts +2 -0
- package/utils/address.js +22 -0
- package/utils/number.d.ts +4 -0
- package/utils/number.js +54 -2
- package/utils/stark.d.ts +2 -1
- package/utils/stark.js +64 -1
- package/__tests__/signer.test.ts +0 -119
- package/dist/types.d.ts +0 -109
- package/src/types.ts +0 -131
- package/types.d.ts +0 -116
package/types/index.d.ts
ADDED
package/types/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
Object.defineProperty(o, k2, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
: function (o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
});
|
|
18
|
+
var __exportStar =
|
|
19
|
+
(this && this.__exportStar) ||
|
|
20
|
+
function (m, exports) {
|
|
21
|
+
for (var p in m)
|
|
22
|
+
if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
23
|
+
__createBinding(exports, m, p);
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
26
|
+
__exportStar(require('./lib'), exports);
|
|
27
|
+
__exportStar(require('./api'), exports);
|
|
28
|
+
__exportStar(require('./signer'), exports);
|
package/types/lib.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ec as EC } from 'elliptic';
|
|
2
|
+
|
|
3
|
+
import type { BigNumberish } from '../utils/number';
|
|
4
|
+
export declare type KeyPair = EC.KeyPair;
|
|
5
|
+
export declare type Signature = BigNumberish[];
|
|
6
|
+
export declare type RawCalldata = BigNumberish[];
|
|
7
|
+
export declare type DeployContractPayload = {
|
|
8
|
+
contract: CompiledContract | string;
|
|
9
|
+
constructorCalldata?: RawCalldata;
|
|
10
|
+
addressSalt?: BigNumberish;
|
|
11
|
+
};
|
|
12
|
+
export declare type Invocation = {
|
|
13
|
+
contractAddress: string;
|
|
14
|
+
entrypoint: string;
|
|
15
|
+
calldata?: RawCalldata;
|
|
16
|
+
signature?: Signature;
|
|
17
|
+
};
|
|
18
|
+
export declare type ExecuteInvocation = Omit<Invocation, 'signature'>;
|
|
19
|
+
export declare type InvocationsDetails = {
|
|
20
|
+
nonce?: BigNumberish;
|
|
21
|
+
};
|
|
22
|
+
export declare type Call = Omit<Invocation, 'signature' | 'nonce'>;
|
|
23
|
+
export declare type Status =
|
|
24
|
+
| 'NOT_RECEIVED'
|
|
25
|
+
| 'RECEIVED'
|
|
26
|
+
| 'PENDING'
|
|
27
|
+
| 'ACCEPTED_ON_L2'
|
|
28
|
+
| 'ACCEPTED_ON_L1'
|
|
29
|
+
| 'REJECTED';
|
|
30
|
+
export declare type TransactionStatus = 'TRANSACTION_RECEIVED';
|
|
31
|
+
export declare type Type = 'DEPLOY' | 'INVOKE_FUNCTION';
|
|
32
|
+
export declare type EntryPointType = 'EXTERNAL';
|
|
33
|
+
export declare type CompressedProgram = string;
|
|
34
|
+
export declare type AbiEntry = {
|
|
35
|
+
name: string;
|
|
36
|
+
type: 'felt' | 'felt*' | string;
|
|
37
|
+
};
|
|
38
|
+
export declare type FunctionAbi = {
|
|
39
|
+
inputs: AbiEntry[];
|
|
40
|
+
name: string;
|
|
41
|
+
outputs: AbiEntry[];
|
|
42
|
+
stateMutability?: 'view';
|
|
43
|
+
type: 'function';
|
|
44
|
+
};
|
|
45
|
+
export declare type StructAbi = {
|
|
46
|
+
members: (AbiEntry & {
|
|
47
|
+
offset: number;
|
|
48
|
+
})[];
|
|
49
|
+
name: string;
|
|
50
|
+
size: number;
|
|
51
|
+
type: 'struct';
|
|
52
|
+
};
|
|
53
|
+
export declare type Abi = Array<FunctionAbi | StructAbi>;
|
|
54
|
+
export declare type EntryPointsByType = object;
|
|
55
|
+
export declare type Program = Record<any, any>;
|
|
56
|
+
export declare type BlockNumber = 'pending' | null | number;
|
|
57
|
+
export declare type CompiledContract = {
|
|
58
|
+
abi: Abi;
|
|
59
|
+
entry_points_by_type: EntryPointsByType;
|
|
60
|
+
program: Program;
|
|
61
|
+
};
|
|
62
|
+
export declare type CompressedCompiledContract = Omit<CompiledContract, 'program'> & {
|
|
63
|
+
program: CompressedProgram;
|
|
64
|
+
};
|
package/types/lib.js
ADDED
package/types/signer.js
ADDED
package/utils/address.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.validateAndParseAddress = exports.addAddressPadding = void 0;
|
|
4
|
+
var constants_1 = require('../constants');
|
|
5
|
+
var encode_1 = require('./encode');
|
|
6
|
+
var number_1 = require('./number');
|
|
7
|
+
function addAddressPadding(address) {
|
|
8
|
+
return (0, encode_1.addHexPrefix)((0, encode_1.removeHexPrefix)(address).padStart(64, '0'));
|
|
9
|
+
}
|
|
10
|
+
exports.addAddressPadding = addAddressPadding;
|
|
11
|
+
function validateAndParseAddress(address) {
|
|
12
|
+
if (typeof address !== 'string') {
|
|
13
|
+
throw new Error('Invalid Address Type');
|
|
14
|
+
}
|
|
15
|
+
(0, number_1.assertInRange)(address, constants_1.ZERO, constants_1.MASK_251, 'Starknet Address');
|
|
16
|
+
var result = addAddressPadding(address);
|
|
17
|
+
if (!result.match(/^(0x)?[0-9a-fA-F]{64}$/)) {
|
|
18
|
+
throw new Error('Invalid Address Format');
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
exports.validateAndParseAddress = validateAndParseAddress;
|
package/utils/number.d.ts
CHANGED
|
@@ -4,9 +4,13 @@ export declare function isHex(hex: string): boolean;
|
|
|
4
4
|
export declare function toBN(number: BigNumberish, base?: number | 'hex'): BN;
|
|
5
5
|
export declare function toHex(number: BN): string;
|
|
6
6
|
export declare function hexToDecimalString(hex: string): string;
|
|
7
|
+
export declare function toFelt(num: BigNumberish): string;
|
|
7
8
|
export declare function assertInRange(
|
|
8
9
|
input: BigNumberish,
|
|
9
10
|
lowerBound: BigNumberish,
|
|
10
11
|
upperBound: BigNumberish,
|
|
11
12
|
inputName?: string
|
|
12
13
|
): void;
|
|
14
|
+
export declare function bigNumberishArrayToDecimalStringArray(
|
|
15
|
+
rawCalldata: BigNumberish[]
|
|
16
|
+
): string[];
|
package/utils/number.js
CHANGED
|
@@ -1,17 +1,56 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
Object.defineProperty(o, k2, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
: function (o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
});
|
|
18
|
+
var __setModuleDefault =
|
|
19
|
+
(this && this.__setModuleDefault) ||
|
|
20
|
+
(Object.create
|
|
21
|
+
? function (o, v) {
|
|
22
|
+
Object.defineProperty(o, 'default', { enumerable: true, value: v });
|
|
23
|
+
}
|
|
24
|
+
: function (o, v) {
|
|
25
|
+
o['default'] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar =
|
|
28
|
+
(this && this.__importStar) ||
|
|
29
|
+
function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null)
|
|
33
|
+
for (var k in mod)
|
|
34
|
+
if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k))
|
|
35
|
+
__createBinding(result, mod, k);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
2
39
|
var __importDefault =
|
|
3
40
|
(this && this.__importDefault) ||
|
|
4
41
|
function (mod) {
|
|
5
42
|
return mod && mod.__esModule ? mod : { default: mod };
|
|
6
43
|
};
|
|
7
44
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
8
|
-
exports.
|
|
45
|
+
exports.bigNumberishArrayToDecimalStringArray =
|
|
46
|
+
exports.assertInRange =
|
|
47
|
+
exports.toFelt =
|
|
9
48
|
exports.hexToDecimalString =
|
|
10
49
|
exports.toHex =
|
|
11
50
|
exports.toBN =
|
|
12
51
|
exports.isHex =
|
|
13
52
|
void 0;
|
|
14
|
-
var bn_js_1 =
|
|
53
|
+
var bn_js_1 = __importStar(require('bn.js'));
|
|
15
54
|
var minimalistic_assert_1 = __importDefault(require('minimalistic-assert'));
|
|
16
55
|
var encode_1 = require('./encode');
|
|
17
56
|
function isHex(hex) {
|
|
@@ -32,6 +71,13 @@ function hexToDecimalString(hex) {
|
|
|
32
71
|
return toBN('0x' + hex.replace(/^0x/, '')).toString();
|
|
33
72
|
}
|
|
34
73
|
exports.hexToDecimalString = hexToDecimalString;
|
|
74
|
+
function toFelt(num) {
|
|
75
|
+
if ((0, bn_js_1.isBN)(num)) {
|
|
76
|
+
return num.toString();
|
|
77
|
+
}
|
|
78
|
+
return toBN(num).toString();
|
|
79
|
+
}
|
|
80
|
+
exports.toFelt = toFelt;
|
|
35
81
|
/*
|
|
36
82
|
Asserts input is equal to or greater then lowerBound and lower then upperBound.
|
|
37
83
|
Assert message specifies inputName.
|
|
@@ -50,3 +96,9 @@ function assertInRange(input, lowerBound, upperBound, inputName) {
|
|
|
50
96
|
);
|
|
51
97
|
}
|
|
52
98
|
exports.assertInRange = assertInRange;
|
|
99
|
+
function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
100
|
+
return rawCalldata.map(function (x) {
|
|
101
|
+
return toBN(x).toString(10);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
exports.bigNumberishArrayToDecimalStringArray = bigNumberishArrayToDecimalStringArray;
|
package/utils/stark.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CompressedProgram, Program, Signature } from '../types';
|
|
1
|
+
import { Calldata, CompressedProgram, Program, RawArgs, Signature } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Function to compress compiled cairo program
|
|
4
4
|
*
|
|
@@ -18,3 +18,4 @@ export declare function getSelectorFromName(funcName: string): string;
|
|
|
18
18
|
export declare function randomAddress(): string;
|
|
19
19
|
export declare function makeAddress(input: string): string;
|
|
20
20
|
export declare function formatSignature(sig?: Signature): string[];
|
|
21
|
+
export declare function compileCalldata(args: RawArgs): Calldata;
|
package/utils/stark.js
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
var __read =
|
|
3
|
+
(this && this.__read) ||
|
|
4
|
+
function (o, n) {
|
|
5
|
+
var m = typeof Symbol === 'function' && o[Symbol.iterator];
|
|
6
|
+
if (!m) return o;
|
|
7
|
+
var i = m.call(o),
|
|
8
|
+
r,
|
|
9
|
+
ar = [],
|
|
10
|
+
e;
|
|
11
|
+
try {
|
|
12
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
e = { error: error };
|
|
15
|
+
} finally {
|
|
16
|
+
try {
|
|
17
|
+
if (r && !r.done && (m = i['return'])) m.call(i);
|
|
18
|
+
} finally {
|
|
19
|
+
if (e) throw e.error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return ar;
|
|
23
|
+
};
|
|
24
|
+
var __spreadArray =
|
|
25
|
+
(this && this.__spreadArray) ||
|
|
26
|
+
function (to, from, pack) {
|
|
27
|
+
if (pack || arguments.length === 2)
|
|
28
|
+
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
29
|
+
if (ar || !(i in from)) {
|
|
30
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
31
|
+
ar[i] = from[i];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
35
|
+
};
|
|
2
36
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.
|
|
37
|
+
exports.compileCalldata =
|
|
38
|
+
exports.formatSignature =
|
|
4
39
|
exports.makeAddress =
|
|
5
40
|
exports.randomAddress =
|
|
6
41
|
exports.getSelectorFromName =
|
|
@@ -62,3 +97,31 @@ function formatSignature(sig) {
|
|
|
62
97
|
}
|
|
63
98
|
}
|
|
64
99
|
exports.formatSignature = formatSignature;
|
|
100
|
+
function compileCalldata(args) {
|
|
101
|
+
return Object.values(args).flatMap(function (value) {
|
|
102
|
+
if (Array.isArray(value))
|
|
103
|
+
return __spreadArray(
|
|
104
|
+
[(0, number_1.toBN)(value.length).toString()],
|
|
105
|
+
__read(
|
|
106
|
+
value.map(function (x) {
|
|
107
|
+
return (0, number_1.toBN)(x).toString();
|
|
108
|
+
})
|
|
109
|
+
),
|
|
110
|
+
false
|
|
111
|
+
);
|
|
112
|
+
if (typeof value === 'object' && 'type' in value)
|
|
113
|
+
return Object.entries(value)
|
|
114
|
+
.filter(function (_a) {
|
|
115
|
+
var _b = __read(_a, 1),
|
|
116
|
+
k = _b[0];
|
|
117
|
+
return k !== 'type';
|
|
118
|
+
})
|
|
119
|
+
.map(function (_a) {
|
|
120
|
+
var _b = __read(_a, 2),
|
|
121
|
+
v = _b[1];
|
|
122
|
+
return (0, number_1.toBN)(v).toString();
|
|
123
|
+
});
|
|
124
|
+
return (0, number_1.toBN)(value).toString();
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
exports.compileCalldata = compileCalldata;
|
package/__tests__/signer.test.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
CompiledContract,
|
|
5
|
-
Contract,
|
|
6
|
-
Signer,
|
|
7
|
-
compileCalldata,
|
|
8
|
-
defaultProvider,
|
|
9
|
-
ec,
|
|
10
|
-
json,
|
|
11
|
-
number,
|
|
12
|
-
stark,
|
|
13
|
-
} from '../src';
|
|
14
|
-
|
|
15
|
-
const compiledArgentAccount: CompiledContract = json.parse(
|
|
16
|
-
fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')
|
|
17
|
-
);
|
|
18
|
-
const compiledErc20: CompiledContract = json.parse(
|
|
19
|
-
fs.readFileSync('./__mocks__/ERC20.json').toString('ascii')
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
describe('deploy and test Wallet', () => {
|
|
23
|
-
const privateKey = stark.randomAddress();
|
|
24
|
-
|
|
25
|
-
const starkKeyPair = ec.getKeyPair(privateKey);
|
|
26
|
-
const starkKeyPub = ec.getStarkKey(starkKeyPair);
|
|
27
|
-
let walletAddress: string;
|
|
28
|
-
let erc20: Contract;
|
|
29
|
-
let erc20Address: string;
|
|
30
|
-
let signer: Signer;
|
|
31
|
-
|
|
32
|
-
beforeAll(async () => {
|
|
33
|
-
const { code: codeErc20, address: erc20AddressLocal } = await defaultProvider.deployContract(
|
|
34
|
-
compiledErc20,
|
|
35
|
-
[]
|
|
36
|
-
);
|
|
37
|
-
erc20Address = erc20AddressLocal;
|
|
38
|
-
erc20 = new Contract(compiledErc20.abi, erc20Address);
|
|
39
|
-
|
|
40
|
-
expect(codeErc20).toBe('TRANSACTION_RECEIVED');
|
|
41
|
-
|
|
42
|
-
const { code, address: walletAddressLocal } = await defaultProvider.deployContract(
|
|
43
|
-
compiledArgentAccount,
|
|
44
|
-
compileCalldata({
|
|
45
|
-
signer: starkKeyPub,
|
|
46
|
-
guardian: '0',
|
|
47
|
-
L1_address: '0',
|
|
48
|
-
}),
|
|
49
|
-
starkKeyPub
|
|
50
|
-
);
|
|
51
|
-
walletAddress = walletAddressLocal;
|
|
52
|
-
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
53
|
-
|
|
54
|
-
const { code: codeErc20Mint, transaction_hash: txErc20Mint } = await erc20.invoke('mint', {
|
|
55
|
-
recipient: walletAddress,
|
|
56
|
-
amount: '1000',
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
expect(codeErc20Mint).toBe('TRANSACTION_RECEIVED');
|
|
60
|
-
|
|
61
|
-
signer = new Signer(defaultProvider, walletAddressLocal, starkKeyPair);
|
|
62
|
-
|
|
63
|
-
await defaultProvider.waitForTx(txErc20Mint);
|
|
64
|
-
});
|
|
65
|
-
test('same wallet address', () => {
|
|
66
|
-
expect(walletAddress).toBe(signer.address);
|
|
67
|
-
});
|
|
68
|
-
test('read nonce', async () => {
|
|
69
|
-
const { result } = await signer.callContract({
|
|
70
|
-
contract_address: signer.address,
|
|
71
|
-
entry_point_selector: stark.getSelectorFromName('get_nonce'),
|
|
72
|
-
});
|
|
73
|
-
const nonce = result[0];
|
|
74
|
-
|
|
75
|
-
expect(number.toBN(nonce).toString()).toStrictEqual(number.toBN(0).toString());
|
|
76
|
-
});
|
|
77
|
-
test('read balance of wallet', async () => {
|
|
78
|
-
const { res } = await erc20.call('balance_of', {
|
|
79
|
-
user: walletAddress,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(1000).toString());
|
|
83
|
-
});
|
|
84
|
-
test('execute by wallet owner', async () => {
|
|
85
|
-
const { code, transaction_hash } = await signer.addTransaction({
|
|
86
|
-
type: 'INVOKE_FUNCTION',
|
|
87
|
-
contract_address: erc20Address,
|
|
88
|
-
entry_point_selector: stark.getSelectorFromName('transfer'),
|
|
89
|
-
calldata: [erc20Address, '10'],
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
93
|
-
await defaultProvider.waitForTx(transaction_hash);
|
|
94
|
-
});
|
|
95
|
-
test('read balance of wallet after transfer', async () => {
|
|
96
|
-
const { res } = await erc20.call('balance_of', {
|
|
97
|
-
user: walletAddress,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(990).toString());
|
|
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
|
-
});
|
|
119
|
-
});
|
package/dist/types.d.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import type { ec as EC } from 'elliptic';
|
|
2
|
-
import type { BigNumberish } from './utils/number';
|
|
3
|
-
export declare type KeyPair = EC.KeyPair;
|
|
4
|
-
export declare type Signature = BigNumberish[];
|
|
5
|
-
export declare type GetContractAddressesResponse = {
|
|
6
|
-
Starknet: string;
|
|
7
|
-
GpsStatementVerifier: string;
|
|
8
|
-
};
|
|
9
|
-
export declare type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
10
|
-
export declare type TransactionStatus = 'TRANSACTION_RECEIVED';
|
|
11
|
-
export declare type Type = 'DEPLOY' | 'INVOKE_FUNCTION';
|
|
12
|
-
export declare type EntryPointType = 'EXTERNAL';
|
|
13
|
-
export declare type CompressedProgram = string;
|
|
14
|
-
export declare type AbiEntry = {
|
|
15
|
-
name: string;
|
|
16
|
-
type: 'felt' | 'felt*' | string;
|
|
17
|
-
};
|
|
18
|
-
export declare type FunctionAbi = {
|
|
19
|
-
inputs: AbiEntry[];
|
|
20
|
-
name: string;
|
|
21
|
-
outputs: AbiEntry[];
|
|
22
|
-
stateMutability?: 'view';
|
|
23
|
-
type: 'function';
|
|
24
|
-
};
|
|
25
|
-
export declare type StructAbi = {
|
|
26
|
-
members: (AbiEntry & {
|
|
27
|
-
offset: number;
|
|
28
|
-
})[];
|
|
29
|
-
name: string;
|
|
30
|
-
size: number;
|
|
31
|
-
type: 'struct';
|
|
32
|
-
};
|
|
33
|
-
export declare type Abi = FunctionAbi | StructAbi;
|
|
34
|
-
export declare type EntryPointsByType = object;
|
|
35
|
-
export declare type Program = object;
|
|
36
|
-
export declare type BlockNumber = 'pending' | null | number;
|
|
37
|
-
export declare type CompiledContract = {
|
|
38
|
-
abi: Abi[];
|
|
39
|
-
entry_points_by_type: EntryPointsByType;
|
|
40
|
-
program: Program;
|
|
41
|
-
};
|
|
42
|
-
export declare type CompressedCompiledContract = Omit<CompiledContract, 'program'>;
|
|
43
|
-
export declare type DeployTransaction = {
|
|
44
|
-
type: 'DEPLOY';
|
|
45
|
-
contract_definition: CompressedCompiledContract;
|
|
46
|
-
contract_address_salt: BigNumberish;
|
|
47
|
-
constructor_calldata: string[];
|
|
48
|
-
nonce?: BigNumberish;
|
|
49
|
-
};
|
|
50
|
-
export declare type InvokeFunctionTransaction = {
|
|
51
|
-
type: 'INVOKE_FUNCTION';
|
|
52
|
-
contract_address: string;
|
|
53
|
-
signature?: Signature;
|
|
54
|
-
entry_point_type?: EntryPointType;
|
|
55
|
-
entry_point_selector: string;
|
|
56
|
-
calldata?: string[];
|
|
57
|
-
nonce?: BigNumberish;
|
|
58
|
-
};
|
|
59
|
-
export declare type CallContractTransaction = Omit<InvokeFunctionTransaction, 'type'>;
|
|
60
|
-
export declare type Transaction = DeployTransaction | InvokeFunctionTransaction;
|
|
61
|
-
export declare type CallContractResponse = {
|
|
62
|
-
result: string[];
|
|
63
|
-
};
|
|
64
|
-
export declare type GetBlockResponse = {
|
|
65
|
-
block_number: number;
|
|
66
|
-
state_root: string;
|
|
67
|
-
block_hash: string;
|
|
68
|
-
transactions: {
|
|
69
|
-
[txHash: string]: Transaction;
|
|
70
|
-
};
|
|
71
|
-
timestamp: number;
|
|
72
|
-
transaction_receipts: {
|
|
73
|
-
[txHash: string]: {
|
|
74
|
-
block_hash: string;
|
|
75
|
-
transaction_hash: string;
|
|
76
|
-
l2_to_l1_messages: {
|
|
77
|
-
to_address: string;
|
|
78
|
-
payload: string[];
|
|
79
|
-
from_address: string;
|
|
80
|
-
}[];
|
|
81
|
-
block_number: BlockNumber;
|
|
82
|
-
status: Status;
|
|
83
|
-
transaction_index: number;
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
previous_block_hash: string;
|
|
87
|
-
status: Status;
|
|
88
|
-
};
|
|
89
|
-
export declare type GetCodeResponse = {
|
|
90
|
-
bytecode: string[];
|
|
91
|
-
abi: Abi[];
|
|
92
|
-
};
|
|
93
|
-
export declare type GetTransactionStatusResponse = {
|
|
94
|
-
tx_status: Status;
|
|
95
|
-
block_hash: string;
|
|
96
|
-
};
|
|
97
|
-
export declare type GetTransactionResponse = {
|
|
98
|
-
status: Status;
|
|
99
|
-
transaction: Transaction;
|
|
100
|
-
block_hash: string;
|
|
101
|
-
block_number: BlockNumber;
|
|
102
|
-
transaction_index: number;
|
|
103
|
-
transaction_hash: string;
|
|
104
|
-
};
|
|
105
|
-
export declare type AddTransactionResponse = {
|
|
106
|
-
code: TransactionStatus;
|
|
107
|
-
transaction_hash: string;
|
|
108
|
-
address?: string;
|
|
109
|
-
};
|
package/src/types.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import type { ec as EC } from 'elliptic';
|
|
2
|
-
|
|
3
|
-
import type { BigNumberish } from './utils/number';
|
|
4
|
-
|
|
5
|
-
export type KeyPair = EC.KeyPair;
|
|
6
|
-
export type Signature = BigNumberish[];
|
|
7
|
-
|
|
8
|
-
export type GetContractAddressesResponse = {
|
|
9
|
-
Starknet: string;
|
|
10
|
-
GpsStatementVerifier: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type Status =
|
|
14
|
-
| 'NOT_RECEIVED'
|
|
15
|
-
| 'RECEIVED'
|
|
16
|
-
| 'PENDING'
|
|
17
|
-
| 'ACCEPTED_ON_L2'
|
|
18
|
-
| 'ACCEPTED_ON_L1'
|
|
19
|
-
| 'REJECTED';
|
|
20
|
-
export type TransactionStatus = 'TRANSACTION_RECEIVED';
|
|
21
|
-
export type Type = 'DEPLOY' | 'INVOKE_FUNCTION';
|
|
22
|
-
export type EntryPointType = 'EXTERNAL';
|
|
23
|
-
export type CompressedProgram = string;
|
|
24
|
-
|
|
25
|
-
export type AbiEntry = { name: string; type: 'felt' | 'felt*' | string };
|
|
26
|
-
|
|
27
|
-
export type FunctionAbi = {
|
|
28
|
-
inputs: AbiEntry[];
|
|
29
|
-
name: string;
|
|
30
|
-
outputs: AbiEntry[];
|
|
31
|
-
stateMutability?: 'view';
|
|
32
|
-
type: 'function';
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type StructAbi = {
|
|
36
|
-
members: (AbiEntry & { offset: number })[];
|
|
37
|
-
name: string;
|
|
38
|
-
size: number;
|
|
39
|
-
type: 'struct';
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export type Abi = FunctionAbi | StructAbi;
|
|
43
|
-
|
|
44
|
-
export type EntryPointsByType = object;
|
|
45
|
-
export type Program = object;
|
|
46
|
-
export type BlockNumber = 'pending' | null | number;
|
|
47
|
-
|
|
48
|
-
export type CompiledContract = {
|
|
49
|
-
abi: Abi[];
|
|
50
|
-
entry_points_by_type: EntryPointsByType;
|
|
51
|
-
program: Program;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export type CompressedCompiledContract = Omit<CompiledContract, 'program'>;
|
|
55
|
-
|
|
56
|
-
export type DeployTransaction = {
|
|
57
|
-
type: 'DEPLOY';
|
|
58
|
-
contract_definition: CompressedCompiledContract;
|
|
59
|
-
contract_address_salt: BigNumberish;
|
|
60
|
-
constructor_calldata: string[];
|
|
61
|
-
nonce?: BigNumberish;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export type InvokeFunctionTransaction = {
|
|
65
|
-
type: 'INVOKE_FUNCTION';
|
|
66
|
-
contract_address: string;
|
|
67
|
-
signature?: Signature;
|
|
68
|
-
entry_point_type?: EntryPointType;
|
|
69
|
-
entry_point_selector: string;
|
|
70
|
-
calldata?: string[];
|
|
71
|
-
nonce?: BigNumberish;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export type CallContractTransaction = Omit<InvokeFunctionTransaction, 'type'>;
|
|
75
|
-
|
|
76
|
-
export type Transaction = DeployTransaction | InvokeFunctionTransaction;
|
|
77
|
-
|
|
78
|
-
export type CallContractResponse = {
|
|
79
|
-
result: string[];
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export type GetBlockResponse = {
|
|
83
|
-
block_number: number;
|
|
84
|
-
state_root: string;
|
|
85
|
-
block_hash: string;
|
|
86
|
-
transactions: {
|
|
87
|
-
[txHash: string]: Transaction;
|
|
88
|
-
};
|
|
89
|
-
timestamp: number;
|
|
90
|
-
transaction_receipts: {
|
|
91
|
-
[txHash: string]: {
|
|
92
|
-
block_hash: string;
|
|
93
|
-
transaction_hash: string;
|
|
94
|
-
l2_to_l1_messages: {
|
|
95
|
-
to_address: string;
|
|
96
|
-
payload: string[];
|
|
97
|
-
from_address: string;
|
|
98
|
-
}[];
|
|
99
|
-
block_number: BlockNumber;
|
|
100
|
-
status: Status;
|
|
101
|
-
transaction_index: number;
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
previous_block_hash: string;
|
|
105
|
-
status: Status;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
export type GetCodeResponse = {
|
|
109
|
-
bytecode: string[];
|
|
110
|
-
abi: Abi[];
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
export type GetTransactionStatusResponse = {
|
|
114
|
-
tx_status: Status;
|
|
115
|
-
block_hash: string;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
export type GetTransactionResponse = {
|
|
119
|
-
status: Status;
|
|
120
|
-
transaction: Transaction;
|
|
121
|
-
block_hash: string;
|
|
122
|
-
block_number: BlockNumber;
|
|
123
|
-
transaction_index: number;
|
|
124
|
-
transaction_hash: string;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
export type AddTransactionResponse = {
|
|
128
|
-
code: TransactionStatus;
|
|
129
|
-
transaction_hash: string;
|
|
130
|
-
address?: string;
|
|
131
|
-
};
|