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/dist/signer/default.d.ts
CHANGED
|
@@ -1,34 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AddTransactionResponse, KeyPair, Signature, Transaction } from '../types';
|
|
1
|
+
import { Abi, Invocation, InvocationsSignerDetails, KeyPair, Signature } from '../types';
|
|
3
2
|
import { TypedData } from '../utils/typedData';
|
|
4
3
|
import { SignerInterface } from './interface';
|
|
5
|
-
export declare class Signer
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
13
|
-
*
|
|
14
|
-
* @param transaction - transaction to be invoked
|
|
15
|
-
* @returns a confirmation of invoking a function on the starknet contract
|
|
16
|
-
*/
|
|
17
|
-
addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
18
|
-
/**
|
|
19
|
-
* Sign an JSON object with the starknet private key and return the signature
|
|
20
|
-
*
|
|
21
|
-
* @param json - JSON object to be signed
|
|
22
|
-
* @returns the signature of the JSON object
|
|
23
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
24
|
-
*/
|
|
25
|
-
signMessage(typedData: TypedData): Promise<Signature>;
|
|
26
|
-
/**
|
|
27
|
-
* Hash a JSON object with pederson hash and return the hash
|
|
28
|
-
*
|
|
29
|
-
* @param json - JSON object to be hashed
|
|
30
|
-
* @returns the hash of the JSON object
|
|
31
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
32
|
-
*/
|
|
33
|
-
hashMessage(typedData: TypedData): Promise<string>;
|
|
4
|
+
export declare class Signer implements SignerInterface {
|
|
5
|
+
protected keyPair: KeyPair;
|
|
6
|
+
constructor(keyPair: KeyPair);
|
|
7
|
+
getPubKey(): Promise<string>;
|
|
8
|
+
signTransaction(transactions: Invocation[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
9
|
+
signMessage(typedData: TypedData, walletAddress: string): Promise<Signature>;
|
|
34
10
|
}
|
package/dist/signer/default.js
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (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);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
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 __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -50,136 +35,55 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
50
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
36
|
}
|
|
52
37
|
};
|
|
53
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
54
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
55
|
-
if (!m) return o;
|
|
56
|
-
var i = m.call(o), r, ar = [], e;
|
|
57
|
-
try {
|
|
58
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
59
|
-
}
|
|
60
|
-
catch (error) { e = { error: error }; }
|
|
61
|
-
finally {
|
|
62
|
-
try {
|
|
63
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
64
|
-
}
|
|
65
|
-
finally { if (e) throw e.error; }
|
|
66
|
-
}
|
|
67
|
-
return ar;
|
|
68
|
-
};
|
|
69
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
70
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
71
|
-
if (ar || !(i in from)) {
|
|
72
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
73
|
-
ar[i] = from[i];
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
77
|
-
};
|
|
78
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
79
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
80
|
-
};
|
|
81
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
82
39
|
exports.Signer = void 0;
|
|
83
|
-
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
84
|
-
var provider_1 = require("../provider");
|
|
85
40
|
var ellipticCurve_1 = require("../utils/ellipticCurve");
|
|
86
41
|
var encode_1 = require("../utils/encode");
|
|
87
42
|
var hash_1 = require("../utils/hash");
|
|
88
43
|
var number_1 = require("../utils/number");
|
|
89
44
|
var stark_1 = require("../utils/stark");
|
|
90
45
|
var typedData_1 = require("../utils/typedData");
|
|
91
|
-
var Signer = /** @class */ (function (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
var _this = _super.call(this, provider) || this;
|
|
95
|
-
_this.keyPair = keyPair;
|
|
96
|
-
_this.address = address;
|
|
97
|
-
return _this;
|
|
46
|
+
var Signer = /** @class */ (function () {
|
|
47
|
+
function Signer(keyPair) {
|
|
48
|
+
this.keyPair = keyPair;
|
|
98
49
|
}
|
|
99
|
-
|
|
100
|
-
* Invoke a function on the starknet contract
|
|
101
|
-
*
|
|
102
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
103
|
-
*
|
|
104
|
-
* @param transaction - transaction to be invoked
|
|
105
|
-
* @returns a confirmation of invoking a function on the starknet contract
|
|
106
|
-
*/
|
|
107
|
-
Signer.prototype.addTransaction = function (transaction) {
|
|
50
|
+
Signer.prototype.getPubKey = function () {
|
|
108
51
|
return __awaiter(this, void 0, void 0, function () {
|
|
109
|
-
var nonceBn, result, calldataDecimal, msgHash, signature;
|
|
110
52
|
return __generator(this, function (_a) {
|
|
111
|
-
|
|
112
|
-
case 0:
|
|
113
|
-
if (transaction.type === 'DEPLOY')
|
|
114
|
-
return [2 /*return*/, _super.prototype.addTransaction.call(this, transaction)];
|
|
115
|
-
(0, minimalistic_assert_1.default)(!transaction.signature, "Adding signatures to a signer transaction currently isn't supported");
|
|
116
|
-
if (!transaction.nonce) return [3 /*break*/, 1];
|
|
117
|
-
nonceBn = (0, number_1.toBN)(transaction.nonce);
|
|
118
|
-
return [3 /*break*/, 3];
|
|
119
|
-
case 1: return [4 /*yield*/, this.callContract({
|
|
120
|
-
contract_address: this.address,
|
|
121
|
-
entry_point_selector: (0, stark_1.getSelectorFromName)('get_nonce'),
|
|
122
|
-
})];
|
|
123
|
-
case 2:
|
|
124
|
-
result = (_a.sent()).result;
|
|
125
|
-
nonceBn = (0, number_1.toBN)(result[0]);
|
|
126
|
-
_a.label = 3;
|
|
127
|
-
case 3:
|
|
128
|
-
calldataDecimal = (transaction.calldata || []).map(function (x) { return (0, number_1.toBN)(x).toString(); });
|
|
129
|
-
msgHash = (0, encode_1.addHexPrefix)((0, hash_1.hashMessage)(this.address, transaction.contract_address, transaction.entry_point_selector, calldataDecimal, nonceBn.toString()));
|
|
130
|
-
signature = (0, ellipticCurve_1.sign)(this.keyPair, msgHash);
|
|
131
|
-
return [2 /*return*/, _super.prototype.addTransaction.call(this, {
|
|
132
|
-
type: 'INVOKE_FUNCTION',
|
|
133
|
-
entry_point_selector: (0, stark_1.getSelectorFromName)('execute'),
|
|
134
|
-
calldata: __spreadArray(__spreadArray([
|
|
135
|
-
transaction.contract_address,
|
|
136
|
-
transaction.entry_point_selector,
|
|
137
|
-
calldataDecimal.length.toString()
|
|
138
|
-
], __read(calldataDecimal), false), [
|
|
139
|
-
nonceBn.toString(),
|
|
140
|
-
], false).map(function (x) { return (0, number_1.toBN)(x).toString(); }),
|
|
141
|
-
contract_address: this.address,
|
|
142
|
-
signature: signature,
|
|
143
|
-
})];
|
|
144
|
-
}
|
|
53
|
+
return [2 /*return*/, (0, ellipticCurve_1.getStarkKey)(this.keyPair)];
|
|
145
54
|
});
|
|
146
55
|
});
|
|
147
56
|
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
*
|
|
151
|
-
* @param json - JSON object to be signed
|
|
152
|
-
* @returns the signature of the JSON object
|
|
153
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
154
|
-
*/
|
|
155
|
-
Signer.prototype.signMessage = function (typedData) {
|
|
57
|
+
Signer.prototype.signTransaction = function (transactions, transactionsDetail, abis) {
|
|
58
|
+
if (abis === void 0) { abis = []; }
|
|
156
59
|
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
-
var _a, _b;
|
|
60
|
+
var _a, contractAddress, entrypoint, _b, calldata, nonce, walletAddress, nonceBn, entrypointSelector, calldataDecimal, msgHash;
|
|
158
61
|
return __generator(this, function (_c) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
case 1: return [2 /*return*/, _a.apply(void 0, _b.concat([_c.sent()]))];
|
|
62
|
+
if (transactions.length !== 1) {
|
|
63
|
+
throw new Error('Only one transaction at a time is currently supported by this signer');
|
|
64
|
+
}
|
|
65
|
+
if ((abis === null || abis === void 0 ? void 0 : abis.length) !== 0 && abis.length !== transactions.length) {
|
|
66
|
+
throw new Error('ABI must be provided for each transaction or no transaction');
|
|
165
67
|
}
|
|
68
|
+
_a = transactions[0], contractAddress = _a.contractAddress, entrypoint = _a.entrypoint, _b = _a.calldata, calldata = _b === void 0 ? [] : _b;
|
|
69
|
+
nonce = transactionsDetail.nonce, walletAddress = transactionsDetail.walletAddress;
|
|
70
|
+
nonceBn = (0, number_1.toBN)(nonce);
|
|
71
|
+
entrypointSelector = (0, stark_1.getSelectorFromName)(entrypoint);
|
|
72
|
+
calldataDecimal = (0, number_1.bigNumberishArrayToDecimalStringArray)(calldata);
|
|
73
|
+
msgHash = (0, encode_1.addHexPrefix)((0, hash_1.hashMessage)(walletAddress, contractAddress, entrypointSelector, calldataDecimal, nonceBn.toString()));
|
|
74
|
+
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
166
75
|
});
|
|
167
76
|
});
|
|
168
77
|
};
|
|
169
|
-
|
|
170
|
-
* Hash a JSON object with pederson hash and return the hash
|
|
171
|
-
*
|
|
172
|
-
* @param json - JSON object to be hashed
|
|
173
|
-
* @returns the hash of the JSON object
|
|
174
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
175
|
-
*/
|
|
176
|
-
Signer.prototype.hashMessage = function (typedData) {
|
|
78
|
+
Signer.prototype.signMessage = function (typedData, walletAddress) {
|
|
177
79
|
return __awaiter(this, void 0, void 0, function () {
|
|
80
|
+
var msgHash;
|
|
178
81
|
return __generator(this, function (_a) {
|
|
179
|
-
|
|
82
|
+
msgHash = (0, typedData_1.getMessageHash)(typedData, walletAddress);
|
|
83
|
+
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
180
84
|
});
|
|
181
85
|
});
|
|
182
86
|
};
|
|
183
87
|
return Signer;
|
|
184
|
-
}(
|
|
88
|
+
}());
|
|
185
89
|
exports.Signer = Signer;
|
package/dist/signer/index.d.ts
CHANGED
package/dist/signer/index.js
CHANGED
|
@@ -10,5 +10,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./default"), exports);
|
|
14
13
|
__exportStar(require("./interface"), exports);
|
|
14
|
+
__exportStar(require("./default"), exports);
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare abstract class SignerInterface extends Provider {
|
|
5
|
-
abstract address: string;
|
|
1
|
+
import { Abi, Invocation, InvocationsSignerDetails, Signature } from '../types';
|
|
2
|
+
import { TypedData } from '../utils/typedData';
|
|
3
|
+
export declare abstract class SignerInterface {
|
|
6
4
|
/**
|
|
7
|
-
*
|
|
5
|
+
* Method to get the public key of the signer
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @param transaction - transaction to be invoked
|
|
12
|
-
* @returns a confirmation of invoking a function on the starknet contract
|
|
7
|
+
* @returns public key of signer as hex string with 0x prefix
|
|
13
8
|
*/
|
|
14
|
-
abstract
|
|
9
|
+
abstract getPubKey(): Promise<string>;
|
|
15
10
|
/**
|
|
16
11
|
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
17
12
|
* This adds a message prefix so it cant be interchanged with transactions
|
|
@@ -20,14 +15,18 @@ export declare abstract class SignerInterface extends Provider {
|
|
|
20
15
|
* @returns the signature of the JSON object
|
|
21
16
|
* @throws {Error} if the JSON object is not a valid JSON
|
|
22
17
|
*/
|
|
23
|
-
abstract signMessage(typedData: TypedData): Promise<Signature>;
|
|
18
|
+
abstract signMessage(typedData: TypedData, walletAddress: string): Promise<Signature>;
|
|
24
19
|
/**
|
|
25
|
-
*
|
|
26
|
-
* This adds a message prefix so it cant be interchanged with transactions
|
|
20
|
+
* Signs a transaction with the starknet private key and returns the signature
|
|
27
21
|
*
|
|
28
|
-
* @param
|
|
29
|
-
*
|
|
30
|
-
*
|
|
22
|
+
* @param invocation the invocation object containing:
|
|
23
|
+
* - contractAddress - the address of the contract
|
|
24
|
+
* - entrypoint - the entrypoint of the contract
|
|
25
|
+
* - calldata - (defaults to []) the calldata
|
|
26
|
+
* - signature - (defaults to []) the signature
|
|
27
|
+
* @param abi (optional) the abi of the contract for better displaying
|
|
28
|
+
*
|
|
29
|
+
* @returns signature
|
|
31
30
|
*/
|
|
32
|
-
abstract
|
|
31
|
+
abstract signTransaction(transactions: Invocation[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
33
32
|
}
|
package/dist/signer/interface.js
CHANGED
|
@@ -1,27 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (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);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
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 __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.SignerInterface = void 0;
|
|
19
|
-
var
|
|
20
|
-
var SignerInterface = /** @class */ (function (_super) {
|
|
21
|
-
__extends(SignerInterface, _super);
|
|
4
|
+
var SignerInterface = /** @class */ (function () {
|
|
22
5
|
function SignerInterface() {
|
|
23
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
24
6
|
}
|
|
25
7
|
return SignerInterface;
|
|
26
|
-
}(
|
|
8
|
+
}());
|
|
27
9
|
exports.SignerInterface = SignerInterface;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
2
|
+
import { BigNumberish } from '../utils/number';
|
|
3
|
+
import { Abi, BlockNumber, CompressedCompiledContract, EntryPointType, RawCalldata, Signature, Status, TransactionStatus } from './lib';
|
|
4
|
+
export declare type Endpoints = {
|
|
5
|
+
get_contract_addresses: {
|
|
6
|
+
QUERY: never;
|
|
7
|
+
REQUEST: never;
|
|
8
|
+
RESPONSE: GetContractAddressesResponse;
|
|
9
|
+
};
|
|
10
|
+
add_transaction: {
|
|
11
|
+
QUERY: never;
|
|
12
|
+
REQUEST: Transaction;
|
|
13
|
+
RESPONSE: AddTransactionResponse;
|
|
14
|
+
};
|
|
15
|
+
get_transaction: {
|
|
16
|
+
QUERY: {
|
|
17
|
+
transactionHash: string;
|
|
18
|
+
};
|
|
19
|
+
REQUEST: never;
|
|
20
|
+
RESPONSE: GetTransactionResponse;
|
|
21
|
+
};
|
|
22
|
+
get_transaction_status: {
|
|
23
|
+
QUERY: {
|
|
24
|
+
transactionHash: string;
|
|
25
|
+
};
|
|
26
|
+
REQUEST: never;
|
|
27
|
+
RESPONSE: GetTransactionStatusResponse;
|
|
28
|
+
};
|
|
29
|
+
get_storage_at: {
|
|
30
|
+
QUERY: {
|
|
31
|
+
contractAddress: string;
|
|
32
|
+
key: number;
|
|
33
|
+
blockIdentifier: BlockIdentifier;
|
|
34
|
+
};
|
|
35
|
+
REQUEST: never;
|
|
36
|
+
RESPONSE: object;
|
|
37
|
+
};
|
|
38
|
+
get_code: {
|
|
39
|
+
QUERY: {
|
|
40
|
+
contractAddress: string;
|
|
41
|
+
blockIdentifier: BlockIdentifier;
|
|
42
|
+
};
|
|
43
|
+
REQUEST: never;
|
|
44
|
+
RESPONSE: GetCodeResponse;
|
|
45
|
+
};
|
|
46
|
+
get_block: {
|
|
47
|
+
QUERY: {
|
|
48
|
+
blockIdentifier: BlockIdentifier;
|
|
49
|
+
};
|
|
50
|
+
REQUEST: never;
|
|
51
|
+
RESPONSE: GetBlockResponse;
|
|
52
|
+
};
|
|
53
|
+
call_contract: {
|
|
54
|
+
QUERY: {
|
|
55
|
+
blockIdentifier: BlockIdentifier;
|
|
56
|
+
};
|
|
57
|
+
REQUEST: CallContractTransaction;
|
|
58
|
+
RESPONSE: CallContractResponse;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export declare type GetContractAddressesResponse = {
|
|
62
|
+
Starknet: string;
|
|
63
|
+
GpsStatementVerifier: string;
|
|
64
|
+
};
|
|
65
|
+
export declare type DeployTransaction = {
|
|
66
|
+
type: 'DEPLOY';
|
|
67
|
+
contract_definition: CompressedCompiledContract;
|
|
68
|
+
contract_address_salt: BigNumberish;
|
|
69
|
+
constructor_calldata: string[];
|
|
70
|
+
nonce?: BigNumberish;
|
|
71
|
+
};
|
|
72
|
+
export declare type InvokeFunctionTransaction = {
|
|
73
|
+
type: 'INVOKE_FUNCTION';
|
|
74
|
+
contract_address: string;
|
|
75
|
+
signature?: Signature;
|
|
76
|
+
entry_point_type?: EntryPointType;
|
|
77
|
+
entry_point_selector: string;
|
|
78
|
+
calldata?: RawCalldata;
|
|
79
|
+
nonce?: BigNumberish;
|
|
80
|
+
};
|
|
81
|
+
export declare type CallContractTransaction = Omit<InvokeFunctionTransaction, 'type' | 'entry_point_type' | 'nonce'>;
|
|
82
|
+
export declare type Transaction = DeployTransaction | InvokeFunctionTransaction;
|
|
83
|
+
export declare type CallContractResponse = {
|
|
84
|
+
result: string[];
|
|
85
|
+
};
|
|
86
|
+
export declare type GetBlockResponse = {
|
|
87
|
+
block_number: number;
|
|
88
|
+
state_root: string;
|
|
89
|
+
block_hash: string;
|
|
90
|
+
transactions: {
|
|
91
|
+
[txHash: string]: Transaction;
|
|
92
|
+
};
|
|
93
|
+
timestamp: number;
|
|
94
|
+
transaction_receipts: {
|
|
95
|
+
[txHash: string]: {
|
|
96
|
+
block_hash: string;
|
|
97
|
+
transaction_hash: string;
|
|
98
|
+
l2_to_l1_messages: {
|
|
99
|
+
to_address: string;
|
|
100
|
+
payload: string[];
|
|
101
|
+
from_address: string;
|
|
102
|
+
}[];
|
|
103
|
+
block_number: BlockNumber;
|
|
104
|
+
status: Status;
|
|
105
|
+
transaction_index: number;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
previous_block_hash: string;
|
|
109
|
+
status: Status;
|
|
110
|
+
};
|
|
111
|
+
export declare type GetCodeResponse = {
|
|
112
|
+
bytecode: string[];
|
|
113
|
+
abi: Abi;
|
|
114
|
+
};
|
|
115
|
+
export declare type GetTransactionStatusResponse = {
|
|
116
|
+
tx_status: Status;
|
|
117
|
+
block_hash: string;
|
|
118
|
+
};
|
|
119
|
+
export declare type GetTransactionResponse = {
|
|
120
|
+
status: Status;
|
|
121
|
+
transaction: Transaction;
|
|
122
|
+
block_hash: string;
|
|
123
|
+
block_number: BlockNumber;
|
|
124
|
+
transaction_index: number;
|
|
125
|
+
transaction_hash: string;
|
|
126
|
+
};
|
|
127
|
+
export declare type AddTransactionResponse = {
|
|
128
|
+
code: TransactionStatus;
|
|
129
|
+
transaction_hash: string;
|
|
130
|
+
address?: string;
|
|
131
|
+
};
|
|
132
|
+
export declare type TransactionReceipt = {
|
|
133
|
+
status: Status;
|
|
134
|
+
transaction_hash: string;
|
|
135
|
+
transaction_index: number;
|
|
136
|
+
block_hash: string;
|
|
137
|
+
block_number: BlockNumber;
|
|
138
|
+
l2_to_l1_messages: string[];
|
|
139
|
+
events: string[];
|
|
140
|
+
};
|
|
141
|
+
export declare type RawArgs = {
|
|
142
|
+
[inputName: string]: string | string[] | {
|
|
143
|
+
type: 'struct';
|
|
144
|
+
[k: string]: BigNumberish;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
export declare type Calldata = string[];
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./lib"), exports);
|
|
14
|
+
__exportStar(require("./api"), exports);
|
|
15
|
+
__exportStar(require("./signer"), exports);
|
|
@@ -0,0 +1,57 @@
|
|
|
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 RawCalldata = BigNumberish[];
|
|
6
|
+
export declare type DeployContractPayload = {
|
|
7
|
+
contract: CompiledContract | string;
|
|
8
|
+
constructorCalldata?: RawCalldata;
|
|
9
|
+
addressSalt?: BigNumberish;
|
|
10
|
+
};
|
|
11
|
+
export declare type Invocation = {
|
|
12
|
+
contractAddress: string;
|
|
13
|
+
entrypoint: string;
|
|
14
|
+
calldata?: RawCalldata;
|
|
15
|
+
signature?: Signature;
|
|
16
|
+
};
|
|
17
|
+
export declare type ExecuteInvocation = Omit<Invocation, 'signature'>;
|
|
18
|
+
export declare type InvocationsDetails = {
|
|
19
|
+
nonce?: BigNumberish;
|
|
20
|
+
};
|
|
21
|
+
export declare type Call = Omit<Invocation, 'signature' | 'nonce'>;
|
|
22
|
+
export declare type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
23
|
+
export declare type TransactionStatus = 'TRANSACTION_RECEIVED';
|
|
24
|
+
export declare type Type = 'DEPLOY' | 'INVOKE_FUNCTION';
|
|
25
|
+
export declare type EntryPointType = 'EXTERNAL';
|
|
26
|
+
export declare type CompressedProgram = string;
|
|
27
|
+
export declare type AbiEntry = {
|
|
28
|
+
name: string;
|
|
29
|
+
type: 'felt' | 'felt*' | string;
|
|
30
|
+
};
|
|
31
|
+
export declare type FunctionAbi = {
|
|
32
|
+
inputs: AbiEntry[];
|
|
33
|
+
name: string;
|
|
34
|
+
outputs: AbiEntry[];
|
|
35
|
+
stateMutability?: 'view';
|
|
36
|
+
type: 'function';
|
|
37
|
+
};
|
|
38
|
+
export declare type StructAbi = {
|
|
39
|
+
members: (AbiEntry & {
|
|
40
|
+
offset: number;
|
|
41
|
+
})[];
|
|
42
|
+
name: string;
|
|
43
|
+
size: number;
|
|
44
|
+
type: 'struct';
|
|
45
|
+
};
|
|
46
|
+
export declare type Abi = Array<FunctionAbi | StructAbi>;
|
|
47
|
+
export declare type EntryPointsByType = object;
|
|
48
|
+
export declare type Program = Record<any, any>;
|
|
49
|
+
export declare type BlockNumber = 'pending' | null | number;
|
|
50
|
+
export declare type CompiledContract = {
|
|
51
|
+
abi: Abi;
|
|
52
|
+
entry_points_by_type: EntryPointsByType;
|
|
53
|
+
program: Program;
|
|
54
|
+
};
|
|
55
|
+
export declare type CompressedCompiledContract = Omit<CompiledContract, 'program'> & {
|
|
56
|
+
program: CompressedProgram;
|
|
57
|
+
};
|
|
@@ -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/dist/utils/number.d.ts
CHANGED
|
@@ -4,4 +4,6 @@ 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(input: BigNumberish, lowerBound: BigNumberish, upperBound: BigNumberish, inputName?: string): void;
|
|
9
|
+
export declare function bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[]): string[];
|
package/dist/utils/number.js
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
2
21
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
23
|
};
|
|
5
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.assertInRange = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
|
|
7
|
-
var bn_js_1 =
|
|
25
|
+
exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
|
|
26
|
+
var bn_js_1 = __importStar(require("bn.js"));
|
|
8
27
|
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
9
28
|
var encode_1 = require("./encode");
|
|
10
29
|
function isHex(hex) {
|
|
@@ -25,6 +44,13 @@ function hexToDecimalString(hex) {
|
|
|
25
44
|
return toBN("0x" + hex.replace(/^0x/, '')).toString();
|
|
26
45
|
}
|
|
27
46
|
exports.hexToDecimalString = hexToDecimalString;
|
|
47
|
+
function toFelt(num) {
|
|
48
|
+
if ((0, bn_js_1.isBN)(num)) {
|
|
49
|
+
return num.toString();
|
|
50
|
+
}
|
|
51
|
+
return toBN(num).toString();
|
|
52
|
+
}
|
|
53
|
+
exports.toFelt = toFelt;
|
|
28
54
|
/*
|
|
29
55
|
Asserts input is equal to or greater then lowerBound and lower then upperBound.
|
|
30
56
|
Assert message specifies inputName.
|
|
@@ -38,3 +64,7 @@ function assertInRange(input, lowerBound, upperBound, inputName) {
|
|
|
38
64
|
(0, minimalistic_assert_1.default)(inputBn.gte(toBN(lowerBound)) && inputBn.lt(toBN(upperBound)), "Message not signable, " + messageSuffix + ".");
|
|
39
65
|
}
|
|
40
66
|
exports.assertInRange = assertInRange;
|
|
67
|
+
function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
68
|
+
return rawCalldata.map(function (x) { return toBN(x).toString(10); });
|
|
69
|
+
}
|
|
70
|
+
exports.bigNumberishArrayToDecimalStringArray = bigNumberishArrayToDecimalStringArray;
|
package/dist/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;
|