starknet 3.18.2 → 4.0.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 +70 -0
- package/README.md +1 -2
- package/__tests__/account.test.ts +11 -56
- package/__tests__/contract.test.ts +11 -49
- package/__tests__/defaultProvider.test.ts +321 -0
- package/__tests__/fixtures.ts +32 -11
- package/__tests__/jest.setup.ts +2 -3
- package/__tests__/rpcProvider.test.ts +17 -0
- package/__tests__/sequencerProvider.test.ts +45 -0
- package/account/default.d.ts +54 -77
- package/account/default.js +271 -596
- package/account/index.js +18 -31
- package/account/interface.d.ts +66 -95
- package/account/interface.js +20 -30
- package/constants.d.ts +17 -19
- package/constants.js +2038 -2059
- package/contract/contractFactory.d.ts +25 -29
- package/contract/contractFactory.js +94 -210
- package/contract/default.d.ts +117 -146
- package/contract/default.js +582 -776
- package/contract/index.js +19 -32
- package/contract/interface.d.ts +72 -92
- package/contract/interface.js +6 -5
- package/dist/account/default.d.ts +5 -9
- package/dist/account/default.js +35 -169
- package/dist/account/interface.d.ts +3 -15
- package/dist/contract/contractFactory.js +4 -4
- package/dist/contract/default.d.ts +3 -3
- package/dist/contract/default.js +3 -2
- package/dist/contract/interface.d.ts +2 -2
- package/dist/provider/default.d.ts +18 -134
- package/dist/provider/default.js +47 -411
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +2 -0
- package/dist/provider/interface.d.ts +45 -50
- package/dist/provider/rpc.d.ts +57 -0
- package/dist/provider/rpc.js +364 -0
- package/dist/provider/sequencer.d.ts +66 -0
- package/dist/provider/sequencer.js +444 -0
- package/dist/types/account.d.ts +2 -3
- package/dist/types/api/index.d.ts +16 -0
- package/dist/types/api/index.js +18 -0
- package/dist/types/api/rpc.d.ts +221 -0
- package/dist/types/{api.js → api/rpc.js} +0 -0
- package/dist/types/api/sequencer.d.ts +289 -0
- package/dist/types/api/sequencer.js +2 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.js +15 -1
- package/dist/types/lib.d.ts +3 -1
- package/dist/types/provider.d.ts +86 -0
- package/dist/types/provider.js +2 -0
- package/dist/utils/fetchPonyfill.d.ts +2 -0
- package/dist/utils/fetchPonyfill.js +6 -0
- package/dist/utils/provider.d.ts +4 -0
- package/dist/utils/provider.js +38 -0
- package/dist/utils/responseParser/index.d.ts +11 -0
- package/dist/utils/responseParser/index.js +9 -0
- package/dist/utils/responseParser/rpc.d.ts +13 -0
- package/dist/utils/responseParser/rpc.js +96 -0
- package/dist/utils/responseParser/sequencer.d.ts +13 -0
- package/dist/utils/responseParser/sequencer.js +124 -0
- package/index.js +42 -75
- package/package.json +2 -3
- package/provider/default.d.ts +21 -175
- package/provider/default.js +139 -704
- package/provider/errors.d.ts +4 -4
- package/provider/errors.js +30 -40
- package/provider/index.d.ts +2 -0
- package/provider/index.js +22 -33
- package/provider/interface.d.ts +104 -131
- package/provider/interface.js +6 -5
- package/provider/rpc.d.ts +57 -0
- package/provider/rpc.js +364 -0
- package/provider/sequencer.d.ts +66 -0
- package/provider/sequencer.js +444 -0
- package/provider/utils.d.ts +7 -9
- package/provider/utils.js +39 -44
- package/signer/default.d.ts +5 -9
- package/signer/default.js +72 -177
- package/signer/index.js +18 -31
- package/signer/interface.d.ts +29 -33
- package/signer/interface.js +6 -5
- package/src/account/default.ts +26 -146
- package/src/account/interface.ts +5 -20
- package/src/contract/contractFactory.ts +3 -6
- package/src/contract/default.ts +6 -4
- package/src/contract/interface.ts +2 -2
- package/src/provider/default.ts +63 -395
- package/src/provider/index.ts +2 -0
- package/src/provider/interface.ts +68 -63
- package/src/provider/rpc.ts +299 -0
- package/src/provider/sequencer.ts +385 -0
- package/src/types/account.ts +2 -3
- package/src/types/api/index.ts +17 -0
- package/src/types/api/rpc.ts +247 -0
- package/src/types/api/sequencer.ts +331 -0
- package/src/types/index.ts +3 -1
- package/src/types/lib.ts +3 -1
- package/src/types/provider.ts +108 -0
- package/src/utils/fetchPonyfill.ts +4 -0
- package/src/utils/provider.ts +28 -0
- package/src/utils/responseParser/index.ts +28 -0
- package/src/utils/responseParser/rpc.ts +93 -0
- package/src/utils/responseParser/sequencer.ts +127 -0
- package/types/account.d.ts +5 -7
- package/types/account.js +2 -2
- package/types/api/index.d.ts +16 -0
- package/types/api/index.js +18 -0
- package/types/api/rpc.d.ts +221 -0
- package/types/api/rpc.js +2 -0
- package/types/api/sequencer.d.ts +289 -0
- package/types/api/sequencer.js +2 -0
- package/types/contract.d.ts +1 -1
- package/types/contract.js +2 -2
- package/types/index.d.ts +3 -1
- package/types/index.js +35 -34
- package/types/lib.d.ts +36 -41
- package/types/lib.js +2 -2
- package/types/provider.d.ts +86 -0
- package/types/provider.js +2 -0
- package/types/signer.d.ts +2 -2
- package/types/signer.js +2 -2
- package/utils/address.js +26 -37
- package/utils/ellipticCurve.d.ts +1 -6
- package/utils/ellipticCurve.js +73 -137
- package/utils/encode.js +49 -85
- package/utils/fetchPonyfill.d.ts +2 -0
- package/utils/fetchPonyfill.js +6 -0
- package/utils/hash.d.ts +4 -31
- package/utils/hash.js +76 -141
- package/utils/json.d.ts +13 -45
- package/utils/json.js +15 -22
- package/utils/number.d.ts +2 -9
- package/utils/number.js +47 -81
- package/utils/provider.d.ts +4 -0
- package/utils/provider.js +38 -0
- package/utils/responseParser/index.d.ts +11 -0
- package/utils/responseParser/index.js +9 -0
- package/utils/responseParser/rpc.d.ts +13 -0
- package/utils/responseParser/rpc.js +96 -0
- package/utils/responseParser/sequencer.d.ts +13 -0
- package/utils/responseParser/sequencer.js +124 -0
- package/utils/shortString.js +13 -21
- package/utils/stark.d.ts +0 -1
- package/utils/stark.js +59 -93
- package/utils/transaction.d.ts +3 -6
- package/utils/transaction.js +50 -81
- package/utils/typedData/index.d.ts +3 -15
- package/utils/typedData/index.js +109 -175
- package/utils/typedData/types.d.ts +9 -9
- package/utils/typedData/types.js +2 -2
- package/utils/typedData/utils.js +6 -6
- package/utils/uint256.d.ts +5 -5
- package/utils/uint256.js +16 -26
- package/www/docs/API/account.md +3 -4
- package/www/docs/API/contract.md +2 -2
- package/www/docs/API/contractFactory.md +2 -2
- package/www/docs/API/provider.md +185 -74
- package/www/guides/account.md +1 -8
- package/www/guides/erc20.md +3 -0
- package/__tests__/provider.test.ts +0 -168
- package/dist/types/api.d.ts +0 -261
- package/src/types/api.ts +0 -303
- package/types/api.d.ts +0 -287
- package/types/api.js +0 -2
package/signer/default.js
CHANGED
|
@@ -1,184 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
var __awaiter =
|
|
3
|
-
|
|
4
|
-
function (thisArg, _arguments, P, generator) {
|
|
5
|
-
function adopt(value) {
|
|
6
|
-
return value instanceof P
|
|
7
|
-
? value
|
|
8
|
-
: new P(function (resolve) {
|
|
9
|
-
resolve(value);
|
|
10
|
-
});
|
|
11
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
12
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
reject(e);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function rejected(value) {
|
|
21
|
-
try {
|
|
22
|
-
step(generator['throw'](value));
|
|
23
|
-
} catch (e) {
|
|
24
|
-
reject(e);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function step(result) {
|
|
28
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
29
|
-
}
|
|
30
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
31
9
|
});
|
|
32
|
-
|
|
33
|
-
var __generator =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
label: 0,
|
|
38
|
-
sent: function () {
|
|
39
|
-
if (t[0] & 1) throw t[1];
|
|
40
|
-
return t[1];
|
|
41
|
-
},
|
|
42
|
-
trys: [],
|
|
43
|
-
ops: [],
|
|
44
|
-
},
|
|
45
|
-
f,
|
|
46
|
-
y,
|
|
47
|
-
t,
|
|
48
|
-
g;
|
|
49
|
-
return (
|
|
50
|
-
(g = { next: verb(0), throw: verb(1), return: verb(2) }),
|
|
51
|
-
typeof Symbol === 'function' &&
|
|
52
|
-
(g[Symbol.iterator] = function () {
|
|
53
|
-
return this;
|
|
54
|
-
}),
|
|
55
|
-
g
|
|
56
|
-
);
|
|
57
|
-
function verb(n) {
|
|
58
|
-
return function (v) {
|
|
59
|
-
return step([n, v]);
|
|
60
|
-
};
|
|
61
|
-
}
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
62
15
|
function step(op) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
op[0]
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
break;
|
|
84
|
-
case 4:
|
|
85
|
-
_.label++;
|
|
86
|
-
return { value: op[1], done: false };
|
|
87
|
-
case 5:
|
|
88
|
-
_.label++;
|
|
89
|
-
y = op[1];
|
|
90
|
-
op = [0];
|
|
91
|
-
continue;
|
|
92
|
-
case 7:
|
|
93
|
-
op = _.ops.pop();
|
|
94
|
-
_.trys.pop();
|
|
95
|
-
continue;
|
|
96
|
-
default:
|
|
97
|
-
if (
|
|
98
|
-
!((t = _.trys), (t = t.length > 0 && t[t.length - 1])) &&
|
|
99
|
-
(op[0] === 6 || op[0] === 2)
|
|
100
|
-
) {
|
|
101
|
-
_ = 0;
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
|
105
|
-
_.label = op[1];
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
109
|
-
_.label = t[1];
|
|
110
|
-
t = op;
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
if (t && _.label < t[2]) {
|
|
114
|
-
_.label = t[2];
|
|
115
|
-
_.ops.push(op);
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
if (t[2]) _.ops.pop();
|
|
119
|
-
_.trys.pop();
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
op = body.call(thisArg, _);
|
|
123
|
-
} catch (e) {
|
|
124
|
-
op = [6, e];
|
|
125
|
-
y = 0;
|
|
126
|
-
} finally {
|
|
127
|
-
f = t = 0;
|
|
128
|
-
}
|
|
129
|
-
if (op[0] & 5) throw op[1];
|
|
130
|
-
return { value: op[0] ? op[1] : void 0, done: true };
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
131
36
|
}
|
|
132
|
-
|
|
133
|
-
Object.defineProperty(exports,
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
134
39
|
exports.Signer = void 0;
|
|
135
|
-
var ellipticCurve_1 = require(
|
|
136
|
-
var hash_1 = require(
|
|
137
|
-
var transaction_1 = require(
|
|
138
|
-
var typedData_1 = require(
|
|
40
|
+
var ellipticCurve_1 = require("../utils/ellipticCurve");
|
|
41
|
+
var hash_1 = require("../utils/hash");
|
|
42
|
+
var transaction_1 = require("../utils/transaction");
|
|
43
|
+
var typedData_1 = require("../utils/typedData");
|
|
139
44
|
var Signer = /** @class */ (function () {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
-
var msgHash;
|
|
176
|
-
return __generator(this, function (_a) {
|
|
177
|
-
msgHash = (0, typedData_1.getMessageHash)(typedData, accountAddress);
|
|
178
|
-
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
};
|
|
182
|
-
return Signer;
|
|
183
|
-
})();
|
|
45
|
+
function Signer(keyPair) {
|
|
46
|
+
this.keyPair = keyPair;
|
|
47
|
+
}
|
|
48
|
+
Signer.prototype.getPubKey = function () {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
50
|
+
return __generator(this, function (_a) {
|
|
51
|
+
return [2 /*return*/, (0, ellipticCurve_1.getStarkKey)(this.keyPair)];
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
Signer.prototype.signTransaction = function (transactions, transactionsDetail, abis) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var calldata, msgHash;
|
|
58
|
+
return __generator(this, function (_a) {
|
|
59
|
+
if (abis && abis.length !== transactions.length) {
|
|
60
|
+
throw new Error('ABI must be provided for each transaction or no transaction');
|
|
61
|
+
}
|
|
62
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, transactionsDetail.nonce);
|
|
63
|
+
msgHash = (0, hash_1.calculcateTransactionHash)(transactionsDetail.walletAddress, transactionsDetail.version, (0, hash_1.getSelectorFromName)('__execute__'), calldata, transactionsDetail.maxFee, transactionsDetail.chainId);
|
|
64
|
+
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
Signer.prototype.signMessage = function (typedData, accountAddress) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
+
var msgHash;
|
|
71
|
+
return __generator(this, function (_a) {
|
|
72
|
+
msgHash = (0, typedData_1.getMessageHash)(typedData, accountAddress);
|
|
73
|
+
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
return Signer;
|
|
78
|
+
}());
|
|
184
79
|
exports.Signer = Signer;
|
package/signer/index.js
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (k2 === undefined) k2 = k;
|
|
20
|
-
o[k2] = m[k];
|
|
21
|
-
});
|
|
22
|
-
var __exportStar =
|
|
23
|
-
(this && this.__exportStar) ||
|
|
24
|
-
function (m, exports) {
|
|
25
|
-
for (var p in m)
|
|
26
|
-
if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
27
|
-
__createBinding(exports, m, p);
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
30
|
-
__exportStar(require('./interface'), exports);
|
|
31
|
-
__exportStar(require('./default'), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./interface"), exports);
|
|
18
|
+
__exportStar(require("./default"), exports);
|
package/signer/interface.d.ts
CHANGED
|
@@ -1,37 +1,33 @@
|
|
|
1
1
|
import { Abi, Invocation, InvocationsSignerDetails, Signature } from '../types';
|
|
2
2
|
import { TypedData } from '../utils/typedData';
|
|
3
3
|
export declare abstract class SignerInterface {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
transactions: Invocation[],
|
|
34
|
-
transactionsDetail: InvocationsSignerDetails,
|
|
35
|
-
abis?: Abi[]
|
|
36
|
-
): Promise<Signature>;
|
|
4
|
+
/**
|
|
5
|
+
* Method to get the public key of the signer
|
|
6
|
+
*
|
|
7
|
+
* @returns public key of signer as hex string with 0x prefix
|
|
8
|
+
*/
|
|
9
|
+
abstract getPubKey(): Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
12
|
+
* This adds a message prefix so it cant be interchanged with transactions
|
|
13
|
+
*
|
|
14
|
+
* @param typedData - JSON object to be signed
|
|
15
|
+
* @param accountAddress - account
|
|
16
|
+
* @returns the signature of the JSON object
|
|
17
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
18
|
+
*/
|
|
19
|
+
abstract signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
|
|
20
|
+
/**
|
|
21
|
+
* Signs a transaction with the starknet private key and returns the signature
|
|
22
|
+
*
|
|
23
|
+
* @param invocation the invocation object containing:
|
|
24
|
+
* - contractAddress - the address of the contract
|
|
25
|
+
* - entrypoint - the entrypoint of the contract
|
|
26
|
+
* - calldata - (defaults to []) the calldata
|
|
27
|
+
* - signature - (defaults to []) the signature
|
|
28
|
+
* @param abi (optional) the abi of the contract for better displaying
|
|
29
|
+
*
|
|
30
|
+
* @returns signature
|
|
31
|
+
*/
|
|
32
|
+
abstract signTransaction(transactions: Invocation[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
37
33
|
}
|
package/signer/interface.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SignerInterface = void 0;
|
|
4
4
|
var SignerInterface = /** @class */ (function () {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function SignerInterface() {
|
|
6
|
+
}
|
|
7
|
+
return SignerInterface;
|
|
8
|
+
}());
|
|
8
9
|
exports.SignerInterface = SignerInterface;
|
package/src/account/default.ts
CHANGED
|
@@ -1,48 +1,35 @@
|
|
|
1
|
-
import assert from 'minimalistic-assert';
|
|
2
|
-
|
|
3
1
|
import { ZERO } from '../constants';
|
|
4
|
-
import {
|
|
2
|
+
import { ProviderInterface, ProviderOptions } from '../provider';
|
|
3
|
+
import { Provider } from '../provider/default';
|
|
5
4
|
import { Signer, SignerInterface } from '../signer';
|
|
6
5
|
import {
|
|
7
6
|
Abi,
|
|
8
|
-
AddTransactionResponse,
|
|
9
7
|
Call,
|
|
10
8
|
InvocationsDetails,
|
|
11
9
|
InvocationsSignerDetails,
|
|
12
|
-
|
|
10
|
+
InvokeFunctionResponse,
|
|
13
11
|
KeyPair,
|
|
14
12
|
Signature,
|
|
15
|
-
Transaction,
|
|
16
13
|
} from '../types';
|
|
17
14
|
import { EstimateFee, EstimateFeeDetails } from '../types/account';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
computeHashOnElements,
|
|
21
|
-
feeTransactionVersion,
|
|
22
|
-
getSelectorFromName,
|
|
23
|
-
transactionVersion,
|
|
24
|
-
} from '../utils/hash';
|
|
25
|
-
import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN, toHex } from '../utils/number';
|
|
26
|
-
import { encodeShortString } from '../utils/shortString';
|
|
15
|
+
import { feeTransactionVersion, transactionVersion } from '../utils/hash';
|
|
16
|
+
import { BigNumberish, toBN, toHex } from '../utils/number';
|
|
27
17
|
import { compileCalldata, estimatedFeeToMaxFee } from '../utils/stark';
|
|
28
18
|
import { fromCallsToExecuteCalldataWithNonce } from '../utils/transaction';
|
|
29
19
|
import { TypedData, getMessageHash } from '../utils/typedData';
|
|
30
20
|
import { AccountInterface } from './interface';
|
|
31
21
|
|
|
32
22
|
export class Account extends Provider implements AccountInterface {
|
|
33
|
-
public address: string;
|
|
34
|
-
|
|
35
23
|
public signer: SignerInterface;
|
|
36
24
|
|
|
37
25
|
constructor(
|
|
38
|
-
|
|
39
|
-
address: string,
|
|
26
|
+
providerOrOptions: ProviderOptions | ProviderInterface,
|
|
27
|
+
public address: string,
|
|
40
28
|
keyPairOrSigner: KeyPair | SignerInterface
|
|
41
29
|
) {
|
|
42
|
-
super(
|
|
30
|
+
super(providerOrOptions);
|
|
43
31
|
this.signer =
|
|
44
32
|
'getPubKey' in keyPairOrSigner ? keyPairOrSigner : new Signer(keyPairOrSigner as KeyPair);
|
|
45
|
-
this.address = address;
|
|
46
33
|
}
|
|
47
34
|
|
|
48
35
|
public async getNonce(): Promise<string> {
|
|
@@ -55,7 +42,7 @@ export class Account extends Provider implements AccountInterface {
|
|
|
55
42
|
|
|
56
43
|
public async estimateFee(
|
|
57
44
|
calls: Call | Call[],
|
|
58
|
-
{ nonce: providedNonce, blockIdentifier
|
|
45
|
+
{ nonce: providedNonce, blockIdentifier }: EstimateFeeDetails = {}
|
|
59
46
|
): Promise<EstimateFee> {
|
|
60
47
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
61
48
|
const nonce = providedNonce ?? (await this.getNonce());
|
|
@@ -72,26 +59,16 @@ export class Account extends Provider implements AccountInterface {
|
|
|
72
59
|
const signature = await this.signer.signTransaction(transactions, signerDetails);
|
|
73
60
|
|
|
74
61
|
const calldata = fromCallsToExecuteCalldataWithNonce(transactions, nonce);
|
|
75
|
-
const
|
|
76
|
-
'
|
|
77
|
-
|
|
78
|
-
{
|
|
79
|
-
contract_address: this.address,
|
|
80
|
-
entry_point_selector: getSelectorFromName('__execute__'),
|
|
81
|
-
calldata,
|
|
82
|
-
version: toHex(version),
|
|
83
|
-
signature: bigNumberishArrayToDecimalStringArray(signature),
|
|
84
|
-
}
|
|
62
|
+
const response = await super.getEstimateFee(
|
|
63
|
+
{ contractAddress: this.address, entrypoint: '__execute__', calldata, signature },
|
|
64
|
+
blockIdentifier,
|
|
65
|
+
{ version }
|
|
85
66
|
);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
throw new Error('Expected either amount or overall_fee in estimate_fee response');
|
|
89
|
-
}
|
|
90
|
-
const suggestedMaxFee = estimatedFeeToMaxFee(fee);
|
|
67
|
+
|
|
68
|
+
const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
|
|
91
69
|
|
|
92
70
|
return {
|
|
93
|
-
|
|
94
|
-
unit: fetchedEstimate.unit,
|
|
71
|
+
...response,
|
|
95
72
|
suggestedMaxFee,
|
|
96
73
|
};
|
|
97
74
|
}
|
|
@@ -110,7 +87,7 @@ export class Account extends Provider implements AccountInterface {
|
|
|
110
87
|
calls: Call | Call[],
|
|
111
88
|
abis: Abi[] | undefined = undefined,
|
|
112
89
|
transactionsDetail: InvocationsDetails = {}
|
|
113
|
-
): Promise<
|
|
90
|
+
): Promise<InvokeFunctionResponse> {
|
|
114
91
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
115
92
|
const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce()));
|
|
116
93
|
let maxFee: BigNumberish = '0';
|
|
@@ -121,124 +98,27 @@ export class Account extends Provider implements AccountInterface {
|
|
|
121
98
|
maxFee = suggestedMaxFee.toString();
|
|
122
99
|
}
|
|
123
100
|
|
|
101
|
+
const version = toBN(transactionVersion);
|
|
102
|
+
|
|
124
103
|
const signerDetails: InvocationsSignerDetails = {
|
|
125
104
|
walletAddress: this.address,
|
|
126
105
|
nonce,
|
|
127
106
|
maxFee,
|
|
128
|
-
version
|
|
107
|
+
version,
|
|
129
108
|
chainId: this.chainId,
|
|
130
109
|
};
|
|
131
110
|
|
|
132
111
|
const signature = await this.signer.signTransaction(transactions, signerDetails, abis);
|
|
133
112
|
|
|
134
113
|
const calldata = fromCallsToExecuteCalldataWithNonce(transactions, nonce);
|
|
135
|
-
return this.fetchEndpoint('add_transaction', undefined, {
|
|
136
|
-
type: 'INVOKE_FUNCTION',
|
|
137
|
-
contract_address: this.address,
|
|
138
|
-
entry_point_selector: getSelectorFromName('__execute__'),
|
|
139
|
-
calldata,
|
|
140
|
-
signature: bigNumberishArrayToDecimalStringArray(signature),
|
|
141
|
-
max_fee: toHex(toBN(maxFee)),
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Temporary method to allow dapps on starknet.js v2 to work with Argent X v3
|
|
147
|
-
* @deprecated to remove ASAP
|
|
148
|
-
*/
|
|
149
|
-
public async LEGACY_addTransaction(transaction: Transaction): Promise<AddTransactionResponse> {
|
|
150
|
-
if (transaction.type === 'DEPLOY') throw new Error('No DEPLOYS');
|
|
151
|
-
if (transaction.type === 'DECLARE') throw new Error('No DECLARES');
|
|
152
114
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
let nonceBn;
|
|
159
|
-
if (transaction.nonce) {
|
|
160
|
-
nonceBn = toBN(transaction.nonce);
|
|
161
|
-
} else {
|
|
162
|
-
const { result } = await this.callContract({
|
|
163
|
-
contractAddress: this.address,
|
|
164
|
-
entrypoint: 'get_nonce',
|
|
165
|
-
});
|
|
166
|
-
nonceBn = toBN(result[0]);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function hashMulticall(
|
|
170
|
-
account: string,
|
|
171
|
-
transactions: InvokeFunctionTransaction[],
|
|
172
|
-
nonce: string,
|
|
173
|
-
maxFee: string
|
|
174
|
-
) {
|
|
175
|
-
const hashArray = transactions
|
|
176
|
-
.map(({ contract_address, entry_point_selector, calldata }) => [
|
|
177
|
-
contract_address,
|
|
178
|
-
entry_point_selector,
|
|
179
|
-
computeHashOnElements(calldata || []),
|
|
180
|
-
])
|
|
181
|
-
.map(bigNumberishArrayToDecimalStringArray)
|
|
182
|
-
.map(computeHashOnElements);
|
|
183
|
-
|
|
184
|
-
return computeHashOnElements([
|
|
185
|
-
encodeShortString('StarkNet Transaction'),
|
|
186
|
-
account,
|
|
187
|
-
computeHashOnElements(hashArray),
|
|
188
|
-
nonce,
|
|
115
|
+
return this.invokeFunction(
|
|
116
|
+
{ contractAddress: this.address, entrypoint: '__execute__', calldata, signature },
|
|
117
|
+
{
|
|
189
118
|
maxFee,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const msgHash = hashMulticall(this.address, [transaction], nonceBn.toString(), '0');
|
|
194
|
-
if (!('keyPair' in this.signer)) {
|
|
195
|
-
throw new Error('No keyPair');
|
|
196
|
-
}
|
|
197
|
-
const signature = sign((this.signer as any).keyPair, msgHash);
|
|
198
|
-
|
|
199
|
-
const transformCallsToMulticallArrays = (calls: InvokeFunctionTransaction[]) => {
|
|
200
|
-
const callArray: any[] = [];
|
|
201
|
-
const calldata: BigNumberish[] = [];
|
|
202
|
-
calls.forEach((call) => {
|
|
203
|
-
const data = call.calldata || [];
|
|
204
|
-
callArray.push({
|
|
205
|
-
to: toBN(call.contract_address).toString(10),
|
|
206
|
-
selector: toBN(call.entry_point_selector).toString(10),
|
|
207
|
-
data_offset: calldata.length.toString(),
|
|
208
|
-
data_len: data.length.toString(),
|
|
209
|
-
});
|
|
210
|
-
calldata.push(...data);
|
|
211
|
-
});
|
|
212
|
-
return {
|
|
213
|
-
callArray,
|
|
214
|
-
calldata: bigNumberishArrayToDecimalStringArray(calldata),
|
|
215
|
-
};
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
const fromCallsToExecuteCalldata2 = (calls: InvokeFunctionTransaction[]): string[] => {
|
|
219
|
-
const { callArray, calldata } = transformCallsToMulticallArrays(calls);
|
|
220
|
-
return [
|
|
221
|
-
callArray.length.toString(),
|
|
222
|
-
...callArray
|
|
223
|
-
.map(
|
|
224
|
-
({ to, selector, data_offset, data_len }) =>
|
|
225
|
-
[to, selector, data_offset, data_len] as string[]
|
|
226
|
-
)
|
|
227
|
-
.flat(),
|
|
228
|
-
calldata.length.toString(),
|
|
229
|
-
...calldata,
|
|
230
|
-
];
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
const calldata = [...fromCallsToExecuteCalldata2([transaction]), nonceBn.toString()];
|
|
234
|
-
|
|
235
|
-
return this.fetchEndpoint('add_transaction', undefined, {
|
|
236
|
-
type: 'INVOKE_FUNCTION',
|
|
237
|
-
contract_address: this.address,
|
|
238
|
-
entry_point_selector: getSelectorFromName('__execute__'),
|
|
239
|
-
calldata,
|
|
240
|
-
signature: bigNumberishArrayToDecimalStringArray(signature),
|
|
241
|
-
});
|
|
119
|
+
version,
|
|
120
|
+
}
|
|
121
|
+
);
|
|
242
122
|
}
|
|
243
123
|
|
|
244
124
|
/**
|