starknet 3.18.2 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +70 -0
- package/README.md +1 -2
- package/__tests__/account.test.ts +11 -56
- package/__tests__/contract.test.ts +11 -49
- package/__tests__/defaultProvider.test.ts +321 -0
- package/__tests__/fixtures.ts +32 -11
- package/__tests__/jest.setup.ts +2 -3
- package/__tests__/rpcProvider.test.ts +17 -0
- package/__tests__/sequencerProvider.test.ts +45 -0
- package/account/default.d.ts +54 -77
- package/account/default.js +271 -596
- package/account/index.js +18 -31
- package/account/interface.d.ts +66 -95
- package/account/interface.js +20 -30
- package/constants.d.ts +17 -19
- package/constants.js +2038 -2059
- package/contract/contractFactory.d.ts +25 -29
- package/contract/contractFactory.js +94 -210
- package/contract/default.d.ts +117 -146
- package/contract/default.js +582 -776
- package/contract/index.js +19 -32
- package/contract/interface.d.ts +72 -92
- package/contract/interface.js +6 -5
- package/dist/account/default.d.ts +5 -9
- package/dist/account/default.js +35 -169
- package/dist/account/interface.d.ts +3 -15
- package/dist/contract/contractFactory.js +4 -4
- package/dist/contract/default.d.ts +3 -3
- package/dist/contract/default.js +3 -2
- package/dist/contract/interface.d.ts +2 -2
- package/dist/provider/default.d.ts +18 -134
- package/dist/provider/default.js +47 -411
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +2 -0
- package/dist/provider/interface.d.ts +45 -50
- package/dist/provider/rpc.d.ts +57 -0
- package/dist/provider/rpc.js +364 -0
- package/dist/provider/sequencer.d.ts +66 -0
- package/dist/provider/sequencer.js +444 -0
- package/dist/types/account.d.ts +2 -3
- package/dist/types/api/index.d.ts +16 -0
- package/dist/types/api/index.js +18 -0
- package/dist/types/api/rpc.d.ts +221 -0
- package/dist/types/{api.js → api/rpc.js} +0 -0
- package/dist/types/api/sequencer.d.ts +289 -0
- package/dist/types/api/sequencer.js +2 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.js +15 -1
- package/dist/types/lib.d.ts +3 -1
- package/dist/types/provider.d.ts +86 -0
- package/dist/types/provider.js +2 -0
- package/dist/utils/fetchPonyfill.d.ts +2 -0
- package/dist/utils/fetchPonyfill.js +6 -0
- package/dist/utils/provider.d.ts +4 -0
- package/dist/utils/provider.js +38 -0
- package/dist/utils/responseParser/index.d.ts +11 -0
- package/dist/utils/responseParser/index.js +9 -0
- package/dist/utils/responseParser/rpc.d.ts +13 -0
- package/dist/utils/responseParser/rpc.js +96 -0
- package/dist/utils/responseParser/sequencer.d.ts +13 -0
- package/dist/utils/responseParser/sequencer.js +124 -0
- package/index.js +42 -75
- package/package.json +2 -3
- package/provider/default.d.ts +21 -175
- package/provider/default.js +139 -704
- package/provider/errors.d.ts +4 -4
- package/provider/errors.js +30 -40
- package/provider/index.d.ts +2 -0
- package/provider/index.js +22 -33
- package/provider/interface.d.ts +104 -131
- package/provider/interface.js +6 -5
- package/provider/rpc.d.ts +57 -0
- package/provider/rpc.js +364 -0
- package/provider/sequencer.d.ts +66 -0
- package/provider/sequencer.js +444 -0
- package/provider/utils.d.ts +7 -9
- package/provider/utils.js +39 -44
- package/signer/default.d.ts +5 -9
- package/signer/default.js +72 -177
- package/signer/index.js +18 -31
- package/signer/interface.d.ts +29 -33
- package/signer/interface.js +6 -5
- package/src/account/default.ts +26 -146
- package/src/account/interface.ts +5 -20
- package/src/contract/contractFactory.ts +3 -6
- package/src/contract/default.ts +6 -4
- package/src/contract/interface.ts +2 -2
- package/src/provider/default.ts +63 -395
- package/src/provider/index.ts +2 -0
- package/src/provider/interface.ts +68 -63
- package/src/provider/rpc.ts +299 -0
- package/src/provider/sequencer.ts +385 -0
- package/src/types/account.ts +2 -3
- package/src/types/api/index.ts +17 -0
- package/src/types/api/rpc.ts +247 -0
- package/src/types/api/sequencer.ts +331 -0
- package/src/types/index.ts +3 -1
- package/src/types/lib.ts +3 -1
- package/src/types/provider.ts +108 -0
- package/src/utils/fetchPonyfill.ts +4 -0
- package/src/utils/provider.ts +28 -0
- package/src/utils/responseParser/index.ts +28 -0
- package/src/utils/responseParser/rpc.ts +93 -0
- package/src/utils/responseParser/sequencer.ts +127 -0
- package/types/account.d.ts +5 -7
- package/types/account.js +2 -2
- package/types/api/index.d.ts +16 -0
- package/types/api/index.js +18 -0
- package/types/api/rpc.d.ts +221 -0
- package/types/api/rpc.js +2 -0
- package/types/api/sequencer.d.ts +289 -0
- package/types/api/sequencer.js +2 -0
- package/types/contract.d.ts +1 -1
- package/types/contract.js +2 -2
- package/types/index.d.ts +3 -1
- package/types/index.js +35 -34
- package/types/lib.d.ts +36 -41
- package/types/lib.js +2 -2
- package/types/provider.d.ts +86 -0
- package/types/provider.js +2 -0
- package/types/signer.d.ts +2 -2
- package/types/signer.js +2 -2
- package/utils/address.js +26 -37
- package/utils/ellipticCurve.d.ts +1 -6
- package/utils/ellipticCurve.js +73 -137
- package/utils/encode.js +49 -85
- package/utils/fetchPonyfill.d.ts +2 -0
- package/utils/fetchPonyfill.js +6 -0
- package/utils/hash.d.ts +4 -31
- package/utils/hash.js +76 -141
- package/utils/json.d.ts +13 -45
- package/utils/json.js +15 -22
- package/utils/number.d.ts +2 -9
- package/utils/number.js +47 -81
- package/utils/provider.d.ts +4 -0
- package/utils/provider.js +38 -0
- package/utils/responseParser/index.d.ts +11 -0
- package/utils/responseParser/index.js +9 -0
- package/utils/responseParser/rpc.d.ts +13 -0
- package/utils/responseParser/rpc.js +96 -0
- package/utils/responseParser/sequencer.d.ts +13 -0
- package/utils/responseParser/sequencer.js +124 -0
- package/utils/shortString.js +13 -21
- package/utils/stark.d.ts +0 -1
- package/utils/stark.js +59 -93
- package/utils/transaction.d.ts +3 -6
- package/utils/transaction.js +50 -81
- package/utils/typedData/index.d.ts +3 -15
- package/utils/typedData/index.js +109 -175
- package/utils/typedData/types.d.ts +9 -9
- package/utils/typedData/types.js +2 -2
- package/utils/typedData/utils.js +6 -6
- package/utils/uint256.d.ts +5 -5
- package/utils/uint256.js +16 -26
- package/www/docs/API/account.md +3 -4
- package/www/docs/API/contract.md +2 -2
- package/www/docs/API/contractFactory.md +2 -2
- package/www/docs/API/provider.md +185 -74
- package/www/guides/account.md +1 -8
- package/www/guides/erc20.md +3 -0
- package/__tests__/provider.test.ts +0 -168
- package/dist/types/api.d.ts +0 -261
- package/src/types/api.ts +0 -303
- package/types/api.d.ts +0 -287
- package/types/api.js +0 -2
package/types/contract.d.ts
CHANGED
package/types/contract.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/types/index.d.ts
CHANGED
package/types/index.js
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
__exportStar(require(
|
|
31
|
-
|
|
32
|
-
__exportStar(require(
|
|
33
|
-
__exportStar(require(
|
|
34
|
-
__exportStar(require(
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.api = void 0;
|
|
30
|
+
__exportStar(require("./lib"), exports);
|
|
31
|
+
exports.api = __importStar(require("./api"));
|
|
32
|
+
__exportStar(require("./signer"), exports);
|
|
33
|
+
__exportStar(require("./contract"), exports);
|
|
34
|
+
__exportStar(require("./account"), exports);
|
|
35
|
+
__exportStar(require("./provider"), exports);
|
package/types/lib.d.ts
CHANGED
|
@@ -1,78 +1,73 @@
|
|
|
1
1
|
import type { ec as EC } from 'elliptic';
|
|
2
|
-
|
|
3
2
|
import type { BigNumberish } from '../utils/number';
|
|
4
3
|
export declare type KeyPair = EC.KeyPair;
|
|
5
4
|
export declare type Signature = string[];
|
|
6
5
|
export declare type RawCalldata = BigNumberish[];
|
|
7
6
|
export declare type DeployContractPayload = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
contract: CompiledContract | string;
|
|
8
|
+
constructorCalldata?: RawCalldata;
|
|
9
|
+
addressSalt?: BigNumberish;
|
|
11
10
|
};
|
|
12
11
|
export declare type DeclareContractPayload = {
|
|
13
|
-
|
|
12
|
+
contract: CompiledContract | string;
|
|
13
|
+
version?: BigNumberish;
|
|
14
14
|
};
|
|
15
15
|
export declare type Invocation = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
contractAddress: string;
|
|
17
|
+
entrypoint: string;
|
|
18
|
+
calldata?: RawCalldata;
|
|
19
|
+
signature?: Signature;
|
|
20
20
|
};
|
|
21
21
|
export declare type Call = Omit<Invocation, 'signature'>;
|
|
22
22
|
export declare type InvocationsDetails = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
nonce?: BigNumberish;
|
|
24
|
+
maxFee?: BigNumberish;
|
|
25
|
+
version?: BigNumberish;
|
|
26
26
|
};
|
|
27
|
-
export declare type Status =
|
|
28
|
-
| 'NOT_RECEIVED'
|
|
29
|
-
| 'RECEIVED'
|
|
30
|
-
| 'PENDING'
|
|
31
|
-
| 'ACCEPTED_ON_L2'
|
|
32
|
-
| 'ACCEPTED_ON_L1'
|
|
33
|
-
| 'REJECTED';
|
|
27
|
+
export declare type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
34
28
|
export declare type TransactionStatus = 'TRANSACTION_RECEIVED';
|
|
35
29
|
export declare type Type = 'DECLARE' | 'DEPLOY' | 'INVOKE_FUNCTION';
|
|
36
30
|
export declare type EntryPointType = 'EXTERNAL';
|
|
37
31
|
export declare type CompressedProgram = string;
|
|
38
32
|
export declare type AbiEntry = {
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
name: string;
|
|
34
|
+
type: 'felt' | 'felt*' | string;
|
|
41
35
|
};
|
|
42
36
|
export declare type FunctionAbi = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
inputs: AbiEntry[];
|
|
38
|
+
name: string;
|
|
39
|
+
outputs: AbiEntry[];
|
|
40
|
+
stateMutability?: 'view';
|
|
41
|
+
type: 'function' | 'constructor';
|
|
48
42
|
};
|
|
49
43
|
export declare type StructAbi = {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
members: (AbiEntry & {
|
|
45
|
+
offset: number;
|
|
46
|
+
})[];
|
|
47
|
+
name: string;
|
|
48
|
+
size: number;
|
|
49
|
+
type: 'struct';
|
|
56
50
|
};
|
|
57
51
|
export declare type Abi = Array<FunctionAbi | StructAbi>;
|
|
58
52
|
export declare type EntryPointsByType = object;
|
|
59
53
|
export declare type Program = Record<any, any>;
|
|
60
|
-
export declare type
|
|
54
|
+
export declare type BlockTag = 'pending' | 'latest';
|
|
55
|
+
export declare type BlockNumber = BlockTag | null | number;
|
|
61
56
|
export declare type CompiledContract = {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
abi: Abi;
|
|
58
|
+
entry_points_by_type: EntryPointsByType;
|
|
59
|
+
program: Program;
|
|
65
60
|
};
|
|
66
61
|
export declare type CompressedCompiledContract = Omit<CompiledContract, 'program'> & {
|
|
67
|
-
|
|
62
|
+
program: CompressedProgram;
|
|
68
63
|
};
|
|
69
64
|
export declare type Struct = {
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
type: 'struct';
|
|
66
|
+
[k: string]: BigNumberish;
|
|
72
67
|
};
|
|
73
68
|
export declare type Args = {
|
|
74
|
-
|
|
69
|
+
[inputName: string]: BigNumberish | BigNumberish[] | ParsedStruct | ParsedStruct[];
|
|
75
70
|
};
|
|
76
71
|
export declare type ParsedStruct = {
|
|
77
|
-
|
|
72
|
+
[key: string]: BigNumberish | ParsedStruct;
|
|
78
73
|
};
|
package/types/lib.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import BN from 'bn.js';
|
|
2
|
+
import { Abi, CompressedProgram, EntryPointsByType, RawCalldata, Signature, Status } from './lib';
|
|
3
|
+
export interface GetBlockResponse {
|
|
4
|
+
accepted_time: number;
|
|
5
|
+
block_hash: string;
|
|
6
|
+
block_number: number;
|
|
7
|
+
gas_price: string;
|
|
8
|
+
new_root: string;
|
|
9
|
+
old_root?: string;
|
|
10
|
+
parent_hash: string;
|
|
11
|
+
sequencer: string;
|
|
12
|
+
status: Status;
|
|
13
|
+
transactions: Array<string>;
|
|
14
|
+
starknet_version?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare type GetTransactionResponse = InvokeTransactionResponse & DeclareTransactionResponse;
|
|
17
|
+
export interface CommonTransactionResponse {
|
|
18
|
+
transaction_hash?: string;
|
|
19
|
+
version?: string;
|
|
20
|
+
signature?: Signature;
|
|
21
|
+
max_fee?: string;
|
|
22
|
+
nonce?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface InvokeTransactionResponse extends CommonTransactionResponse {
|
|
25
|
+
contract_address?: string;
|
|
26
|
+
entry_point_selector?: string;
|
|
27
|
+
calldata: RawCalldata;
|
|
28
|
+
}
|
|
29
|
+
export interface ContractEntryPoint {
|
|
30
|
+
offset: string;
|
|
31
|
+
selector: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ContractClass {
|
|
34
|
+
program: CompressedProgram;
|
|
35
|
+
entry_points_by_type: EntryPointsByType;
|
|
36
|
+
abi?: Abi;
|
|
37
|
+
}
|
|
38
|
+
export interface DeclareTransactionResponse extends CommonTransactionResponse {
|
|
39
|
+
contract_class?: any;
|
|
40
|
+
sender_address?: string;
|
|
41
|
+
}
|
|
42
|
+
export declare type GetTransactionReceiptResponse = InvokeTransactionReceiptResponse | DeclareTransactionReceiptResponse;
|
|
43
|
+
export interface CommonTransactionReceiptResponse {
|
|
44
|
+
transaction_hash: string;
|
|
45
|
+
status: Status;
|
|
46
|
+
actual_fee?: string;
|
|
47
|
+
status_data?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface MessageToL1 {
|
|
50
|
+
to_address: string;
|
|
51
|
+
payload: Array<string>;
|
|
52
|
+
}
|
|
53
|
+
export interface Event {
|
|
54
|
+
from_address: string;
|
|
55
|
+
keys: Array<string>;
|
|
56
|
+
data: Array<string>;
|
|
57
|
+
}
|
|
58
|
+
export interface MessageToL2 {
|
|
59
|
+
from_address: string;
|
|
60
|
+
payload: Array<string>;
|
|
61
|
+
}
|
|
62
|
+
export interface InvokeTransactionReceiptResponse extends CommonTransactionReceiptResponse {
|
|
63
|
+
messages_sent: Array<MessageToL1>;
|
|
64
|
+
events: Array<Event>;
|
|
65
|
+
l1_origin_message?: MessageToL2;
|
|
66
|
+
}
|
|
67
|
+
export declare type DeclareTransactionReceiptResponse = CommonTransactionReceiptResponse;
|
|
68
|
+
export interface EstimateFeeResponse {
|
|
69
|
+
overall_fee: BN;
|
|
70
|
+
gas_consumed?: BN;
|
|
71
|
+
gas_price?: BN;
|
|
72
|
+
}
|
|
73
|
+
export interface InvokeFunctionResponse {
|
|
74
|
+
transaction_hash: string;
|
|
75
|
+
}
|
|
76
|
+
export interface DeployContractResponse {
|
|
77
|
+
contract_address: string;
|
|
78
|
+
transaction_hash: string;
|
|
79
|
+
}
|
|
80
|
+
export interface DeclareContractResponse {
|
|
81
|
+
transaction_hash: string;
|
|
82
|
+
class_hash: string;
|
|
83
|
+
}
|
|
84
|
+
export declare type CallContractResponse = {
|
|
85
|
+
result: Array<string>;
|
|
86
|
+
};
|
package/types/signer.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
2
|
import { InvocationsDetails } from './lib';
|
|
3
3
|
export interface InvocationsSignerDetails extends Required<InvocationsDetails> {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
walletAddress: string;
|
|
5
|
+
chainId: StarknetChainId;
|
|
6
6
|
}
|
package/types/signer.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/utils/address.js
CHANGED
|
@@ -1,52 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.validateChecksumAddress =
|
|
4
|
-
exports.getChecksumAddress =
|
|
5
|
-
exports.validateAndParseAddress =
|
|
6
|
-
exports.addAddressPadding =
|
|
7
|
-
void 0;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateChecksumAddress = exports.getChecksumAddress = exports.validateAndParseAddress = exports.addAddressPadding = void 0;
|
|
8
4
|
/* eslint-disable no-bitwise */
|
|
9
|
-
var bytes_1 = require(
|
|
10
|
-
var constants_1 = require(
|
|
11
|
-
var encode_1 = require(
|
|
12
|
-
var hash_1 = require(
|
|
13
|
-
var number_1 = require(
|
|
5
|
+
var bytes_1 = require("@ethersproject/bytes");
|
|
6
|
+
var constants_1 = require("../constants");
|
|
7
|
+
var encode_1 = require("./encode");
|
|
8
|
+
var hash_1 = require("./hash");
|
|
9
|
+
var number_1 = require("./number");
|
|
14
10
|
function addAddressPadding(address) {
|
|
15
|
-
|
|
16
|
-
(0, encode_1.removeHexPrefix)((0, number_1.toHex)((0, number_1.toBN)(address))).padStart(
|
|
17
|
-
64,
|
|
18
|
-
'0'
|
|
19
|
-
)
|
|
20
|
-
);
|
|
11
|
+
return (0, encode_1.addHexPrefix)((0, encode_1.removeHexPrefix)((0, number_1.toHex)((0, number_1.toBN)(address))).padStart(64, '0'));
|
|
21
12
|
}
|
|
22
13
|
exports.addAddressPadding = addAddressPadding;
|
|
23
14
|
function validateAndParseAddress(address) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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;
|
|
30
21
|
}
|
|
31
22
|
exports.validateAndParseAddress = validateAndParseAddress;
|
|
32
23
|
// from https://github.com/ethers-io/ethers.js/blob/fc1e006575d59792fa97b4efb9ea2f8cca1944cf/packages/address/src.ts/index.ts#L12
|
|
33
24
|
function getChecksumAddress(address) {
|
|
34
|
-
|
|
35
|
-
.
|
|
36
|
-
.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
chars[i + 1] = chars[i + 1].toUpperCase();
|
|
25
|
+
var chars = (0, encode_1.removeHexPrefix)(validateAndParseAddress(address)).toLowerCase().split('');
|
|
26
|
+
var hashed = (0, bytes_1.arrayify)((0, hash_1.pedersen)([0, address]), { hexPad: 'left' }); // as the hash will be 251 bits (63 chars) we need to pad it to 64 chars without changing the number value ("left")
|
|
27
|
+
for (var i = 0; i < chars.length; i += 2) {
|
|
28
|
+
if (hashed[i >> 1] >> 4 >= 8) {
|
|
29
|
+
chars[i] = chars[i].toUpperCase();
|
|
30
|
+
}
|
|
31
|
+
if ((hashed[i >> 1] & 0x0f) >= 8) {
|
|
32
|
+
chars[i + 1] = chars[i + 1].toUpperCase();
|
|
33
|
+
}
|
|
44
34
|
}
|
|
45
|
-
|
|
46
|
-
return (0, encode_1.addHexPrefix)(chars.join(''));
|
|
35
|
+
return (0, encode_1.addHexPrefix)(chars.join(''));
|
|
47
36
|
}
|
|
48
37
|
exports.getChecksumAddress = getChecksumAddress;
|
|
49
38
|
function validateChecksumAddress(address) {
|
|
50
|
-
|
|
39
|
+
return getChecksumAddress(address) === address;
|
|
51
40
|
}
|
|
52
41
|
exports.validateChecksumAddress = validateChecksumAddress;
|
package/utils/ellipticCurve.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ec as EC } from 'elliptic';
|
|
2
|
-
|
|
3
2
|
import { KeyPair, Signature } from '../types';
|
|
4
3
|
import { BigNumberish } from './number';
|
|
5
4
|
export declare const ec: EC;
|
|
@@ -14,8 +13,4 @@ export declare function getStarkKey(keyPair: KeyPair): string;
|
|
|
14
13
|
*/
|
|
15
14
|
export declare function getKeyPairFromPublicKey(publicKey: BigNumberish): KeyPair;
|
|
16
15
|
export declare function sign(keyPair: KeyPair, msgHash: string): Signature;
|
|
17
|
-
export declare function verify(
|
|
18
|
-
keyPair: KeyPair | KeyPair[],
|
|
19
|
-
msgHash: string,
|
|
20
|
-
sig: Signature
|
|
21
|
-
): boolean;
|
|
16
|
+
export declare function verify(keyPair: KeyPair | KeyPair[], msgHash: string, sig: Signature): boolean;
|