starknet 3.18.2 → 3.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- 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__/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 +443 -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/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 +1 -1
- 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 +443 -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 +300 -0
- package/src/provider/sequencer.ts +384 -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/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/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/account/default.js
CHANGED
|
@@ -1,608 +1,283 @@
|
|
|
1
|
-
|
|
2
|
-
var __extends =
|
|
3
|
-
(this && this.__extends) ||
|
|
4
|
-
(function () {
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
5
3
|
var extendStatics = function (d, b) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
d.__proto__ = b;
|
|
11
|
-
}) ||
|
|
12
|
-
function (d, b) {
|
|
13
|
-
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
14
|
-
};
|
|
15
|
-
return extendStatics(d, b);
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
16
8
|
};
|
|
17
9
|
return function (d, b) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
25
15
|
};
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
: new P(function (resolve) {
|
|
34
|
-
resolve(value);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) {
|
|
39
|
-
try {
|
|
40
|
-
step(generator.next(value));
|
|
41
|
-
} catch (e) {
|
|
42
|
-
reject(e);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function rejected(value) {
|
|
46
|
-
try {
|
|
47
|
-
step(generator['throw'](value));
|
|
48
|
-
} catch (e) {
|
|
49
|
-
reject(e);
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
50
23
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
56
35
|
});
|
|
57
|
-
|
|
58
|
-
var __generator =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
label: 0,
|
|
63
|
-
sent: function () {
|
|
64
|
-
if (t[0] & 1) throw t[1];
|
|
65
|
-
return t[1];
|
|
66
|
-
},
|
|
67
|
-
trys: [],
|
|
68
|
-
ops: [],
|
|
69
|
-
},
|
|
70
|
-
f,
|
|
71
|
-
y,
|
|
72
|
-
t,
|
|
73
|
-
g;
|
|
74
|
-
return (
|
|
75
|
-
(g = { next: verb(0), throw: verb(1), return: verb(2) }),
|
|
76
|
-
typeof Symbol === 'function' &&
|
|
77
|
-
(g[Symbol.iterator] = function () {
|
|
78
|
-
return this;
|
|
79
|
-
}),
|
|
80
|
-
g
|
|
81
|
-
);
|
|
82
|
-
function verb(n) {
|
|
83
|
-
return function (v) {
|
|
84
|
-
return step([n, v]);
|
|
85
|
-
};
|
|
86
|
-
}
|
|
36
|
+
};
|
|
37
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
87
41
|
function step(op) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
op[0]
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
break;
|
|
109
|
-
case 4:
|
|
110
|
-
_.label++;
|
|
111
|
-
return { value: op[1], done: false };
|
|
112
|
-
case 5:
|
|
113
|
-
_.label++;
|
|
114
|
-
y = op[1];
|
|
115
|
-
op = [0];
|
|
116
|
-
continue;
|
|
117
|
-
case 7:
|
|
118
|
-
op = _.ops.pop();
|
|
119
|
-
_.trys.pop();
|
|
120
|
-
continue;
|
|
121
|
-
default:
|
|
122
|
-
if (
|
|
123
|
-
!((t = _.trys), (t = t.length > 0 && t[t.length - 1])) &&
|
|
124
|
-
(op[0] === 6 || op[0] === 2)
|
|
125
|
-
) {
|
|
126
|
-
_ = 0;
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
|
130
|
-
_.label = op[1];
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
134
|
-
_.label = t[1];
|
|
135
|
-
t = op;
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
if (t && _.label < t[2]) {
|
|
139
|
-
_.label = t[2];
|
|
140
|
-
_.ops.push(op);
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
if (t[2]) _.ops.pop();
|
|
144
|
-
_.trys.pop();
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
op = body.call(thisArg, _);
|
|
148
|
-
} catch (e) {
|
|
149
|
-
op = [6, e];
|
|
150
|
-
y = 0;
|
|
151
|
-
} finally {
|
|
152
|
-
f = t = 0;
|
|
153
|
-
}
|
|
154
|
-
if (op[0] & 5) throw op[1];
|
|
155
|
-
return { value: op[0] ? op[1] : void 0, done: true };
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
var __read =
|
|
159
|
-
(this && this.__read) ||
|
|
160
|
-
function (o, n) {
|
|
161
|
-
var m = typeof Symbol === 'function' && o[Symbol.iterator];
|
|
162
|
-
if (!m) return o;
|
|
163
|
-
var i = m.call(o),
|
|
164
|
-
r,
|
|
165
|
-
ar = [],
|
|
166
|
-
e;
|
|
167
|
-
try {
|
|
168
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
169
|
-
} catch (error) {
|
|
170
|
-
e = { error: error };
|
|
171
|
-
} finally {
|
|
172
|
-
try {
|
|
173
|
-
if (r && !r.done && (m = i['return'])) m.call(i);
|
|
174
|
-
} finally {
|
|
175
|
-
if (e) throw e.error;
|
|
176
|
-
}
|
|
42
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
+
while (_) try {
|
|
44
|
+
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;
|
|
45
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
+
switch (op[0]) {
|
|
47
|
+
case 0: case 1: t = op; break;
|
|
48
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
+
default:
|
|
52
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
+
if (t[2]) _.ops.pop();
|
|
57
|
+
_.trys.pop(); continue;
|
|
58
|
+
}
|
|
59
|
+
op = body.call(thisArg, _);
|
|
60
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
177
62
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
var __spreadArray =
|
|
181
|
-
(this && this.__spreadArray) ||
|
|
182
|
-
function (to, from, pack) {
|
|
183
|
-
if (pack || arguments.length === 2)
|
|
184
|
-
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
185
|
-
if (ar || !(i in from)) {
|
|
186
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
187
|
-
ar[i] = from[i];
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
191
|
-
};
|
|
192
|
-
var __importDefault =
|
|
193
|
-
(this && this.__importDefault) ||
|
|
194
|
-
function (mod) {
|
|
195
|
-
return mod && mod.__esModule ? mod : { default: mod };
|
|
196
|
-
};
|
|
197
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
198
65
|
exports.Account = void 0;
|
|
199
|
-
var
|
|
200
|
-
var
|
|
201
|
-
var
|
|
202
|
-
var
|
|
203
|
-
var
|
|
204
|
-
var
|
|
205
|
-
var
|
|
206
|
-
var
|
|
207
|
-
var stark_1 = require('../utils/stark');
|
|
208
|
-
var transaction_1 = require('../utils/transaction');
|
|
209
|
-
var typedData_1 = require('../utils/typedData');
|
|
66
|
+
var constants_1 = require("../constants");
|
|
67
|
+
var default_1 = require("../provider/default");
|
|
68
|
+
var signer_1 = require("../signer");
|
|
69
|
+
var hash_1 = require("../utils/hash");
|
|
70
|
+
var number_1 = require("../utils/number");
|
|
71
|
+
var stark_1 = require("../utils/stark");
|
|
72
|
+
var transaction_1 = require("../utils/transaction");
|
|
73
|
+
var typedData_1 = require("../utils/typedData");
|
|
210
74
|
var Account = /** @class */ (function (_super) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
Account.prototype.getNonce = function () {
|
|
220
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
221
|
-
var result;
|
|
222
|
-
return __generator(this, function (_a) {
|
|
223
|
-
switch (_a.label) {
|
|
224
|
-
case 0:
|
|
225
|
-
return [
|
|
226
|
-
4 /*yield*/,
|
|
227
|
-
this.callContract({
|
|
228
|
-
contractAddress: this.address,
|
|
229
|
-
entrypoint: 'get_nonce',
|
|
230
|
-
}),
|
|
231
|
-
];
|
|
232
|
-
case 1:
|
|
233
|
-
result = _a.sent().result;
|
|
234
|
-
return [2 /*return*/, (0, number_1.toHex)((0, number_1.toBN)(result[0]))];
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
};
|
|
239
|
-
Account.prototype.estimateFee = function (calls, _a) {
|
|
240
|
-
var _b;
|
|
241
|
-
var _c = _a === void 0 ? {} : _a,
|
|
242
|
-
providedNonce = _c.nonce,
|
|
243
|
-
_d = _c.blockIdentifier,
|
|
244
|
-
blockIdentifier = _d === void 0 ? 'pending' : _d;
|
|
245
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
246
|
-
var transactions,
|
|
247
|
-
nonce,
|
|
248
|
-
_e,
|
|
249
|
-
version,
|
|
250
|
-
signerDetails,
|
|
251
|
-
signature,
|
|
252
|
-
calldata,
|
|
253
|
-
fetchedEstimate,
|
|
254
|
-
fee,
|
|
255
|
-
suggestedMaxFee;
|
|
256
|
-
return __generator(this, function (_f) {
|
|
257
|
-
switch (_f.label) {
|
|
258
|
-
case 0:
|
|
259
|
-
transactions = Array.isArray(calls) ? calls : [calls];
|
|
260
|
-
if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
|
|
261
|
-
_e = providedNonce;
|
|
262
|
-
return [3 /*break*/, 3];
|
|
263
|
-
case 1:
|
|
264
|
-
return [4 /*yield*/, this.getNonce()];
|
|
265
|
-
case 2:
|
|
266
|
-
_e = _f.sent();
|
|
267
|
-
_f.label = 3;
|
|
268
|
-
case 3:
|
|
269
|
-
nonce = _e;
|
|
270
|
-
version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
|
|
271
|
-
signerDetails = {
|
|
272
|
-
walletAddress: this.address,
|
|
273
|
-
nonce: (0, number_1.toBN)(nonce),
|
|
274
|
-
maxFee: constants_1.ZERO,
|
|
275
|
-
version: version,
|
|
276
|
-
chainId: this.chainId,
|
|
277
|
-
};
|
|
278
|
-
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
279
|
-
case 4:
|
|
280
|
-
signature = _f.sent();
|
|
281
|
-
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
282
|
-
return [
|
|
283
|
-
4 /*yield*/,
|
|
284
|
-
this.fetchEndpoint(
|
|
285
|
-
'estimate_fee',
|
|
286
|
-
{ blockIdentifier: blockIdentifier },
|
|
287
|
-
{
|
|
288
|
-
contract_address: this.address,
|
|
289
|
-
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
290
|
-
calldata: calldata,
|
|
291
|
-
version: (0, number_1.toHex)(version),
|
|
292
|
-
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
293
|
-
}
|
|
294
|
-
),
|
|
295
|
-
];
|
|
296
|
-
case 5:
|
|
297
|
-
fetchedEstimate = _f.sent();
|
|
298
|
-
fee =
|
|
299
|
-
(_b = fetchedEstimate.overall_fee) !== null && _b !== void 0
|
|
300
|
-
? _b
|
|
301
|
-
: fetchedEstimate.amount;
|
|
302
|
-
if (fee === undefined) {
|
|
303
|
-
throw new Error('Expected either amount or overall_fee in estimate_fee response');
|
|
304
|
-
}
|
|
305
|
-
suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(fee);
|
|
306
|
-
return [
|
|
307
|
-
2 /*return*/,
|
|
308
|
-
{
|
|
309
|
-
amount: fee,
|
|
310
|
-
unit: fetchedEstimate.unit,
|
|
311
|
-
suggestedMaxFee: suggestedMaxFee,
|
|
312
|
-
},
|
|
313
|
-
];
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
};
|
|
318
|
-
/**
|
|
319
|
-
* Invoke execute function in account contract
|
|
320
|
-
*
|
|
321
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
322
|
-
*
|
|
323
|
-
* @param calls - one or more calls to be executed
|
|
324
|
-
* @param abis - one or more abis which can be used to display the calls
|
|
325
|
-
* @param transactionsDetail - optional transaction details
|
|
326
|
-
* @returns a confirmation of invoking a function on the starknet contract
|
|
327
|
-
*/
|
|
328
|
-
Account.prototype.execute = function (calls, abis, transactionsDetail) {
|
|
329
|
-
var _a;
|
|
330
|
-
if (abis === void 0) {
|
|
331
|
-
abis = undefined;
|
|
332
|
-
}
|
|
333
|
-
if (transactionsDetail === void 0) {
|
|
334
|
-
transactionsDetail = {};
|
|
75
|
+
__extends(Account, _super);
|
|
76
|
+
function Account(providerOrOptions, address, keyPairOrSigner) {
|
|
77
|
+
var _this = _super.call(this, providerOrOptions) || this;
|
|
78
|
+
_this.address = address;
|
|
79
|
+
_this.signer =
|
|
80
|
+
'getPubKey' in keyPairOrSigner ? keyPairOrSigner : new signer_1.Signer(keyPairOrSigner);
|
|
81
|
+
return _this;
|
|
335
82
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
)
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
Account.prototype.hashMessage = function (typedData) {
|
|
537
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
538
|
-
return __generator(this, function (_a) {
|
|
539
|
-
return [2 /*return*/, (0, typedData_1.getMessageHash)(typedData, this.address)];
|
|
540
|
-
});
|
|
541
|
-
});
|
|
542
|
-
};
|
|
543
|
-
/**
|
|
544
|
-
* Verify a signature of a given hash
|
|
545
|
-
* @warning This method is not recommended, use verifyMessage instead
|
|
546
|
-
*
|
|
547
|
-
* @param hash - JSON object to be verified
|
|
548
|
-
* @param signature - signature of the JSON object
|
|
549
|
-
* @returns true if the signature is valid, false otherwise
|
|
550
|
-
* @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
|
|
551
|
-
*/
|
|
552
|
-
Account.prototype.verifyMessageHash = function (hash, signature) {
|
|
553
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
554
|
-
var _a;
|
|
555
|
-
return __generator(this, function (_b) {
|
|
556
|
-
switch (_b.label) {
|
|
557
|
-
case 0:
|
|
558
|
-
_b.trys.push([0, 2, , 3]);
|
|
559
|
-
return [
|
|
560
|
-
4 /*yield*/,
|
|
561
|
-
this.callContract({
|
|
562
|
-
contractAddress: this.address,
|
|
563
|
-
entrypoint: 'is_valid_signature',
|
|
564
|
-
calldata: (0, stark_1.compileCalldata)({
|
|
565
|
-
hash: (0, number_1.toBN)(hash).toString(),
|
|
566
|
-
signature: signature.map(function (x) {
|
|
567
|
-
return (0, number_1.toBN)(x).toString();
|
|
568
|
-
}),
|
|
569
|
-
}),
|
|
570
|
-
}),
|
|
571
|
-
];
|
|
572
|
-
case 1:
|
|
573
|
-
_b.sent();
|
|
574
|
-
return [2 /*return*/, true];
|
|
575
|
-
case 2:
|
|
576
|
-
_a = _b.sent();
|
|
577
|
-
return [2 /*return*/, false];
|
|
578
|
-
case 3:
|
|
579
|
-
return [2 /*return*/];
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
});
|
|
583
|
-
};
|
|
584
|
-
/**
|
|
585
|
-
* Verify a signature of a JSON object
|
|
586
|
-
*
|
|
587
|
-
* @param hash - hash to be verified
|
|
588
|
-
* @param signature - signature of the hash
|
|
589
|
-
* @returns true if the signature is valid, false otherwise
|
|
590
|
-
* @throws {Error} if the signature is not a valid signature
|
|
591
|
-
*/
|
|
592
|
-
Account.prototype.verifyMessage = function (typedData, signature) {
|
|
593
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
594
|
-
var hash;
|
|
595
|
-
return __generator(this, function (_a) {
|
|
596
|
-
switch (_a.label) {
|
|
597
|
-
case 0:
|
|
598
|
-
return [4 /*yield*/, this.hashMessage(typedData)];
|
|
599
|
-
case 1:
|
|
600
|
-
hash = _a.sent();
|
|
601
|
-
return [2 /*return*/, this.verifyMessageHash(hash, signature)];
|
|
602
|
-
}
|
|
603
|
-
});
|
|
604
|
-
});
|
|
605
|
-
};
|
|
606
|
-
return Account;
|
|
607
|
-
})(provider_1.Provider);
|
|
83
|
+
Account.prototype.getNonce = function () {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
+
var result;
|
|
86
|
+
return __generator(this, function (_a) {
|
|
87
|
+
switch (_a.label) {
|
|
88
|
+
case 0: return [4 /*yield*/, this.callContract({
|
|
89
|
+
contractAddress: this.address,
|
|
90
|
+
entrypoint: 'get_nonce',
|
|
91
|
+
})];
|
|
92
|
+
case 1:
|
|
93
|
+
result = (_a.sent()).result;
|
|
94
|
+
return [2 /*return*/, (0, number_1.toHex)((0, number_1.toBN)(result[0]))];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
Account.prototype.estimateFee = function (calls, _a) {
|
|
100
|
+
var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, blockIdentifier = _b.blockIdentifier;
|
|
101
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
var transactions, nonce, _c, version, signerDetails, signature, calldata, response, suggestedMaxFee;
|
|
103
|
+
return __generator(this, function (_d) {
|
|
104
|
+
switch (_d.label) {
|
|
105
|
+
case 0:
|
|
106
|
+
transactions = Array.isArray(calls) ? calls : [calls];
|
|
107
|
+
if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
|
|
108
|
+
_c = providedNonce;
|
|
109
|
+
return [3 /*break*/, 3];
|
|
110
|
+
case 1: return [4 /*yield*/, this.getNonce()];
|
|
111
|
+
case 2:
|
|
112
|
+
_c = (_d.sent());
|
|
113
|
+
_d.label = 3;
|
|
114
|
+
case 3:
|
|
115
|
+
nonce = _c;
|
|
116
|
+
version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
|
|
117
|
+
signerDetails = {
|
|
118
|
+
walletAddress: this.address,
|
|
119
|
+
nonce: (0, number_1.toBN)(nonce),
|
|
120
|
+
maxFee: constants_1.ZERO,
|
|
121
|
+
version: version,
|
|
122
|
+
chainId: this.chainId,
|
|
123
|
+
};
|
|
124
|
+
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
125
|
+
case 4:
|
|
126
|
+
signature = _d.sent();
|
|
127
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
128
|
+
return [4 /*yield*/, _super.prototype.getEstimateFee.call(this, { contractAddress: this.address, entrypoint: '__execute__', calldata: calldata, signature: signature }, blockIdentifier, { version: version })];
|
|
129
|
+
case 5:
|
|
130
|
+
response = _d.sent();
|
|
131
|
+
suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
|
|
132
|
+
return [2 /*return*/, __assign(__assign({}, response), { suggestedMaxFee: suggestedMaxFee })];
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Invoke execute function in account contract
|
|
139
|
+
*
|
|
140
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
141
|
+
*
|
|
142
|
+
* @param calls - one or more calls to be executed
|
|
143
|
+
* @param abis - one or more abis which can be used to display the calls
|
|
144
|
+
* @param transactionsDetail - optional transaction details
|
|
145
|
+
* @returns a confirmation of invoking a function on the starknet contract
|
|
146
|
+
*/
|
|
147
|
+
Account.prototype.execute = function (calls, abis, transactionsDetail) {
|
|
148
|
+
var _a;
|
|
149
|
+
if (abis === void 0) { abis = undefined; }
|
|
150
|
+
if (transactionsDetail === void 0) { transactionsDetail = {}; }
|
|
151
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
152
|
+
var transactions, nonce, _b, _c, maxFee, suggestedMaxFee, version, signerDetails, signature, calldata;
|
|
153
|
+
return __generator(this, function (_d) {
|
|
154
|
+
switch (_d.label) {
|
|
155
|
+
case 0:
|
|
156
|
+
transactions = Array.isArray(calls) ? calls : [calls];
|
|
157
|
+
_b = number_1.toBN;
|
|
158
|
+
if (!((_a = transactionsDetail.nonce) !== null && _a !== void 0)) return [3 /*break*/, 1];
|
|
159
|
+
_c = _a;
|
|
160
|
+
return [3 /*break*/, 3];
|
|
161
|
+
case 1: return [4 /*yield*/, this.getNonce()];
|
|
162
|
+
case 2:
|
|
163
|
+
_c = (_d.sent());
|
|
164
|
+
_d.label = 3;
|
|
165
|
+
case 3:
|
|
166
|
+
nonce = _b.apply(void 0, [_c]);
|
|
167
|
+
maxFee = '0';
|
|
168
|
+
if (!(transactionsDetail.maxFee || transactionsDetail.maxFee === 0)) return [3 /*break*/, 4];
|
|
169
|
+
maxFee = transactionsDetail.maxFee;
|
|
170
|
+
return [3 /*break*/, 6];
|
|
171
|
+
case 4: return [4 /*yield*/, this.estimateFee(transactions, { nonce: nonce })];
|
|
172
|
+
case 5:
|
|
173
|
+
suggestedMaxFee = (_d.sent()).suggestedMaxFee;
|
|
174
|
+
maxFee = suggestedMaxFee.toString();
|
|
175
|
+
_d.label = 6;
|
|
176
|
+
case 6:
|
|
177
|
+
version = (0, number_1.toBN)(hash_1.transactionVersion);
|
|
178
|
+
signerDetails = {
|
|
179
|
+
walletAddress: this.address,
|
|
180
|
+
nonce: nonce,
|
|
181
|
+
maxFee: maxFee,
|
|
182
|
+
version: version,
|
|
183
|
+
chainId: this.chainId,
|
|
184
|
+
};
|
|
185
|
+
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
186
|
+
case 7:
|
|
187
|
+
signature = _d.sent();
|
|
188
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
189
|
+
return [2 /*return*/, this.invokeFunction({ contractAddress: this.address, entrypoint: '__execute__', calldata: calldata, signature: signature }, {
|
|
190
|
+
maxFee: maxFee,
|
|
191
|
+
version: version,
|
|
192
|
+
})];
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Sign an JSON object with the starknet private key and return the signature
|
|
199
|
+
*
|
|
200
|
+
* @param json - JSON object to be signed
|
|
201
|
+
* @returns the signature of the JSON object
|
|
202
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
203
|
+
*/
|
|
204
|
+
Account.prototype.signMessage = function (typedData) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
206
|
+
return __generator(this, function (_a) {
|
|
207
|
+
return [2 /*return*/, this.signer.signMessage(typedData, this.address)];
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Hash a JSON object with pederson hash and return the hash
|
|
213
|
+
*
|
|
214
|
+
* @param json - JSON object to be hashed
|
|
215
|
+
* @returns the hash of the JSON object
|
|
216
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
217
|
+
*/
|
|
218
|
+
Account.prototype.hashMessage = function (typedData) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
220
|
+
return __generator(this, function (_a) {
|
|
221
|
+
return [2 /*return*/, (0, typedData_1.getMessageHash)(typedData, this.address)];
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Verify a signature of a given hash
|
|
227
|
+
* @warning This method is not recommended, use verifyMessage instead
|
|
228
|
+
*
|
|
229
|
+
* @param hash - JSON object to be verified
|
|
230
|
+
* @param signature - signature of the JSON object
|
|
231
|
+
* @returns true if the signature is valid, false otherwise
|
|
232
|
+
* @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
|
|
233
|
+
*/
|
|
234
|
+
Account.prototype.verifyMessageHash = function (hash, signature) {
|
|
235
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
236
|
+
var _a;
|
|
237
|
+
return __generator(this, function (_b) {
|
|
238
|
+
switch (_b.label) {
|
|
239
|
+
case 0:
|
|
240
|
+
_b.trys.push([0, 2, , 3]);
|
|
241
|
+
return [4 /*yield*/, this.callContract({
|
|
242
|
+
contractAddress: this.address,
|
|
243
|
+
entrypoint: 'is_valid_signature',
|
|
244
|
+
calldata: (0, stark_1.compileCalldata)({
|
|
245
|
+
hash: (0, number_1.toBN)(hash).toString(),
|
|
246
|
+
signature: signature.map(function (x) { return (0, number_1.toBN)(x).toString(); }),
|
|
247
|
+
}),
|
|
248
|
+
})];
|
|
249
|
+
case 1:
|
|
250
|
+
_b.sent();
|
|
251
|
+
return [2 /*return*/, true];
|
|
252
|
+
case 2:
|
|
253
|
+
_a = _b.sent();
|
|
254
|
+
return [2 /*return*/, false];
|
|
255
|
+
case 3: return [2 /*return*/];
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Verify a signature of a JSON object
|
|
262
|
+
*
|
|
263
|
+
* @param hash - hash to be verified
|
|
264
|
+
* @param signature - signature of the hash
|
|
265
|
+
* @returns true if the signature is valid, false otherwise
|
|
266
|
+
* @throws {Error} if the signature is not a valid signature
|
|
267
|
+
*/
|
|
268
|
+
Account.prototype.verifyMessage = function (typedData, signature) {
|
|
269
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
270
|
+
var hash;
|
|
271
|
+
return __generator(this, function (_a) {
|
|
272
|
+
switch (_a.label) {
|
|
273
|
+
case 0: return [4 /*yield*/, this.hashMessage(typedData)];
|
|
274
|
+
case 1:
|
|
275
|
+
hash = _a.sent();
|
|
276
|
+
return [2 /*return*/, this.verifyMessageHash(hash, signature)];
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
return Account;
|
|
282
|
+
}(default_1.Provider));
|
|
608
283
|
exports.Account = Account;
|