starknet 3.10.1 → 3.11.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 +26 -0
- package/__tests__/account.test.ts +3 -1
- package/__tests__/accountContract.test.ts +3 -1
- package/__tests__/provider.test.ts +7 -7
- package/__tests__/utils/address.test.ts +30 -1
- package/dist/provider/default.d.ts +2 -6
- package/dist/provider/default.js +15 -11
- package/dist/provider/interface.d.ts +2 -5
- package/dist/signer/index.d.ts +0 -1
- package/dist/signer/index.js +0 -1
- package/dist/types/api.d.ts +10 -2
- package/dist/utils/address.d.ts +5 -2
- package/dist/utils/address.js +24 -5
- package/dist/utils/encode.js +1 -1
- package/package.json +2 -4
- package/provider/default.d.ts +2 -9
- package/provider/default.js +19 -22
- package/provider/interface.d.ts +2 -8
- package/signer/index.d.ts +0 -1
- package/signer/index.js +0 -1
- package/src/provider/default.ts +17 -15
- package/src/provider/interface.ts +2 -8
- package/src/signer/index.ts +0 -1
- package/src/types/api.ts +11 -2
- package/src/utils/address.ts +29 -8
- package/src/utils/encode.ts +1 -1
- package/types/api.d.ts +11 -2
- package/utils/address.d.ts +5 -2
- package/utils/address.js +35 -5
- package/utils/encode.js +3 -1
- package/www/code-examples/account.js +8 -5
- package/www/code-examples/amm.js +13 -18
- package/www/code-examples/erc20.js +6 -3
- package/www/docs/API/account.md +94 -0
- package/www/docs/API/changelog.md +15 -0
- package/www/docs/API/contract.md +73 -2
- package/www/docs/API/contractFacotry.md +42 -0
- package/www/docs/API/index.md +0 -1
- package/www/docs/API/provider.md +204 -1
- package/www/docs/API/signer.md +35 -0
- package/www/docs/API/utils.md +34 -0
- package/www/docusaurus.config.js +3 -4
- package/www/guides/account.md +1 -1
- package/www/guides/erc20.md +7 -0
- package/www/guides/intro.md +1 -0
- package/www/sidebars.js +1 -1
- package/dist/signer/ledger.d.ts +0 -12
- package/dist/signer/ledger.js +0 -140
- package/signer/ledger.d.ts +0 -15
- package/signer/ledger.js +0 -250
- package/src/signer/ledger.ts +0 -86
package/www/docs/API/provider.md
CHANGED
|
@@ -6,5 +6,208 @@ sidebar_position: 1
|
|
|
6
6
|
|
|
7
7
|
The **Provider** API allows you to interface with the StarkNet network, without signing transactions or messages.
|
|
8
8
|
|
|
9
|
-
Typically, these are
|
|
9
|
+
Typically, these are _read_ calls on the blockchain.
|
|
10
10
|
|
|
11
|
+
## Creating an instance
|
|
12
|
+
|
|
13
|
+
`new starknet.Provider(optionsOrProvider)`
|
|
14
|
+
|
|
15
|
+
The options for the provider depends from the network. The structure of the options object is:
|
|
16
|
+
|
|
17
|
+
- options.**baseUrl** - Base URL of the network
|
|
18
|
+
- options.**feederGatewayUrl** - Feeder Gateway Endpoint of the network
|
|
19
|
+
- options.**gatewayUrl** - Gateway Endpoint
|
|
20
|
+
|
|
21
|
+
Example:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
const provider = new starknet.Provider({
|
|
25
|
+
baseUrl: 'https://alpha4.starknet.io',
|
|
26
|
+
feederGatewayUrl: 'feeder_gateway',
|
|
27
|
+
gatewayUrl: 'gateway',
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**This is also default options for the constructor for the **testnet\*\*\*
|
|
32
|
+
|
|
33
|
+
## Methods
|
|
34
|
+
|
|
35
|
+
Gets the smart contract address on the network
|
|
36
|
+
|
|
37
|
+
provider.**getContractAddresses**() => _Promise < GetContractAddressesResponse >_
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
{
|
|
41
|
+
Starknet: string;
|
|
42
|
+
GpsStatementVerifier: string;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
<hr/>
|
|
47
|
+
|
|
48
|
+
provider.**callContract**(call [ , options ]) => _Promise < CallContractResponse >_
|
|
49
|
+
|
|
50
|
+
Calls a function on the StarkNet contract.
|
|
51
|
+
|
|
52
|
+
The call object structure:
|
|
53
|
+
|
|
54
|
+
- call.**contractAddress** - Address of the contract
|
|
55
|
+
- call.**entrypoint** - Entrypoint of the call (method name)
|
|
56
|
+
- call.**calldata** - Payload for the invoking the method
|
|
57
|
+
|
|
58
|
+
The options object structure:
|
|
59
|
+
|
|
60
|
+
- options.**blockIdentifier**
|
|
61
|
+
|
|
62
|
+
###### CallContractResponse
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
{
|
|
66
|
+
result: string[];
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
<hr/>
|
|
71
|
+
|
|
72
|
+
provider.**getBlock**(blockIdentifire) => _Promise < GetBlockResponse >_
|
|
73
|
+
|
|
74
|
+
Gets the block information.
|
|
75
|
+
|
|
76
|
+
###### _GetBlockResponse_
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
{
|
|
80
|
+
block_hash: string;
|
|
81
|
+
parent_block_hash: string;
|
|
82
|
+
block_number: number;
|
|
83
|
+
state_root: string;
|
|
84
|
+
status: 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
85
|
+
transation: Transaction[];
|
|
86
|
+
timestamp: number;
|
|
87
|
+
transaction_receipts: [];
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
<hr/>
|
|
92
|
+
|
|
93
|
+
provider.**getCode**(contractAddress, blockIdentifire) => _Promise < GetCodeResponse >_
|
|
94
|
+
|
|
95
|
+
Gets the code of the deployed contract.
|
|
96
|
+
|
|
97
|
+
###### _GetCodeResponse_
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
{
|
|
101
|
+
bytecode: string[];
|
|
102
|
+
abi: Abi;
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
<hr/>
|
|
107
|
+
|
|
108
|
+
provider.**getStorageAt**(contractAddress, key, blockIdentifire) => _Promise < any >_
|
|
109
|
+
|
|
110
|
+
Gets the contract's storage variable at a specific key
|
|
111
|
+
|
|
112
|
+
<hr/>
|
|
113
|
+
|
|
114
|
+
provider.**getTransactionStatus**(txHash) => _Promise < GetTransactionStatusResponse >_
|
|
115
|
+
|
|
116
|
+
Gets the status of a transaction.
|
|
117
|
+
|
|
118
|
+
###### _GetTransactionStatusResponse_
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
{
|
|
122
|
+
tx_status: 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
123
|
+
block_hash: string;
|
|
124
|
+
tx_failure_reason?: {
|
|
125
|
+
tx_id: number;
|
|
126
|
+
code: string;
|
|
127
|
+
error_message: string;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
<hr/>
|
|
133
|
+
|
|
134
|
+
provider.**getTransactionReceipt**(txHash, txId) => _Promise < TransactionReceipt >_
|
|
135
|
+
|
|
136
|
+
Gets the status of a transaction.
|
|
137
|
+
|
|
138
|
+
###### _TransactionReceipt_
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
{
|
|
142
|
+
status: 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
143
|
+
transaction_hash: string;
|
|
144
|
+
transaction_index: number;
|
|
145
|
+
block_hash: string;
|
|
146
|
+
block_number: 'pending' | null | number;
|
|
147
|
+
l2_to_l1_messages: string[];
|
|
148
|
+
events: string[];
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
<hr/>
|
|
153
|
+
|
|
154
|
+
provider.**getTransaction**(txHash) => _Promise < GetTransactionResponse >_
|
|
155
|
+
|
|
156
|
+
Gets the transaction information from a tx hash.
|
|
157
|
+
|
|
158
|
+
###### _GetTransactionResponse_
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
{
|
|
162
|
+
status: 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
163
|
+
transaction: Transaction;
|
|
164
|
+
block_hash: string;
|
|
165
|
+
block_number: 'pending' | null | number;
|
|
166
|
+
transaction_index: number;
|
|
167
|
+
transaction_hash: string;
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
<hr/>
|
|
172
|
+
|
|
173
|
+
provider.**getTransactionTrace**(txHash) => _Promise < GetTransactionTraceResponse >_
|
|
174
|
+
|
|
175
|
+
Gets the transaction trace from a tx hash.
|
|
176
|
+
|
|
177
|
+
###### _GetTransactionTraceResponse_
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
{
|
|
181
|
+
function_invocation: {
|
|
182
|
+
caller_address: string;
|
|
183
|
+
contract_address: string;
|
|
184
|
+
code_address: string;
|
|
185
|
+
selector: string;
|
|
186
|
+
calldata: {
|
|
187
|
+
[inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish };
|
|
188
|
+
};
|
|
189
|
+
result: Array<any>;
|
|
190
|
+
execution_resources: any;
|
|
191
|
+
internal_call: Array<any>;
|
|
192
|
+
events: Array<any>;
|
|
193
|
+
messages: Array<any>;
|
|
194
|
+
};
|
|
195
|
+
signature: Signature;
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
<hr/>
|
|
200
|
+
|
|
201
|
+
provider.**deployContract**(payload [ , abi ]) => _Promise < AddTransactionResponse >_
|
|
202
|
+
|
|
203
|
+
Gets the transaction trace from a tx hash.
|
|
204
|
+
|
|
205
|
+
###### _AddTransactionResponse_
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
{
|
|
209
|
+
code: 'TRANSACTION_RECEIVED';
|
|
210
|
+
transaction_hash: string;
|
|
211
|
+
address?: string;
|
|
212
|
+
};
|
|
213
|
+
```
|
package/www/docs/API/signer.md
CHANGED
|
@@ -6,3 +6,38 @@ sidebar_position: 3
|
|
|
6
6
|
|
|
7
7
|
The **Signer** API allows you to sign transactions and messages, and also allows you to get the public key.
|
|
8
8
|
|
|
9
|
+
## Creating an instance
|
|
10
|
+
|
|
11
|
+
`new starknet.Signer(keyPair)`
|
|
12
|
+
|
|
13
|
+
## Signer Methods
|
|
14
|
+
|
|
15
|
+
signer.**getPubKey**() => _Promise < string >_
|
|
16
|
+
|
|
17
|
+
Returns public key of the signer
|
|
18
|
+
|
|
19
|
+
<hr />
|
|
20
|
+
|
|
21
|
+
signer.**signTransaction**(transactions, transactionsDetail [ , abi ]) => _Promise < Signature >_
|
|
22
|
+
|
|
23
|
+
Returns signature of the transaction
|
|
24
|
+
|
|
25
|
+
###### Signature
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
string[]
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
<hr />
|
|
32
|
+
|
|
33
|
+
signer.**signMessage**(typedData, accountAddress) => _Promise < Signature >_
|
|
34
|
+
|
|
35
|
+
Returns signature of the transaction
|
|
36
|
+
|
|
37
|
+
###### Signature
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
string[]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
<hr />
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 6
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Utils
|
|
6
|
+
|
|
7
|
+
Util functions are provided so you can use low level functions in your application.
|
|
8
|
+
|
|
9
|
+
## `address`
|
|
10
|
+
|
|
11
|
+
the address helpers can be imported using:
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { address } from 'starknet.js';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### `getChecksumAddress(address: BigNumberish): string`
|
|
18
|
+
|
|
19
|
+
This function accepts an address as a `BigNumberish` and returns the checksummed address as a string.
|
|
20
|
+
An example:
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { address } from 'starknet.js';
|
|
24
|
+
|
|
25
|
+
const addressToCheck = '0x2fd23d9182193775423497fc0c472e156c57c69e4089a1967fb288a2d84e914';
|
|
26
|
+
|
|
27
|
+
const checksummedAddress = address.getChecksumAddress(addressToCheck);
|
|
28
|
+
|
|
29
|
+
console.log(checksummedAddress); // 0x02FD23D9182193775423497Fc0c472E156C57C69E4089a1967fb288a2D84e914
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### `validateChecksumAddress(address: string): boolean`
|
|
33
|
+
|
|
34
|
+
This function validates the checksum address. It returns true if the address is valid, false otherwise.
|
package/www/docusaurus.config.js
CHANGED
|
@@ -41,8 +41,7 @@ const config = {
|
|
|
41
41
|
blog: {
|
|
42
42
|
showReadingTime: true,
|
|
43
43
|
// Please change this to your repo.
|
|
44
|
-
editUrl:
|
|
45
|
-
'https://github.com/0xs34n/starknet.js',
|
|
44
|
+
editUrl: 'https://github.com/0xs34n/starknet.js',
|
|
46
45
|
},
|
|
47
46
|
theme: {
|
|
48
47
|
customCss: require.resolve('./src/css/custom.css'),
|
|
@@ -70,11 +69,11 @@ const config = {
|
|
|
70
69
|
{
|
|
71
70
|
position: 'left',
|
|
72
71
|
label: 'Guides',
|
|
73
|
-
to: '/guides/intro'
|
|
72
|
+
to: '/guides/intro',
|
|
74
73
|
},
|
|
75
74
|
// {to: '/blog', label: 'Blog', position: 'left'},
|
|
76
75
|
{
|
|
77
|
-
href: 'https://github.com/
|
|
76
|
+
href: 'https://github.com/0xs34n/starknet.js',
|
|
78
77
|
label: 'GitHub',
|
|
79
78
|
position: 'right',
|
|
80
79
|
},
|
package/www/guides/account.md
CHANGED
package/www/guides/erc20.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
sidebar_position: 3
|
|
3
3
|
---
|
|
4
|
+
|
|
4
5
|
# Deploy an ERC20 Contract
|
|
5
6
|
|
|
6
7
|
Dpeploy the contract and wait for deployment transaction to be accepted on StarkNet
|
|
@@ -15,13 +16,16 @@ const erc20Response = await defaultProvider.deployContract({
|
|
|
15
16
|
console.log("Waiting for Tx to be Accepted on Starknet - ERC20 Deployment...");
|
|
16
17
|
await defaultProvider.waitForTransaction(erc20Response.transaction_hash);
|
|
17
18
|
```
|
|
19
|
+
|
|
18
20
|
## Get the erc20 contract address and create the contact object
|
|
21
|
+
|
|
19
22
|
```javascript
|
|
20
23
|
const erc20Address = erc20Response.address;
|
|
21
24
|
const erc20 = new Contract(compiledErc20.abi, erc20Address);
|
|
22
25
|
```
|
|
23
26
|
|
|
24
27
|
## Mint tokens to an account address
|
|
28
|
+
|
|
25
29
|
```javascript
|
|
26
30
|
const { transaction_hash: mintTxHash } = await erc20.mint(
|
|
27
31
|
accountContract.address,
|
|
@@ -32,6 +36,7 @@ await defaultProvider.waitForTransaction(mintTxHash);
|
|
|
32
36
|
```
|
|
33
37
|
|
|
34
38
|
## Check balance after mint
|
|
39
|
+
|
|
35
40
|
```javascript
|
|
36
41
|
console.log(`Calling StarkNet for accountContract balance...`);
|
|
37
42
|
const balanceBeforeTransfer = await erc20.balance_of(accountContract.address);
|
|
@@ -43,6 +48,7 @@ console.log(
|
|
|
43
48
|
```
|
|
44
49
|
|
|
45
50
|
## Transfer tokens
|
|
51
|
+
|
|
46
52
|
```javascript
|
|
47
53
|
// Get the nonce of the account and prepare transfer tx
|
|
48
54
|
console.log(`Calling StarkNet for accountContract nonce...`);
|
|
@@ -76,6 +82,7 @@ await defaultProvider.waitForTransaction(transferTxHash);
|
|
|
76
82
|
```
|
|
77
83
|
|
|
78
84
|
## Check balance after transfer
|
|
85
|
+
|
|
79
86
|
```javascript
|
|
80
87
|
// Check balance after transfer - should be 990
|
|
81
88
|
console.log(`Calling StarkNet for accountContract balance...`);
|
package/www/guides/intro.md
CHANGED
|
@@ -17,4 +17,5 @@ npm install starknet@next
|
|
|
17
17
|
Please check the StarkNet documentation <ins>[here](https://www.cairo-lang.org/docs/hello_starknet/intro.html)</ins> to compile starknet contracts.
|
|
18
18
|
|
|
19
19
|
## Full example with account & erc20
|
|
20
|
+
|
|
20
21
|
Please see workshop <ins>[here](https://github.com/0xs34n/starknet.js-workshop)</ins>
|
package/www/sidebars.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
|
|
15
15
|
const sidebars = {
|
|
16
16
|
// By default, Docusaurus generates a sidebar from the docs folder structure
|
|
17
|
-
tutorialSidebar: [{type: 'autogenerated', dirName: '.'}],
|
|
17
|
+
tutorialSidebar: [{ type: 'autogenerated', dirName: '.' }],
|
|
18
18
|
|
|
19
19
|
// But you can create a sidebar manually
|
|
20
20
|
/*
|
package/dist/signer/ledger.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Invocation, InvocationsSignerDetails, Signature } from '../types';
|
|
2
|
-
import { TypedData } from '../utils/typedData';
|
|
3
|
-
import { SignerInterface } from './interface';
|
|
4
|
-
export declare class LedgerBlindSigner implements SignerInterface {
|
|
5
|
-
derivationPath: string;
|
|
6
|
-
private transport;
|
|
7
|
-
private getEthApp;
|
|
8
|
-
getPubKey(): Promise<string>;
|
|
9
|
-
signTransaction(transactions: Invocation[], transactionsDetail: InvocationsSignerDetails): Promise<Signature>;
|
|
10
|
-
signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
|
|
11
|
-
protected sign(msgHash: string): Promise<Signature>;
|
|
12
|
-
}
|
package/dist/signer/ledger.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.LedgerBlindSigner = void 0;
|
|
43
|
-
var hw_app_eth_1 = __importDefault(require("@ledgerhq/hw-app-eth"));
|
|
44
|
-
var hw_transport_webhid_1 = __importDefault(require("@ledgerhq/hw-transport-webhid"));
|
|
45
|
-
var encode_1 = require("../utils/encode");
|
|
46
|
-
var hash_1 = require("../utils/hash");
|
|
47
|
-
var transaction_1 = require("../utils/transaction");
|
|
48
|
-
var typedData_1 = require("../utils/typedData");
|
|
49
|
-
function hexZeroPad(hash, length) {
|
|
50
|
-
var value = hash;
|
|
51
|
-
if (value.length > 2 * length + 2) {
|
|
52
|
-
throw new Error('value out of range');
|
|
53
|
-
}
|
|
54
|
-
while (value.length < 2 * length + 2) {
|
|
55
|
-
value = "0x0" + value.substring(2);
|
|
56
|
-
}
|
|
57
|
-
return value;
|
|
58
|
-
}
|
|
59
|
-
var LedgerBlindSigner = /** @class */ (function () {
|
|
60
|
-
function LedgerBlindSigner() {
|
|
61
|
-
this.derivationPath = "/2645'/579218131'/1148870696'/0'/0'/0";
|
|
62
|
-
}
|
|
63
|
-
LedgerBlindSigner.prototype.getEthApp = function () {
|
|
64
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
-
var _a, _b;
|
|
66
|
-
return __generator(this, function (_c) {
|
|
67
|
-
switch (_c.label) {
|
|
68
|
-
case 0:
|
|
69
|
-
if (!!this.transport) return [3 /*break*/, 4];
|
|
70
|
-
_c.label = 1;
|
|
71
|
-
case 1:
|
|
72
|
-
_c.trys.push([1, 3, , 4]);
|
|
73
|
-
_a = this;
|
|
74
|
-
return [4 /*yield*/, hw_transport_webhid_1.default.create()];
|
|
75
|
-
case 2:
|
|
76
|
-
_a.transport = _c.sent();
|
|
77
|
-
return [3 /*break*/, 4];
|
|
78
|
-
case 3:
|
|
79
|
-
_b = _c.sent();
|
|
80
|
-
throw new Error('Device connection error');
|
|
81
|
-
case 4: return [2 /*return*/, new hw_app_eth_1.default(this.transport)];
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
LedgerBlindSigner.prototype.getPubKey = function () {
|
|
87
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
88
|
-
var eth, response, starkPub;
|
|
89
|
-
return __generator(this, function (_a) {
|
|
90
|
-
switch (_a.label) {
|
|
91
|
-
case 0: return [4 /*yield*/, this.getEthApp()];
|
|
92
|
-
case 1:
|
|
93
|
-
eth = _a.sent();
|
|
94
|
-
return [4 /*yield*/, eth.starkGetPublicKey(this.derivationPath)];
|
|
95
|
-
case 2:
|
|
96
|
-
response = _a.sent();
|
|
97
|
-
starkPub = "0x" + response.slice(1, 1 + 32).toString('hex');
|
|
98
|
-
return [2 /*return*/, starkPub];
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
LedgerBlindSigner.prototype.signTransaction = function (transactions, transactionsDetail) {
|
|
104
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
105
|
-
var calldata, msgHash;
|
|
106
|
-
return __generator(this, function (_a) {
|
|
107
|
-
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, transactionsDetail.nonce);
|
|
108
|
-
msgHash = (0, hash_1.calculcateTransactionHash)(transactionsDetail.walletAddress, transactionsDetail.version, (0, hash_1.getSelectorFromName)('__execute__'), calldata, transactionsDetail.maxFee, transactionsDetail.chainId);
|
|
109
|
-
return [2 /*return*/, this.sign(msgHash)];
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
LedgerBlindSigner.prototype.signMessage = function (typedData, accountAddress) {
|
|
114
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
-
var msgHash;
|
|
116
|
-
return __generator(this, function (_a) {
|
|
117
|
-
msgHash = (0, typedData_1.getMessageHash)(typedData, accountAddress);
|
|
118
|
-
return [2 /*return*/, this.sign(msgHash)];
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
LedgerBlindSigner.prototype.sign = function (msgHash) {
|
|
123
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
-
var eth, _a, r, s;
|
|
125
|
-
return __generator(this, function (_b) {
|
|
126
|
-
switch (_b.label) {
|
|
127
|
-
case 0: return [4 /*yield*/, this.getEthApp()];
|
|
128
|
-
case 1:
|
|
129
|
-
eth = _b.sent();
|
|
130
|
-
return [4 /*yield*/, eth.starkUnsafeSign(this.derivationPath, hexZeroPad(msgHash, 32))];
|
|
131
|
-
case 2:
|
|
132
|
-
_a = (_b.sent()), r = _a.r, s = _a.s;
|
|
133
|
-
return [2 /*return*/, [(0, encode_1.addHexPrefix)(r), (0, encode_1.addHexPrefix)(s)]];
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
return LedgerBlindSigner;
|
|
139
|
-
}());
|
|
140
|
-
exports.LedgerBlindSigner = LedgerBlindSigner;
|
package/signer/ledger.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Invocation, InvocationsSignerDetails, Signature } from '../types';
|
|
2
|
-
import { TypedData } from '../utils/typedData';
|
|
3
|
-
import { SignerInterface } from './interface';
|
|
4
|
-
export declare class LedgerBlindSigner implements SignerInterface {
|
|
5
|
-
derivationPath: string;
|
|
6
|
-
private transport;
|
|
7
|
-
private getEthApp;
|
|
8
|
-
getPubKey(): Promise<string>;
|
|
9
|
-
signTransaction(
|
|
10
|
-
transactions: Invocation[],
|
|
11
|
-
transactionsDetail: InvocationsSignerDetails
|
|
12
|
-
): Promise<Signature>;
|
|
13
|
-
signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
|
|
14
|
-
protected sign(msgHash: string): Promise<Signature>;
|
|
15
|
-
}
|