starknet 4.12.0 → 4.13.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 +1 -0
- package/CHANGELOG.md +14 -0
- package/__tests__/account.test.ts +0 -2
- package/dist/index.d.ts +2683 -24
- package/dist/index.global.js +22994 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +4713 -53
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4655 -0
- package/dist/index.mjs.map +1 -0
- package/index.d.ts +2683 -24
- package/index.global.js +22994 -0
- package/index.global.js.map +1 -0
- package/index.js +4713 -53
- package/index.js.map +1 -0
- package/index.mjs +4655 -0
- package/index.mjs.map +1 -0
- package/package.json +8 -2
- package/src/account/default.ts +43 -8
- package/src/account/interface.ts +25 -2
- package/src/constants.ts +0 -1
- package/src/provider/default.ts +3 -0
- package/src/provider/interface.ts +2 -0
- package/src/provider/rpc.ts +4 -4
- package/src/provider/sequencer.ts +4 -1
- package/src/types/lib.ts +1 -1
- package/src/types/provider.ts +5 -0
- package/src/utils/ellipticCurve.ts +3 -1
- package/src/utils/fetchPonyfill.ts +3 -2
- package/src/utils/hash.ts +3 -2
- package/src/utils/number.ts +2 -2
- package/tsup.config.ts +10 -0
- package/account/default.d.ts +0 -30
- package/account/default.js +0 -526
- package/account/index.d.ts +0 -2
- package/account/index.js +0 -18
- package/account/interface.d.ts +0 -161
- package/account/interface.js +0 -27
- package/constants.d.ts +0 -36
- package/constants.js +0 -2067
- package/contract/contractFactory.d.ts +0 -31
- package/contract/contractFactory.js +0 -102
- package/contract/default.d.ts +0 -108
- package/contract/default.js +0 -640
- package/contract/index.d.ts +0 -3
- package/contract/index.js +0 -19
- package/contract/interface.d.ts +0 -80
- package/contract/interface.js +0 -9
- package/dist/account/default.d.ts +0 -30
- package/dist/account/default.js +0 -526
- package/dist/account/index.d.ts +0 -2
- package/dist/account/index.js +0 -18
- package/dist/account/interface.d.ts +0 -161
- package/dist/account/interface.js +0 -27
- package/dist/constants.d.ts +0 -36
- package/dist/constants.js +0 -2067
- package/dist/contract/contractFactory.d.ts +0 -31
- package/dist/contract/contractFactory.js +0 -102
- package/dist/contract/default.d.ts +0 -108
- package/dist/contract/default.js +0 -640
- package/dist/contract/index.d.ts +0 -3
- package/dist/contract/index.js +0 -19
- package/dist/contract/interface.d.ts +0 -80
- package/dist/contract/interface.js +0 -9
- package/dist/provider/default.d.ts +0 -37
- package/dist/provider/default.js +0 -207
- package/dist/provider/errors.d.ts +0 -9
- package/dist/provider/errors.js +0 -40
- package/dist/provider/index.d.ts +0 -7
- package/dist/provider/index.js +0 -24
- package/dist/provider/interface.d.ts +0 -203
- package/dist/provider/interface.js +0 -9
- package/dist/provider/rpc.d.ts +0 -86
- package/dist/provider/rpc.js +0 -605
- package/dist/provider/sequencer.d.ts +0 -79
- package/dist/provider/sequencer.js +0 -575
- package/dist/provider/utils.d.ts +0 -30
- package/dist/provider/utils.js +0 -84
- package/dist/signer/default.d.ts +0 -13
- package/dist/signer/default.js +0 -102
- package/dist/signer/index.d.ts +0 -2
- package/dist/signer/index.js +0 -18
- package/dist/signer/interface.d.ts +0 -60
- package/dist/signer/interface.js +0 -9
- package/dist/types/account.d.ts +0 -11
- package/dist/types/account.js +0 -2
- package/dist/types/api/index.d.ts +0 -10
- package/dist/types/api/index.js +0 -18
- package/dist/types/api/openrpc.d.ts +0 -572
- package/dist/types/api/openrpc.js +0 -45
- package/dist/types/api/rpc.d.ts +0 -43
- package/dist/types/api/rpc.js +0 -2
- package/dist/types/api/sequencer.d.ts +0 -320
- package/dist/types/api/sequencer.js +0 -2
- package/dist/types/contract.d.ts +0 -5
- package/dist/types/contract.js +0 -2
- package/dist/types/index.d.ts +0 -7
- package/dist/types/index.js +0 -35
- package/dist/types/lib.d.ts +0 -120
- package/dist/types/lib.js +0 -8
- package/dist/types/provider.d.ts +0 -99
- package/dist/types/provider.js +0 -2
- package/dist/types/signer.d.ts +0 -19
- package/dist/types/signer.js +0 -2
- package/dist/utils/address.d.ts +0 -5
- package/dist/utils/address.js +0 -41
- package/dist/utils/ellipticCurve.d.ts +0 -29
- package/dist/utils/ellipticCurve.js +0 -132
- package/dist/utils/encode.d.ts +0 -15
- package/dist/utils/encode.js +0 -96
- package/dist/utils/fetchPonyfill.d.ts +0 -2
- package/dist/utils/fetchPonyfill.js +0 -6
- package/dist/utils/hash.d.ts +0 -37
- package/dist/utils/hash.js +0 -162
- package/dist/utils/json.d.ts +0 -16
- package/dist/utils/json.js +0 -19
- package/dist/utils/merkle.d.ts +0 -10
- package/dist/utils/merkle.js +0 -89
- package/dist/utils/number.d.ts +0 -16
- package/dist/utils/number.js +0 -112
- package/dist/utils/provider.d.ts +0 -4
- package/dist/utils/provider.js +0 -38
- package/dist/utils/responseParser/index.d.ts +0 -11
- package/dist/utils/responseParser/index.js +0 -9
- package/dist/utils/responseParser/rpc.d.ts +0 -20
- package/dist/utils/responseParser/rpc.js +0 -44
- package/dist/utils/responseParser/sequencer.d.ts +0 -17
- package/dist/utils/responseParser/sequencer.js +0 -99
- package/dist/utils/shortString.d.ts +0 -4
- package/dist/utils/shortString.js +0 -26
- package/dist/utils/stark.d.ts +0 -16
- package/dist/utils/stark.js +0 -91
- package/dist/utils/transaction.d.ts +0 -20
- package/dist/utils/transaction.js +0 -79
- package/dist/utils/typedData/index.d.ts +0 -72
- package/dist/utils/typedData/index.js +0 -239
- package/dist/utils/typedData/types.d.ts +0 -32
- package/dist/utils/typedData/types.js +0 -2
- package/dist/utils/typedData/utils.d.ts +0 -8
- package/dist/utils/typedData/utils.js +0 -16
- package/dist/utils/uint256.d.ts +0 -11
- package/dist/utils/uint256.js +0 -28
- package/dist/utils/url.d.ts +0 -7
- package/dist/utils/url.js +0 -49
- package/provider/default.d.ts +0 -37
- package/provider/default.js +0 -207
- package/provider/errors.d.ts +0 -9
- package/provider/errors.js +0 -40
- package/provider/index.d.ts +0 -7
- package/provider/index.js +0 -24
- package/provider/interface.d.ts +0 -203
- package/provider/interface.js +0 -9
- package/provider/rpc.d.ts +0 -86
- package/provider/rpc.js +0 -605
- package/provider/sequencer.d.ts +0 -79
- package/provider/sequencer.js +0 -575
- package/provider/utils.d.ts +0 -30
- package/provider/utils.js +0 -84
- package/signer/default.d.ts +0 -13
- package/signer/default.js +0 -102
- package/signer/index.d.ts +0 -2
- package/signer/index.js +0 -18
- package/signer/interface.d.ts +0 -60
- package/signer/interface.js +0 -9
- package/types/account.d.ts +0 -11
- package/types/account.js +0 -2
- package/types/api/index.d.ts +0 -10
- package/types/api/index.js +0 -18
- package/types/api/openrpc.d.ts +0 -572
- package/types/api/openrpc.js +0 -45
- package/types/api/rpc.d.ts +0 -43
- package/types/api/rpc.js +0 -2
- package/types/api/sequencer.d.ts +0 -320
- package/types/api/sequencer.js +0 -2
- package/types/contract.d.ts +0 -5
- package/types/contract.js +0 -2
- package/types/index.d.ts +0 -7
- package/types/index.js +0 -35
- package/types/lib.d.ts +0 -120
- package/types/lib.js +0 -8
- package/types/provider.d.ts +0 -99
- package/types/provider.js +0 -2
- package/types/signer.d.ts +0 -19
- package/types/signer.js +0 -2
- package/utils/address.d.ts +0 -5
- package/utils/address.js +0 -41
- package/utils/ellipticCurve.d.ts +0 -29
- package/utils/ellipticCurve.js +0 -132
- package/utils/encode.d.ts +0 -15
- package/utils/encode.js +0 -96
- package/utils/fetchPonyfill.d.ts +0 -2
- package/utils/fetchPonyfill.js +0 -6
- package/utils/hash.d.ts +0 -37
- package/utils/hash.js +0 -162
- package/utils/json.d.ts +0 -16
- package/utils/json.js +0 -19
- package/utils/merkle.d.ts +0 -10
- package/utils/merkle.js +0 -89
- package/utils/number.d.ts +0 -16
- package/utils/number.js +0 -112
- package/utils/provider.d.ts +0 -4
- package/utils/provider.js +0 -38
- package/utils/responseParser/index.d.ts +0 -11
- package/utils/responseParser/index.js +0 -9
- package/utils/responseParser/rpc.d.ts +0 -20
- package/utils/responseParser/rpc.js +0 -44
- package/utils/responseParser/sequencer.d.ts +0 -17
- package/utils/responseParser/sequencer.js +0 -99
- package/utils/shortString.d.ts +0 -4
- package/utils/shortString.js +0 -26
- package/utils/stark.d.ts +0 -16
- package/utils/stark.js +0 -91
- package/utils/transaction.d.ts +0 -20
- package/utils/transaction.js +0 -79
- package/utils/typedData/index.d.ts +0 -72
- package/utils/typedData/index.js +0 -239
- package/utils/typedData/types.d.ts +0 -32
- package/utils/typedData/types.js +0 -2
- package/utils/typedData/utils.d.ts +0 -8
- package/utils/typedData/utils.js +0 -16
- package/utils/uint256.d.ts +0 -11
- package/utils/uint256.js +0 -28
- package/utils/url.d.ts +0 -7
- package/utils/url.js +0 -49
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { BigNumberish } from '../number';
|
|
2
|
-
import { StarkNetMerkleType, StarkNetType, TypedData } from './types';
|
|
3
|
-
export * from './types';
|
|
4
|
-
export declare function prepareSelector(selector: string): string;
|
|
5
|
-
export declare function isMerkleTreeType(type: StarkNetType): type is StarkNetMerkleType;
|
|
6
|
-
interface Context {
|
|
7
|
-
parent?: string;
|
|
8
|
-
key?: string;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Get the dependencies of a struct type. If a struct has the same dependency multiple times, it's only included once
|
|
12
|
-
* in the resulting array.
|
|
13
|
-
*
|
|
14
|
-
* @param {TypedData} typedData
|
|
15
|
-
* @param {string} type
|
|
16
|
-
* @param {string[]} [dependencies]
|
|
17
|
-
* @return {string[]}
|
|
18
|
-
*/
|
|
19
|
-
export declare const getDependencies: (types: TypedData['types'], type: string, dependencies?: string[]) => string[];
|
|
20
|
-
/**
|
|
21
|
-
* Encode a type to a string. All dependant types are alphabetically sorted.
|
|
22
|
-
*
|
|
23
|
-
* @param {TypedData} typedData
|
|
24
|
-
* @param {string} type
|
|
25
|
-
* @return {string}
|
|
26
|
-
*/
|
|
27
|
-
export declare const encodeType: (types: TypedData['types'], type: string) => string;
|
|
28
|
-
/**
|
|
29
|
-
* Get a type string as hash.
|
|
30
|
-
*
|
|
31
|
-
* @param {TypedData} typedData
|
|
32
|
-
* @param {string} type
|
|
33
|
-
* @return {string}
|
|
34
|
-
*/
|
|
35
|
-
export declare const getTypeHash: (types: TypedData['types'], type: string) => string;
|
|
36
|
-
/**
|
|
37
|
-
* Encodes a single value to an ABI serialisable string, number or Buffer. Returns the data as tuple, which consists of
|
|
38
|
-
* an array of ABI compatible types, and an array of corresponding values.
|
|
39
|
-
*
|
|
40
|
-
* @param {TypedData} typedData
|
|
41
|
-
* @param {string} type
|
|
42
|
-
* @param {any} data
|
|
43
|
-
* @returns {[string, string]}
|
|
44
|
-
*/
|
|
45
|
-
export declare const encodeValue: (types: TypedData['types'], type: string, data: unknown, ctx?: Context) => [string, string];
|
|
46
|
-
/**
|
|
47
|
-
* Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values. All
|
|
48
|
-
* dependant types are automatically encoded.
|
|
49
|
-
*
|
|
50
|
-
* @param {TypedData} typedData
|
|
51
|
-
* @param {string} type
|
|
52
|
-
* @param {Record<string, any>} data
|
|
53
|
-
*/
|
|
54
|
-
export declare const encodeData: <T extends TypedData>(types: T["types"], type: string, data: T["message"]) => string[][];
|
|
55
|
-
/**
|
|
56
|
-
* Get encoded data as a hash. The data should be a key -> value object with all the required values. All dependant
|
|
57
|
-
* types are automatically encoded.
|
|
58
|
-
*
|
|
59
|
-
* @param {TypedData} typedData
|
|
60
|
-
* @param {string} type
|
|
61
|
-
* @param {Record<string, any>} data
|
|
62
|
-
* @return {Buffer}
|
|
63
|
-
*/
|
|
64
|
-
export declare const getStructHash: <T extends TypedData>(types: T["types"], type: string, data: T["message"]) => string;
|
|
65
|
-
/**
|
|
66
|
-
* Get the EIP-191 encoded message to sign, from the typedData object.
|
|
67
|
-
*
|
|
68
|
-
* @param {TypedData} typedData
|
|
69
|
-
* @param {BigNumberish} account
|
|
70
|
-
* @return {string}
|
|
71
|
-
*/
|
|
72
|
-
export declare const getMessageHash: (typedData: TypedData, account: BigNumberish) => string;
|
|
@@ -1,239 +0,0 @@
|
|
|
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
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
17
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
18
|
-
if (!m) return o;
|
|
19
|
-
var i = m.call(o), r, ar = [], e;
|
|
20
|
-
try {
|
|
21
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
22
|
-
}
|
|
23
|
-
catch (error) { e = { error: error }; }
|
|
24
|
-
finally {
|
|
25
|
-
try {
|
|
26
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
27
|
-
}
|
|
28
|
-
finally { if (e) throw e.error; }
|
|
29
|
-
}
|
|
30
|
-
return ar;
|
|
31
|
-
};
|
|
32
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
33
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
34
|
-
if (ar || !(i in from)) {
|
|
35
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
36
|
-
ar[i] = from[i];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.getMessageHash = exports.getStructHash = exports.encodeData = exports.encodeValue = exports.getTypeHash = exports.encodeType = exports.getDependencies = exports.isMerkleTreeType = exports.prepareSelector = void 0;
|
|
43
|
-
var hash_1 = require("../hash");
|
|
44
|
-
var merkle_1 = require("../merkle");
|
|
45
|
-
var number_1 = require("../number");
|
|
46
|
-
var shortString_1 = require("../shortString");
|
|
47
|
-
var utils_1 = require("./utils");
|
|
48
|
-
__exportStar(require("./types"), exports);
|
|
49
|
-
function getHex(value) {
|
|
50
|
-
try {
|
|
51
|
-
return (0, number_1.toHex)((0, number_1.toBN)(value));
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
if (typeof value === 'string') {
|
|
55
|
-
return (0, number_1.toHex)((0, number_1.toBN)((0, shortString_1.encodeShortString)(value)));
|
|
56
|
-
}
|
|
57
|
-
throw new Error("Invalid BigNumberish: ".concat(value));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function prepareSelector(selector) {
|
|
61
|
-
return (0, number_1.isHex)(selector) ? selector : (0, hash_1.getSelectorFromName)(selector);
|
|
62
|
-
}
|
|
63
|
-
exports.prepareSelector = prepareSelector;
|
|
64
|
-
function isMerkleTreeType(type) {
|
|
65
|
-
return type.type === 'merkletree';
|
|
66
|
-
}
|
|
67
|
-
exports.isMerkleTreeType = isMerkleTreeType;
|
|
68
|
-
/**
|
|
69
|
-
* Get the dependencies of a struct type. If a struct has the same dependency multiple times, it's only included once
|
|
70
|
-
* in the resulting array.
|
|
71
|
-
*
|
|
72
|
-
* @param {TypedData} typedData
|
|
73
|
-
* @param {string} type
|
|
74
|
-
* @param {string[]} [dependencies]
|
|
75
|
-
* @return {string[]}
|
|
76
|
-
*/
|
|
77
|
-
var getDependencies = function (types, type, dependencies) {
|
|
78
|
-
if (dependencies === void 0) { dependencies = []; }
|
|
79
|
-
// Include pointers (struct arrays)
|
|
80
|
-
if (type[type.length - 1] === '*') {
|
|
81
|
-
// eslint-disable-next-line no-param-reassign
|
|
82
|
-
type = type.slice(0, -1);
|
|
83
|
-
}
|
|
84
|
-
if (dependencies.includes(type)) {
|
|
85
|
-
return dependencies;
|
|
86
|
-
}
|
|
87
|
-
if (!types[type]) {
|
|
88
|
-
return dependencies;
|
|
89
|
-
}
|
|
90
|
-
return __spreadArray([
|
|
91
|
-
type
|
|
92
|
-
], __read(types[type].reduce(function (previous, t) { return __spreadArray(__spreadArray([], __read(previous), false), __read((0, exports.getDependencies)(types, t.type, previous).filter(function (dependency) { return !previous.includes(dependency); })), false); }, [])), false);
|
|
93
|
-
};
|
|
94
|
-
exports.getDependencies = getDependencies;
|
|
95
|
-
function getMerkleTreeType(types, ctx) {
|
|
96
|
-
if (ctx.parent && ctx.key) {
|
|
97
|
-
var parentType = types[ctx.parent];
|
|
98
|
-
var merkleType = parentType.find(function (t) { return t.name === ctx.key; });
|
|
99
|
-
var isMerkleTree = isMerkleTreeType(merkleType);
|
|
100
|
-
if (!isMerkleTree) {
|
|
101
|
-
throw new Error("".concat(ctx.key, " is not a merkle tree"));
|
|
102
|
-
}
|
|
103
|
-
if (merkleType.contains.endsWith('*')) {
|
|
104
|
-
throw new Error("Merkle tree contain property must not be an array but was given ".concat(ctx.key));
|
|
105
|
-
}
|
|
106
|
-
return merkleType.contains;
|
|
107
|
-
}
|
|
108
|
-
return 'raw';
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Encode a type to a string. All dependant types are alphabetically sorted.
|
|
112
|
-
*
|
|
113
|
-
* @param {TypedData} typedData
|
|
114
|
-
* @param {string} type
|
|
115
|
-
* @return {string}
|
|
116
|
-
*/
|
|
117
|
-
var encodeType = function (types, type) {
|
|
118
|
-
var _a = __read((0, exports.getDependencies)(types, type)), primary = _a[0], dependencies = _a.slice(1);
|
|
119
|
-
var newTypes = !primary ? [] : __spreadArray([primary], __read(dependencies.sort()), false);
|
|
120
|
-
return newTypes
|
|
121
|
-
.map(function (dependency) {
|
|
122
|
-
return "".concat(dependency, "(").concat(types[dependency].map(function (t) { return "".concat(t.name, ":").concat(t.type); }), ")");
|
|
123
|
-
})
|
|
124
|
-
.join('');
|
|
125
|
-
};
|
|
126
|
-
exports.encodeType = encodeType;
|
|
127
|
-
/**
|
|
128
|
-
* Get a type string as hash.
|
|
129
|
-
*
|
|
130
|
-
* @param {TypedData} typedData
|
|
131
|
-
* @param {string} type
|
|
132
|
-
* @return {string}
|
|
133
|
-
*/
|
|
134
|
-
var getTypeHash = function (types, type) {
|
|
135
|
-
return (0, hash_1.getSelectorFromName)((0, exports.encodeType)(types, type));
|
|
136
|
-
};
|
|
137
|
-
exports.getTypeHash = getTypeHash;
|
|
138
|
-
/**
|
|
139
|
-
* Encodes a single value to an ABI serialisable string, number or Buffer. Returns the data as tuple, which consists of
|
|
140
|
-
* an array of ABI compatible types, and an array of corresponding values.
|
|
141
|
-
*
|
|
142
|
-
* @param {TypedData} typedData
|
|
143
|
-
* @param {string} type
|
|
144
|
-
* @param {any} data
|
|
145
|
-
* @returns {[string, string]}
|
|
146
|
-
*/
|
|
147
|
-
var encodeValue = function (types, type, data, ctx) {
|
|
148
|
-
if (ctx === void 0) { ctx = {}; }
|
|
149
|
-
if (types[type]) {
|
|
150
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
151
|
-
return [type, (0, exports.getStructHash)(types, type, data)];
|
|
152
|
-
}
|
|
153
|
-
if (Object.keys(types)
|
|
154
|
-
.map(function (x) { return "".concat(x, "*"); })
|
|
155
|
-
.includes(type)) {
|
|
156
|
-
var structHashes = data.map(function (struct) {
|
|
157
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
158
|
-
return (0, exports.getStructHash)(types, type.slice(0, -1), struct);
|
|
159
|
-
});
|
|
160
|
-
return [type, (0, hash_1.computeHashOnElements)(structHashes)];
|
|
161
|
-
}
|
|
162
|
-
if (type === 'merkletree') {
|
|
163
|
-
var merkleTreeType_1 = getMerkleTreeType(types, ctx);
|
|
164
|
-
var structHashes = data.map(function (struct) {
|
|
165
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
166
|
-
return (0, exports.encodeValue)(types, merkleTreeType_1, struct)[1];
|
|
167
|
-
});
|
|
168
|
-
var root = new merkle_1.MerkleTree(structHashes).root;
|
|
169
|
-
return ['felt', root];
|
|
170
|
-
}
|
|
171
|
-
if (type === 'felt*') {
|
|
172
|
-
return ['felt*', (0, hash_1.computeHashOnElements)(data)];
|
|
173
|
-
}
|
|
174
|
-
if (type === 'selector') {
|
|
175
|
-
return ['felt', prepareSelector(data)];
|
|
176
|
-
}
|
|
177
|
-
return [type, getHex(data)];
|
|
178
|
-
};
|
|
179
|
-
exports.encodeValue = encodeValue;
|
|
180
|
-
/**
|
|
181
|
-
* Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values. All
|
|
182
|
-
* dependant types are automatically encoded.
|
|
183
|
-
*
|
|
184
|
-
* @param {TypedData} typedData
|
|
185
|
-
* @param {string} type
|
|
186
|
-
* @param {Record<string, any>} data
|
|
187
|
-
*/
|
|
188
|
-
var encodeData = function (types, type, data) {
|
|
189
|
-
var _a = __read(types[type].reduce(function (_a, field) {
|
|
190
|
-
var _b = __read(_a, 2), ts = _b[0], vs = _b[1];
|
|
191
|
-
if (data[field.name] === undefined || data[field.name] === null) {
|
|
192
|
-
throw new Error("Cannot encode data: missing data for '".concat(field.name, "'"));
|
|
193
|
-
}
|
|
194
|
-
var value = data[field.name];
|
|
195
|
-
var _c = __read((0, exports.encodeValue)(types, field.type, value, {
|
|
196
|
-
parent: type,
|
|
197
|
-
key: field.name,
|
|
198
|
-
}), 2), t = _c[0], encodedValue = _c[1];
|
|
199
|
-
return [
|
|
200
|
-
__spreadArray(__spreadArray([], __read(ts), false), [t], false),
|
|
201
|
-
__spreadArray(__spreadArray([], __read(vs), false), [encodedValue], false),
|
|
202
|
-
];
|
|
203
|
-
}, [['felt'], [(0, exports.getTypeHash)(types, type)]]), 2), returnTypes = _a[0], values = _a[1];
|
|
204
|
-
return [returnTypes, values];
|
|
205
|
-
};
|
|
206
|
-
exports.encodeData = encodeData;
|
|
207
|
-
/**
|
|
208
|
-
* Get encoded data as a hash. The data should be a key -> value object with all the required values. All dependant
|
|
209
|
-
* types are automatically encoded.
|
|
210
|
-
*
|
|
211
|
-
* @param {TypedData} typedData
|
|
212
|
-
* @param {string} type
|
|
213
|
-
* @param {Record<string, any>} data
|
|
214
|
-
* @return {Buffer}
|
|
215
|
-
*/
|
|
216
|
-
var getStructHash = function (types, type, data) {
|
|
217
|
-
return (0, hash_1.computeHashOnElements)((0, exports.encodeData)(types, type, data)[1]);
|
|
218
|
-
};
|
|
219
|
-
exports.getStructHash = getStructHash;
|
|
220
|
-
/**
|
|
221
|
-
* Get the EIP-191 encoded message to sign, from the typedData object.
|
|
222
|
-
*
|
|
223
|
-
* @param {TypedData} typedData
|
|
224
|
-
* @param {BigNumberish} account
|
|
225
|
-
* @return {string}
|
|
226
|
-
*/
|
|
227
|
-
var getMessageHash = function (typedData, account) {
|
|
228
|
-
if (!(0, utils_1.validateTypedData)(typedData)) {
|
|
229
|
-
throw new Error('Typed data does not match JSON schema');
|
|
230
|
-
}
|
|
231
|
-
var message = [
|
|
232
|
-
(0, shortString_1.encodeShortString)('StarkNet Message'),
|
|
233
|
-
(0, exports.getStructHash)(typedData.types, 'StarkNetDomain', typedData.domain),
|
|
234
|
-
account,
|
|
235
|
-
(0, exports.getStructHash)(typedData.types, typedData.primaryType, typedData.message),
|
|
236
|
-
];
|
|
237
|
-
return (0, hash_1.computeHashOnElements)(message);
|
|
238
|
-
};
|
|
239
|
-
exports.getMessageHash = getMessageHash;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export declare type StarkNetMerkleType = {
|
|
2
|
-
name: string;
|
|
3
|
-
type: 'merkletree';
|
|
4
|
-
contains: string;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* A single type, as part of a struct. The `type` field can be any of the EIP-712 supported types.
|
|
8
|
-
*
|
|
9
|
-
* Note that the `uint` and `int` aliases like in Solidity, and fixed point numbers are not supported by the EIP-712
|
|
10
|
-
* standard.
|
|
11
|
-
*/
|
|
12
|
-
export declare type StarkNetType = {
|
|
13
|
-
name: string;
|
|
14
|
-
type: string;
|
|
15
|
-
} | StarkNetMerkleType;
|
|
16
|
-
/**
|
|
17
|
-
* The EIP712 domain struct. Any of these fields are optional, but it must contain at least one field.
|
|
18
|
-
*/
|
|
19
|
-
export interface StarkNetDomain extends Record<string, unknown> {
|
|
20
|
-
name?: string;
|
|
21
|
-
version?: string;
|
|
22
|
-
chainId?: string | number;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* The complete typed data, with all the structs, domain data, primary type of the message, and the message itself.
|
|
26
|
-
*/
|
|
27
|
-
export interface TypedData {
|
|
28
|
-
types: Record<string, StarkNetType[]>;
|
|
29
|
-
primaryType: string;
|
|
30
|
-
domain: StarkNetDomain;
|
|
31
|
-
message: Record<string, unknown>;
|
|
32
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateTypedData = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Validates that `data` matches the EIP-712 JSON schema.
|
|
6
|
-
*
|
|
7
|
-
* @param {any} data
|
|
8
|
-
* @return {boolean}
|
|
9
|
-
*/
|
|
10
|
-
var validateTypedData = function (data) {
|
|
11
|
-
var typedData = data;
|
|
12
|
-
// Validate that the data matches the EIP-712 JSON schema
|
|
13
|
-
var valid = Boolean(typedData.types && typedData.primaryType && typedData.message);
|
|
14
|
-
return valid;
|
|
15
|
-
};
|
|
16
|
-
exports.validateTypedData = validateTypedData;
|
package/dist/utils/uint256.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
|
-
import { BigNumberish } from './number';
|
|
3
|
-
export interface Uint256 {
|
|
4
|
-
low: BigNumberish;
|
|
5
|
-
high: BigNumberish;
|
|
6
|
-
}
|
|
7
|
-
export declare function uint256ToBN(uint256: Uint256): import("bn.js");
|
|
8
|
-
export declare const UINT_128_MAX: import("bn.js");
|
|
9
|
-
export declare const UINT_256_MAX: import("bn.js");
|
|
10
|
-
export declare function isUint256(bn: BigNumberish): boolean;
|
|
11
|
-
export declare function bnToUint256(bignumber: BigNumberish): Uint256;
|
package/dist/utils/uint256.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.bnToUint256 = exports.isUint256 = exports.UINT_256_MAX = exports.UINT_128_MAX = exports.uint256ToBN = void 0;
|
|
4
|
-
var encode_1 = require("./encode");
|
|
5
|
-
var number_1 = require("./number");
|
|
6
|
-
// function to convert Uint256 to BN
|
|
7
|
-
function uint256ToBN(uint256) {
|
|
8
|
-
return (0, number_1.toBN)(uint256.high).shln(128).add((0, number_1.toBN)(uint256.low));
|
|
9
|
-
}
|
|
10
|
-
exports.uint256ToBN = uint256ToBN;
|
|
11
|
-
exports.UINT_128_MAX = (0, number_1.toBN)(1).shln(128).sub((0, number_1.toBN)(1));
|
|
12
|
-
exports.UINT_256_MAX = (0, number_1.toBN)(1).shln(256).sub((0, number_1.toBN)(1));
|
|
13
|
-
// function to check if BN is smaller or equal 2**256-1
|
|
14
|
-
function isUint256(bn) {
|
|
15
|
-
return (0, number_1.toBN)(bn).lte(exports.UINT_256_MAX);
|
|
16
|
-
}
|
|
17
|
-
exports.isUint256 = isUint256;
|
|
18
|
-
// function to convert BN to Uint256
|
|
19
|
-
function bnToUint256(bignumber) {
|
|
20
|
-
var bn = (0, number_1.toBN)(bignumber);
|
|
21
|
-
if (!isUint256(bn))
|
|
22
|
-
throw new Error('Number is too large');
|
|
23
|
-
return {
|
|
24
|
-
low: (0, encode_1.addHexPrefix)(bn.maskn(128).toString(16)),
|
|
25
|
-
high: (0, encode_1.addHexPrefix)(bn.shrn(128).toString(16)),
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
exports.bnToUint256 = bnToUint256;
|
package/dist/utils/url.d.ts
DELETED
package/dist/utils/url.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.buildUrl = exports.isUrl = void 0;
|
|
7
|
-
var url_join_1 = __importDefault(require("url-join"));
|
|
8
|
-
/**
|
|
9
|
-
* Inspired from https://github.com/segmentio/is-url
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* RegExps.
|
|
13
|
-
* A URL must match #1 and then at least one of #2/#3.
|
|
14
|
-
* Use two levels of REs to avoid REDOS.
|
|
15
|
-
*/
|
|
16
|
-
var protocolAndDomainRE = /^(?:\w+:)?\/\/(\S+)$/;
|
|
17
|
-
var localhostDomainRE = /^localhost[:?\d]*(?:[^:?\d]\S*)?$/;
|
|
18
|
-
var nonLocalhostDomainRE = /^[^\s.]+\.\S{2,}$/;
|
|
19
|
-
/**
|
|
20
|
-
* Loosely validate a URL `string`.
|
|
21
|
-
* @param {String} s
|
|
22
|
-
* @return {Boolean}
|
|
23
|
-
*/
|
|
24
|
-
function isUrl(s) {
|
|
25
|
-
if (!s) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
if (typeof s !== 'string') {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
var match = s.match(protocolAndDomainRE);
|
|
32
|
-
if (!match) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
var everythingAfterProtocol = match[1];
|
|
36
|
-
if (!everythingAfterProtocol) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
if (localhostDomainRE.test(everythingAfterProtocol) ||
|
|
40
|
-
nonLocalhostDomainRE.test(everythingAfterProtocol)) {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
exports.isUrl = isUrl;
|
|
46
|
-
function buildUrl(baseUrl, defaultPath, urlOrPath) {
|
|
47
|
-
return isUrl(urlOrPath) ? urlOrPath : (0, url_join_1.default)(baseUrl, urlOrPath !== null && urlOrPath !== void 0 ? urlOrPath : defaultPath);
|
|
48
|
-
}
|
|
49
|
-
exports.buildUrl = buildUrl;
|
package/provider/default.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { StarknetChainId } from '../constants';
|
|
2
|
-
import { Call, CallContractResponse, ContractClass, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
|
|
3
|
-
import { DeclareContractTransaction, DeployAccountContractTransaction, InvocationsDetails } from '../types/lib';
|
|
4
|
-
import { BigNumberish } from '../utils/number';
|
|
5
|
-
import { ProviderInterface } from './interface';
|
|
6
|
-
import { RpcProviderOptions } from './rpc';
|
|
7
|
-
import { SequencerProviderOptions } from './sequencer';
|
|
8
|
-
import { BlockIdentifier } from './utils';
|
|
9
|
-
export interface ProviderOptions {
|
|
10
|
-
sequencer?: SequencerProviderOptions;
|
|
11
|
-
rpc?: RpcProviderOptions;
|
|
12
|
-
}
|
|
13
|
-
export declare class Provider implements ProviderInterface {
|
|
14
|
-
private provider;
|
|
15
|
-
constructor(providerOrOptions?: ProviderOptions | ProviderInterface);
|
|
16
|
-
get chainId(): StarknetChainId;
|
|
17
|
-
getChainId(): Promise<StarknetChainId>;
|
|
18
|
-
getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
|
|
19
|
-
getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
|
|
20
|
-
getClassHashAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<string>;
|
|
21
|
-
getClassByHash(classHash: string): Promise<ContractClass>;
|
|
22
|
-
getEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
23
|
-
getInvokeEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
24
|
-
getNonce(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
25
|
-
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
26
|
-
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
27
|
-
getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
|
|
28
|
-
callContract(request: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
29
|
-
invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
|
|
30
|
-
deployContract(payload: DeployContractPayload, details: InvocationsDetails): Promise<DeployContractResponse>;
|
|
31
|
-
deployAccountContract(payload: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
|
|
32
|
-
declareContract(transaction: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
|
|
33
|
-
getDeclareEstimateFee(transaction: DeclareContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
34
|
-
getDeployAccountEstimateFee(transaction: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
35
|
-
getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
36
|
-
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
37
|
-
}
|