@lombard.finance/ts-verifier 0.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/README.md +51 -0
- package/address-calculator.ts +575 -0
- package/example.ts +75 -0
- package/package.json +18 -0
- package/tsconfig.json +113 -0
- package/verifier.ts +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Lombard Deposit Address Verifier
|
|
2
|
+
|
|
3
|
+
This library can be used by users of the Lombard Finance protocol to ensure that the provided deposit addresses from the webpage actually match the derivation path in the backend code.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
Assuming `git` is installed, you can download this repository with:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
git clone https://github.com/lombard-finance/ts-verifier
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then, navigate into the folder:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cd ts-verifier
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
And finally, run the installation (ensure you are using Node 18.10 or higher):
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn
|
|
23
|
+
yarn global add ts-node
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
The library can be used very simply:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
ts-node verifier.ts <blockchain> <destination_address>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Possible options for blockchain are:
|
|
35
|
+
|
|
36
|
+
- `ethereum`
|
|
37
|
+
- `bsc`
|
|
38
|
+
- `base`
|
|
39
|
+
- `sui`
|
|
40
|
+
|
|
41
|
+
The library will query the Lombard API for deposit addresses, and then compute them internally to see if they match. For each deposit address linked to your destination address, the binary will attempt to match them, printing out 'match' or 'mismatch' in either case, and printing both addresses (fetched and derived) in all cases so that you may double-check the result yourself. It will look something like this:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
$ ts-node verifier.ts ethereum 0x564974801D2ffBE736Ed59C9bE39F6c0A4274aE6
|
|
45
|
+
Checking for address bc1qu6mwr50akfpfwjes4nh53taexuhzt6gsf8ysnn:
|
|
46
|
+
- partner code: lombard
|
|
47
|
+
- nonce: 0
|
|
48
|
+
Address fetched from API: bc1qu6mwr50akfpfwjes4nh53taexuhzt6gsf8ysnn
|
|
49
|
+
Address computed: bc1qu6mwr50akfpfwjes4nh53taexuhzt6gsf8ysnn
|
|
50
|
+
Addresses match!
|
|
51
|
+
```
|
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
// Bitcoin Segwit Address Generator
|
|
2
|
+
// TypeScript implementation based on Go code
|
|
3
|
+
|
|
4
|
+
import * as crypto from "crypto";
|
|
5
|
+
import * as secp256k1 from "secp256k1";
|
|
6
|
+
import * as bitcoin from "bitcoinjs-lib";
|
|
7
|
+
|
|
8
|
+
// Constants
|
|
9
|
+
const MAINNET_PUBLIC_KEY = Buffer.from(
|
|
10
|
+
"033dcf7a68429b23a0396ca61c1ab243ccbbcc629ff04c59394458d6db5dd2bb15",
|
|
11
|
+
"hex",
|
|
12
|
+
);
|
|
13
|
+
const SIGNET_PUBLIC_KEY = Buffer.from(
|
|
14
|
+
"025615e9748b945bad807b56d3a723578673d08566a4818510c0ba2123317414f8",
|
|
15
|
+
"hex",
|
|
16
|
+
);
|
|
17
|
+
const DEPOSIT_AUX_TAG = "LombardDepositAux";
|
|
18
|
+
const DEPOSIT_AUX_V0 = 0;
|
|
19
|
+
const MAX_REFERRAL_ID_SIZE = 256;
|
|
20
|
+
const SEGWIT_TWEAK_TAG = "SegwitTweak";
|
|
21
|
+
const DEPOSIT_ADDR_TAG = "LombardDepositAddr";
|
|
22
|
+
const AUX_DATA_SIZE = 32;
|
|
23
|
+
const TWEAK_SIZE = 32;
|
|
24
|
+
|
|
25
|
+
// Chain IDs
|
|
26
|
+
const ETHEREUM_CHAIN_ID = Buffer.from(
|
|
27
|
+
"0000000000000000000000000000000000000000000000000000000000000001",
|
|
28
|
+
"hex",
|
|
29
|
+
);
|
|
30
|
+
const BASE_CHAIN_ID = Buffer.from(
|
|
31
|
+
"0000000000000000000000000000000000000000000000000000000000002105",
|
|
32
|
+
"hex",
|
|
33
|
+
);
|
|
34
|
+
const BSC_CHAIN_ID = Buffer.from(
|
|
35
|
+
"0000000000000000000000000000000000000000000000000000000000000038",
|
|
36
|
+
"hex",
|
|
37
|
+
);
|
|
38
|
+
const SUI_CHAIN_ID = Buffer.from(
|
|
39
|
+
"0100000000000000000000000000000000000000000000000000000035834a8a",
|
|
40
|
+
"hex",
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// LBTC Contracts
|
|
44
|
+
const ETHEREUM_LBTC_CONTRACT = Buffer.from(
|
|
45
|
+
"8236a87084f8B84306f72007F36F2618A5634494",
|
|
46
|
+
"hex",
|
|
47
|
+
);
|
|
48
|
+
const BASE_LBTC_CONTRACT = Buffer.from(
|
|
49
|
+
"ecAc9C5F704e954931349Da37F60E39f515c11c1",
|
|
50
|
+
"hex",
|
|
51
|
+
);
|
|
52
|
+
const BSC_LBTC_CONTRACT = Buffer.from(
|
|
53
|
+
"ecAc9C5F704e954931349Da37F60E39f515c11c1",
|
|
54
|
+
"hex",
|
|
55
|
+
);
|
|
56
|
+
const SUI_LBTC_CONTRACT = Buffer.from(
|
|
57
|
+
"3e8e9423d80e1774a7ca128fccd8bf5f1f7753be658c5e645929037f7c819040",
|
|
58
|
+
"hex",
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// API
|
|
62
|
+
const URL = "https://mainnet.prod.lombard.finance/api/v1/address/destination/";
|
|
63
|
+
|
|
64
|
+
// Blockchain Types
|
|
65
|
+
export enum BlockchainType {
|
|
66
|
+
EVM = "evm",
|
|
67
|
+
Sui = "sui",
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export enum SupportedBlockchains {
|
|
71
|
+
Ethereum = "ethereum",
|
|
72
|
+
Base = "base",
|
|
73
|
+
BSC = "bsc",
|
|
74
|
+
Sui = "sui",
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Network Parameters
|
|
78
|
+
export interface NetworkParams {
|
|
79
|
+
messagePrefix: string;
|
|
80
|
+
bech32: string;
|
|
81
|
+
bip32: {
|
|
82
|
+
public: number;
|
|
83
|
+
private: number;
|
|
84
|
+
};
|
|
85
|
+
pubKeyHash: number;
|
|
86
|
+
scriptHash: number;
|
|
87
|
+
wif: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Networks
|
|
91
|
+
export const Networks = {
|
|
92
|
+
mainnet: bitcoin.networks.bitcoin,
|
|
93
|
+
signet: {
|
|
94
|
+
messagePrefix: "\x18Bitcoin Signed Message:\n",
|
|
95
|
+
bech32: "tb",
|
|
96
|
+
bip32: {
|
|
97
|
+
public: 0x043587cf,
|
|
98
|
+
private: 0x04358394,
|
|
99
|
+
},
|
|
100
|
+
pubKeyHash: 0x6f,
|
|
101
|
+
scriptHash: 0xc4,
|
|
102
|
+
wif: 0xef,
|
|
103
|
+
} as NetworkParams,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// Config type
|
|
107
|
+
export interface Config {
|
|
108
|
+
network: "mainnet" | "signet";
|
|
109
|
+
depositPublicKey: Buffer;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// DestConfig type
|
|
113
|
+
export interface DestConfig {
|
|
114
|
+
network: "ethereum" | "sui" | "solana";
|
|
115
|
+
chainId: LChainId;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Address type
|
|
119
|
+
export type Address = Buffer;
|
|
120
|
+
|
|
121
|
+
// ChainId type
|
|
122
|
+
export type LChainId = Buffer;
|
|
123
|
+
|
|
124
|
+
// Error classes
|
|
125
|
+
export class BitcoinAddressError extends Error {
|
|
126
|
+
constructor(message: string) {
|
|
127
|
+
super(message);
|
|
128
|
+
this.name = "BitcoinAddressError";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Helper function to create a SHA-256 hash
|
|
134
|
+
*/
|
|
135
|
+
function sha256(data: Buffer | Uint8Array): Buffer {
|
|
136
|
+
return crypto.createHash("sha256").update(data).digest();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Creates a tagged hasher used for deposit aux data
|
|
141
|
+
*/
|
|
142
|
+
function auxDepositHasher(): crypto.Hash {
|
|
143
|
+
const tag = sha256(Buffer.from(DEPOSIT_AUX_TAG));
|
|
144
|
+
|
|
145
|
+
const h = crypto.createHash("sha256");
|
|
146
|
+
h.update(tag);
|
|
147
|
+
h.update(tag);
|
|
148
|
+
|
|
149
|
+
return h;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Compute v0 AuxData given a nonce and referrerId
|
|
154
|
+
*/
|
|
155
|
+
export function computeAuxDataV0(
|
|
156
|
+
nonce: number,
|
|
157
|
+
referrerId: Buffer | Uint8Array,
|
|
158
|
+
): Buffer {
|
|
159
|
+
if (referrerId.length > MAX_REFERRAL_ID_SIZE) {
|
|
160
|
+
throw new BitcoinAddressError(
|
|
161
|
+
`Wrong size for referrerId (got ${referrerId.length}, want not greater than ${MAX_REFERRAL_ID_SIZE})`,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const nonceBytes = Buffer.alloc(4);
|
|
166
|
+
nonceBytes.writeUInt32BE(nonce, 0);
|
|
167
|
+
|
|
168
|
+
const h = auxDepositHasher();
|
|
169
|
+
|
|
170
|
+
// Version0
|
|
171
|
+
h.update(Buffer.from([DEPOSIT_AUX_V0]));
|
|
172
|
+
h.update(nonceBytes);
|
|
173
|
+
h.update(Buffer.from(referrerId));
|
|
174
|
+
|
|
175
|
+
return h.digest();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* EVM-specific deposit tweak calculations
|
|
180
|
+
*/
|
|
181
|
+
export function depositTweak(
|
|
182
|
+
lbtcAddress: Buffer,
|
|
183
|
+
depositAddress: Buffer,
|
|
184
|
+
chainId: Buffer | Uint8Array,
|
|
185
|
+
auxData: Buffer | Uint8Array,
|
|
186
|
+
): Buffer {
|
|
187
|
+
const tag = sha256(Buffer.from(DEPOSIT_ADDR_TAG));
|
|
188
|
+
const h = crypto.createHash("sha256");
|
|
189
|
+
h.update(tag);
|
|
190
|
+
h.update(tag);
|
|
191
|
+
h.update(Buffer.from(auxData));
|
|
192
|
+
h.update(Buffer.from([0])); // evm tag
|
|
193
|
+
h.update(Buffer.from(chainId));
|
|
194
|
+
h.update(lbtcAddress);
|
|
195
|
+
h.update(depositAddress);
|
|
196
|
+
return h.digest();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Calculate tweak bytes for a given request
|
|
201
|
+
*/
|
|
202
|
+
export function calcTweakBytes(
|
|
203
|
+
blockchainType: BlockchainType,
|
|
204
|
+
chainId: Uint8Array,
|
|
205
|
+
toAddress: Address,
|
|
206
|
+
lbtcAddress: Address,
|
|
207
|
+
auxData: Uint8Array | Buffer,
|
|
208
|
+
): Buffer {
|
|
209
|
+
switch (blockchainType) {
|
|
210
|
+
case BlockchainType.EVM:
|
|
211
|
+
// EVM chain uses 20-byte address
|
|
212
|
+
if (lbtcAddress.length !== 20) {
|
|
213
|
+
throw new BitcoinAddressError(
|
|
214
|
+
`Bad LbtcAddress (got ${lbtcAddress.length} bytes, expected 20)`,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (toAddress.length !== 20) {
|
|
219
|
+
throw new BitcoinAddressError(
|
|
220
|
+
`Bad ToAddress (got ${toAddress.length} bytes, expected 20)`,
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return depositTweak(lbtcAddress, toAddress, chainId, auxData);
|
|
225
|
+
case BlockchainType.Sui:
|
|
226
|
+
// Sui uses 32-byte address
|
|
227
|
+
if (lbtcAddress.length !== 32) {
|
|
228
|
+
throw new BitcoinAddressError(
|
|
229
|
+
`Bad LbtcAddress (got ${lbtcAddress.length} bytes, expected 32)`,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (toAddress.length !== 32) {
|
|
234
|
+
throw new BitcoinAddressError(
|
|
235
|
+
`Bad ToAddress (got ${toAddress.length} bytes, expected 32)`,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return depositTweak(lbtcAddress, toAddress, chainId, auxData);
|
|
240
|
+
default:
|
|
241
|
+
throw new BitcoinAddressError(
|
|
242
|
+
`Unsupported blockchain type: ${blockchainType}`,
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Compute tweak value for a given public key from a byte string
|
|
249
|
+
*/
|
|
250
|
+
function computeTweakValue(
|
|
251
|
+
publicKey: Buffer,
|
|
252
|
+
tweak: Buffer | Uint8Array,
|
|
253
|
+
): Buffer {
|
|
254
|
+
if (tweak.length !== TWEAK_SIZE) {
|
|
255
|
+
throw new BitcoinAddressError(
|
|
256
|
+
`Wrong size for tweak (got ${tweak.length}, want ${TWEAK_SIZE})`,
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (!publicKey) {
|
|
261
|
+
throw new BitcoinAddressError("Nil public key");
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// First, compute the tag bytes, sha256(SegwitTweakTag)
|
|
265
|
+
const tag = sha256(Buffer.from(SEGWIT_TWEAK_TAG));
|
|
266
|
+
|
|
267
|
+
// Now compute sha256(tag || tag || pk || tweak)
|
|
268
|
+
const h = crypto.createHash("sha256");
|
|
269
|
+
h.update(tag);
|
|
270
|
+
h.update(tag);
|
|
271
|
+
h.update(publicKey);
|
|
272
|
+
h.update(Buffer.from(tweak));
|
|
273
|
+
|
|
274
|
+
return h.digest();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Tweaks a public key with the provided tweak value
|
|
279
|
+
*/
|
|
280
|
+
export function tweakPublicKey(
|
|
281
|
+
publicKey: Buffer,
|
|
282
|
+
tweak: Buffer | Uint8Array,
|
|
283
|
+
): Buffer {
|
|
284
|
+
const tweakScalar = computeTweakValue(publicKey, tweak);
|
|
285
|
+
|
|
286
|
+
// Add the private key & tweak scalar (G*tweak + publicKey)
|
|
287
|
+
try {
|
|
288
|
+
return Buffer.from(secp256k1.publicKeyTweakAdd(publicKey, tweakScalar));
|
|
289
|
+
} catch (error) {
|
|
290
|
+
throw new BitcoinAddressError(`Failed to tweak public key: ${error}`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Converts a public key to a segwit address
|
|
296
|
+
*/
|
|
297
|
+
export function pubkeyToSegwitAddr(
|
|
298
|
+
publicKey: Buffer,
|
|
299
|
+
network: NetworkParams,
|
|
300
|
+
): string {
|
|
301
|
+
const publicKeyHash = bitcoin.crypto.hash160(publicKey);
|
|
302
|
+
const address = bitcoin.payments.p2wpkh({
|
|
303
|
+
hash: publicKeyHash,
|
|
304
|
+
network: network,
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
return address.address!;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Tweaker class for handling public key tweaking operations
|
|
312
|
+
*/
|
|
313
|
+
export class Tweaker {
|
|
314
|
+
private publicKey: Buffer;
|
|
315
|
+
|
|
316
|
+
constructor(publicKey: Buffer) {
|
|
317
|
+
// Validate the public key
|
|
318
|
+
if (!secp256k1.publicKeyVerify(publicKey)) {
|
|
319
|
+
throw new BitcoinAddressError("Invalid public key");
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
this.publicKey = publicKey;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Derive a new deposit public key from a 32-byte tweak
|
|
327
|
+
*/
|
|
328
|
+
derivePubkey(tweakBytes: Buffer | Uint8Array): Buffer {
|
|
329
|
+
return tweakPublicKey(this.publicKey, tweakBytes);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Derive a new deposit public key and build a segwit address
|
|
334
|
+
*/
|
|
335
|
+
deriveSegwit(
|
|
336
|
+
tweakBytes: Buffer | Uint8Array,
|
|
337
|
+
network: NetworkParams,
|
|
338
|
+
): {
|
|
339
|
+
address: string;
|
|
340
|
+
tweakedPublicKey: Buffer;
|
|
341
|
+
} {
|
|
342
|
+
const tweakedPublicKey = this.derivePubkey(tweakBytes);
|
|
343
|
+
const address = pubkeyToSegwitAddr(tweakedPublicKey, network);
|
|
344
|
+
|
|
345
|
+
return {
|
|
346
|
+
address,
|
|
347
|
+
tweakedPublicKey,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Get the original public key
|
|
353
|
+
*/
|
|
354
|
+
getPublicKey(): Buffer {
|
|
355
|
+
return this.publicKey;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Service class for calculating deterministic Bitcoin addresses
|
|
361
|
+
*/
|
|
362
|
+
export class AddressService {
|
|
363
|
+
private tweaker: Tweaker;
|
|
364
|
+
private network: NetworkParams;
|
|
365
|
+
|
|
366
|
+
constructor(config: Config) {
|
|
367
|
+
let network: NetworkParams;
|
|
368
|
+
|
|
369
|
+
switch (config.network) {
|
|
370
|
+
case "mainnet":
|
|
371
|
+
network = Networks.mainnet;
|
|
372
|
+
break;
|
|
373
|
+
case "signet":
|
|
374
|
+
network = Networks.signet;
|
|
375
|
+
break;
|
|
376
|
+
default:
|
|
377
|
+
throw new BitcoinAddressError(`Unknown network: '${config.network}'`);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
try {
|
|
381
|
+
this.tweaker = new Tweaker(config.depositPublicKey);
|
|
382
|
+
} catch (error) {
|
|
383
|
+
throw new BitcoinAddressError("Bad public deposit key");
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
this.network = network;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Calculate a deterministic address based on inputs
|
|
391
|
+
*/
|
|
392
|
+
calculateDeterministicAddress(
|
|
393
|
+
chainId: LChainId,
|
|
394
|
+
lbtcAddress: Address,
|
|
395
|
+
toAddress: Address,
|
|
396
|
+
referralId: Buffer | Uint8Array,
|
|
397
|
+
nonce: number,
|
|
398
|
+
blockchainType: BlockchainType,
|
|
399
|
+
): string {
|
|
400
|
+
// Compute aux data
|
|
401
|
+
let auxData: Buffer;
|
|
402
|
+
try {
|
|
403
|
+
auxData = computeAuxDataV0(nonce, referralId);
|
|
404
|
+
} catch (error) {
|
|
405
|
+
throw new BitcoinAddressError(
|
|
406
|
+
`Computing aux data for nonce=${nonce}, referal_id=${referralId.toString("hex")}: ${error}`,
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// Calculate tweak bytes
|
|
411
|
+
let tweakBytes: Buffer;
|
|
412
|
+
try {
|
|
413
|
+
tweakBytes = calcTweakBytes(
|
|
414
|
+
blockchainType,
|
|
415
|
+
chainId,
|
|
416
|
+
toAddress,
|
|
417
|
+
lbtcAddress,
|
|
418
|
+
auxData,
|
|
419
|
+
);
|
|
420
|
+
} catch (error) {
|
|
421
|
+
throw new BitcoinAddressError(
|
|
422
|
+
`Computing tweakBytes for deterministic address: ${error}`,
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// Derive segwit address
|
|
427
|
+
try {
|
|
428
|
+
const { address } = this.tweaker.deriveSegwit(tweakBytes, this.network);
|
|
429
|
+
return address;
|
|
430
|
+
} catch (error) {
|
|
431
|
+
throw new BitcoinAddressError(`Deriving segwit address: ${error}`);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Create a new address service from a configuration
|
|
438
|
+
*/
|
|
439
|
+
export function createAddressService(config: Config): AddressService {
|
|
440
|
+
return new AddressService(config);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// API Response interfaces
|
|
444
|
+
export interface DepositMetadata {
|
|
445
|
+
to_address: string;
|
|
446
|
+
to_blockchain: string;
|
|
447
|
+
referral: string;
|
|
448
|
+
nonce: number;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export interface AddressInfo {
|
|
452
|
+
btc_address: string;
|
|
453
|
+
type: string;
|
|
454
|
+
deposit_metadata: DepositMetadata;
|
|
455
|
+
created_at: string;
|
|
456
|
+
deprecated: boolean;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export interface ApiResponse {
|
|
460
|
+
addresses: AddressInfo[];
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Main function for calculating a deterministic address
|
|
465
|
+
*/
|
|
466
|
+
export async function calculateDeterministicAddress(
|
|
467
|
+
chain: SupportedBlockchains,
|
|
468
|
+
toAddress: string,
|
|
469
|
+
): Promise<{
|
|
470
|
+
computedAddresses: string[];
|
|
471
|
+
claimedAddresses: string[];
|
|
472
|
+
referralIds: string[];
|
|
473
|
+
nonces: number[];
|
|
474
|
+
}> {
|
|
475
|
+
if (!toAddress.startsWith("0x")) {
|
|
476
|
+
throw new BitcoinAddressError("Malformed toAddress");
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
let config: Config = {
|
|
480
|
+
network: "mainnet",
|
|
481
|
+
depositPublicKey: MAINNET_PUBLIC_KEY,
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
let chainId: Buffer;
|
|
485
|
+
let lbtcAddress: Address;
|
|
486
|
+
let destination: string;
|
|
487
|
+
let blockchainType: BlockchainType;
|
|
488
|
+
switch (chain) {
|
|
489
|
+
case SupportedBlockchains.Ethereum:
|
|
490
|
+
chainId = ETHEREUM_CHAIN_ID;
|
|
491
|
+
lbtcAddress = ETHEREUM_LBTC_CONTRACT;
|
|
492
|
+
destination = "DESTINATION_BLOCKCHAIN_ETHEREUM";
|
|
493
|
+
blockchainType = BlockchainType.EVM;
|
|
494
|
+
break;
|
|
495
|
+
case SupportedBlockchains.Base:
|
|
496
|
+
chainId = BASE_CHAIN_ID;
|
|
497
|
+
lbtcAddress = BASE_LBTC_CONTRACT;
|
|
498
|
+
destination = "DESTINATION_BLOCKCHAIN_BASE";
|
|
499
|
+
blockchainType = BlockchainType.EVM;
|
|
500
|
+
break;
|
|
501
|
+
case SupportedBlockchains.BSC:
|
|
502
|
+
chainId = BSC_CHAIN_ID;
|
|
503
|
+
lbtcAddress = BSC_LBTC_CONTRACT;
|
|
504
|
+
destination = "DESTINATION_BLOCKCHAIN_BSC";
|
|
505
|
+
blockchainType = BlockchainType.EVM;
|
|
506
|
+
break;
|
|
507
|
+
case SupportedBlockchains.Sui:
|
|
508
|
+
chainId = SUI_CHAIN_ID;
|
|
509
|
+
lbtcAddress = SUI_LBTC_CONTRACT;
|
|
510
|
+
destination = "DESTINATION_BLOCKCHAIN_SUI";
|
|
511
|
+
blockchainType = BlockchainType.Sui;
|
|
512
|
+
break;
|
|
513
|
+
default:
|
|
514
|
+
console.error("Unexpected destination chain:", chain);
|
|
515
|
+
throw new BitcoinAddressError(`Unexpected destination chain: ${chain}`);
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
let claimedAddresses: string[] = [];
|
|
520
|
+
let referralIds: string[] = [];
|
|
521
|
+
let nonces: number[] = [];
|
|
522
|
+
try {
|
|
523
|
+
// Fetch data from the API
|
|
524
|
+
const url = URL + destination + "/" + toAddress;
|
|
525
|
+
const response = await fetch(url);
|
|
526
|
+
|
|
527
|
+
if (!response.ok) {
|
|
528
|
+
throw new BitcoinAddressError(
|
|
529
|
+
`API request failed with status: ${response.status}`,
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const data = (await response.json()) as ApiResponse;
|
|
534
|
+
|
|
535
|
+
if (!data.addresses || data.addresses.length === 0) {
|
|
536
|
+
throw new BitcoinAddressError("No addresses returned from API");
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
data.addresses.forEach((address) => {
|
|
540
|
+
if (!address.deprecated || address.deprecated === undefined) {
|
|
541
|
+
claimedAddresses.push(address.btc_address);
|
|
542
|
+
referralIds.push(address.deposit_metadata.referral);
|
|
543
|
+
nonces.push(address.deposit_metadata.nonce);
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
} catch (error: unknown) {
|
|
547
|
+
if (error instanceof BitcoinAddressError) {
|
|
548
|
+
throw error;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
552
|
+
throw new BitcoinAddressError(
|
|
553
|
+
`Failed to verify address with API: ${errorMessage}`,
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const address = Buffer.from(toAddress.substring(2), "hex");
|
|
558
|
+
const service = createAddressService(config);
|
|
559
|
+
const len = claimedAddresses.length;
|
|
560
|
+
let computedAddresses: string[] = [];
|
|
561
|
+
for (let i = 0; i < len; i++) {
|
|
562
|
+
const computedAddress = service.calculateDeterministicAddress(
|
|
563
|
+
chainId,
|
|
564
|
+
lbtcAddress,
|
|
565
|
+
address,
|
|
566
|
+
Buffer.from(referralIds[i]),
|
|
567
|
+
nonces[i],
|
|
568
|
+
blockchainType,
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
computedAddresses.push(computedAddress);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
return { computedAddresses, claimedAddresses, referralIds, nonces };
|
|
575
|
+
}
|
package/example.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
calculateDeterministicAddress,
|
|
3
|
+
Config,
|
|
4
|
+
BlockchainType,
|
|
5
|
+
BitcoinAddressError,
|
|
6
|
+
SupportedBlockchains,
|
|
7
|
+
} from "./address-calculator";
|
|
8
|
+
|
|
9
|
+
// Example usage
|
|
10
|
+
async function generateSegwitAddress() {
|
|
11
|
+
try {
|
|
12
|
+
{
|
|
13
|
+
// Sample chain
|
|
14
|
+
const chain = SupportedBlockchains.Ethereum;
|
|
15
|
+
|
|
16
|
+
// Destination address (20 bytes)
|
|
17
|
+
const toAddress = "0x57f9672ba603251c9c03b36cabdbbca7ca8cfcf4";
|
|
18
|
+
|
|
19
|
+
// Calculate deterministic segwit address
|
|
20
|
+
const match = await calculateDeterministicAddress(chain, toAddress);
|
|
21
|
+
|
|
22
|
+
console.log("Match:", match);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
{
|
|
26
|
+
// Sample chain
|
|
27
|
+
const chain = SupportedBlockchains.BSC;
|
|
28
|
+
|
|
29
|
+
// Destination address (20 bytes)
|
|
30
|
+
const toAddress = "0xf594c30b28435afb37f0b10f71ac9fe45389fbdc";
|
|
31
|
+
|
|
32
|
+
// Calculate deterministic segwit address
|
|
33
|
+
const match = await calculateDeterministicAddress(chain, toAddress);
|
|
34
|
+
|
|
35
|
+
console.log("Match:", match);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
{
|
|
39
|
+
// Sample chain
|
|
40
|
+
const chain = SupportedBlockchains.Base;
|
|
41
|
+
|
|
42
|
+
// Destination address (20 bytes)
|
|
43
|
+
const toAddress = "0x0f90793a54e809bf708bd0fbcc63d311e3bb1be1";
|
|
44
|
+
|
|
45
|
+
// Calculate deterministic segwit address
|
|
46
|
+
const match = await calculateDeterministicAddress(chain, toAddress);
|
|
47
|
+
|
|
48
|
+
console.log("Match:", match);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
{
|
|
52
|
+
// Sample chain
|
|
53
|
+
const chain = SupportedBlockchains.Sui;
|
|
54
|
+
|
|
55
|
+
// Destination address (32 bytes)
|
|
56
|
+
const toAddress =
|
|
57
|
+
"0xa51d5c52371626bb6894ce9b599c935f8dea92ca34668f2da7148df2458640b8";
|
|
58
|
+
|
|
59
|
+
// Calculate deterministic segwit address
|
|
60
|
+
const match = await calculateDeterministicAddress(chain, toAddress);
|
|
61
|
+
|
|
62
|
+
console.log("Match:", match);
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (error instanceof BitcoinAddressError) {
|
|
66
|
+
console.error("Bitcoin Address Generation Error:", error.message);
|
|
67
|
+
} else {
|
|
68
|
+
console.error("Unexpected Error:", error);
|
|
69
|
+
}
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Run the example
|
|
75
|
+
generateSegwitAddress().catch(console.error);
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lombard.finance/ts-verifier",
|
|
3
|
+
"description": "Lombard Deposit Address Verifier",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"homepage": "/",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"format": "prettier *.js \"*{.js,.ts}\" -w",
|
|
8
|
+
"lint": "prettier *.js \"*{.js,.ts}\" --check"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@types/node": "^22.13.10",
|
|
12
|
+
"@types/secp256k1": "^4.0.6",
|
|
13
|
+
"bitcoinjs-lib": "^6.1.7",
|
|
14
|
+
"prettier": "^3.5.3",
|
|
15
|
+
"secp256k1": "^5.0.1",
|
|
16
|
+
"typescript": "^5.8.2"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Projects */
|
|
6
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
+
|
|
13
|
+
/* Language and Environment */
|
|
14
|
+
"target": "es2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
|
+
// "libReplacement": true, /* Enable lib replacement. */
|
|
18
|
+
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
19
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
20
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
21
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
22
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
23
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
24
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
25
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
26
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
27
|
+
|
|
28
|
+
/* Modules */
|
|
29
|
+
"module": "commonjs", /* Specify what module code is generated. */
|
|
30
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
31
|
+
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
32
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
33
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
34
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
35
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
36
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
37
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
38
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
39
|
+
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
40
|
+
// "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
|
|
41
|
+
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
42
|
+
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
43
|
+
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
44
|
+
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
|
|
45
|
+
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
46
|
+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
47
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
48
|
+
|
|
49
|
+
/* JavaScript Support */
|
|
50
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
51
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
52
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
53
|
+
|
|
54
|
+
/* Emit */
|
|
55
|
+
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
56
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
57
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
58
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
59
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
60
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
61
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
62
|
+
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
|
63
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
64
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
65
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
66
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
67
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
68
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
69
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
70
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
71
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
72
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
73
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
74
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
75
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
76
|
+
|
|
77
|
+
/* Interop Constraints */
|
|
78
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
79
|
+
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
80
|
+
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
|
81
|
+
// "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */
|
|
82
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
83
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
84
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
85
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
86
|
+
|
|
87
|
+
/* Type Checking */
|
|
88
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
89
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
90
|
+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
91
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
92
|
+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
93
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
94
|
+
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
|
|
95
|
+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
96
|
+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
97
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
98
|
+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
99
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
100
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
101
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
102
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
103
|
+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
104
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
105
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
106
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
107
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
108
|
+
|
|
109
|
+
/* Completeness */
|
|
110
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
111
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
112
|
+
}
|
|
113
|
+
}
|
package/verifier.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
calculateDeterministicAddress,
|
|
3
|
+
BitcoinAddressError,
|
|
4
|
+
SupportedBlockchains,
|
|
5
|
+
} from "./address-calculator";
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
const type = process.argv[2];
|
|
9
|
+
let blockchainType: SupportedBlockchains;
|
|
10
|
+
switch (type) {
|
|
11
|
+
case "ethereum":
|
|
12
|
+
blockchainType = SupportedBlockchains.Ethereum;
|
|
13
|
+
break;
|
|
14
|
+
case "base":
|
|
15
|
+
blockchainType = SupportedBlockchains.Base;
|
|
16
|
+
break;
|
|
17
|
+
case "bsc":
|
|
18
|
+
blockchainType = SupportedBlockchains.BSC;
|
|
19
|
+
break;
|
|
20
|
+
case "sui":
|
|
21
|
+
blockchainType = SupportedBlockchains.Sui;
|
|
22
|
+
break;
|
|
23
|
+
default:
|
|
24
|
+
throw new BitcoinAddressError(
|
|
25
|
+
`Unrecognized destination network: ${type}`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const toAddress = process.argv[3];
|
|
30
|
+
const { computedAddresses, claimedAddresses, referralIds, nonces } =
|
|
31
|
+
await calculateDeterministicAddress(blockchainType, toAddress);
|
|
32
|
+
|
|
33
|
+
const len = computedAddresses.length;
|
|
34
|
+
for (let i = 0; i < len; i++) {
|
|
35
|
+
console.log(`Checking for address ${claimedAddresses[i]}:`);
|
|
36
|
+
if (referralIds[i] != undefined) {
|
|
37
|
+
console.log(`- partner code: ${referralIds[i]}`);
|
|
38
|
+
}
|
|
39
|
+
if (nonces[i] != undefined) {
|
|
40
|
+
console.log(`- nonce: ${nonces[i]}`);
|
|
41
|
+
} else {
|
|
42
|
+
console.log(`- nonce: 0`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log(`Address fetched from API:\t${claimedAddresses[i]}`);
|
|
46
|
+
console.log(`Address computed:\t\t${computedAddresses[i]}`);
|
|
47
|
+
|
|
48
|
+
if (computedAddresses[i] === claimedAddresses[i]) {
|
|
49
|
+
console.log("Addresses match!");
|
|
50
|
+
} else {
|
|
51
|
+
console.log("WARNING: Address mismatch!");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (i !== len - 1) {
|
|
55
|
+
console.log("");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
main();
|