@vleap/warps-adapter-fastset 0.1.0-alpha.26 → 0.1.0-alpha.28
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/dist/index.d.cts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +668 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +674 -69
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
9
|
var __export = (target, all) => {
|
|
9
10
|
for (var name2 in all)
|
|
10
11
|
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
@@ -26,6 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
27
|
mod
|
|
27
28
|
));
|
|
28
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
29
31
|
|
|
30
32
|
// src/index.ts
|
|
31
33
|
var index_exports = {};
|
|
@@ -40,9 +42,6 @@ module.exports = __toCommonJS(index_exports);
|
|
|
40
42
|
// src/main.ts
|
|
41
43
|
var import_warps6 = require("@vleap/warps");
|
|
42
44
|
|
|
43
|
-
// src/WarpFastsetDataLoader.ts
|
|
44
|
-
var bech323 = __toESM(require("bech32"), 1);
|
|
45
|
-
|
|
46
45
|
// src/helpers/encode.ts
|
|
47
46
|
var encoder = new TextEncoder();
|
|
48
47
|
var decoder = new TextDecoder();
|
|
@@ -89,7 +88,10 @@ var FastsetClient = class {
|
|
|
89
88
|
});
|
|
90
89
|
}
|
|
91
90
|
async getAccountInfo(address) {
|
|
92
|
-
return this.request(this.proxyUrl, "set_proxy_getAccountInfo", { address });
|
|
91
|
+
return this.request(this.proxyUrl, "set_proxy_getAccountInfo", { address, token_balances_filter: [] });
|
|
92
|
+
}
|
|
93
|
+
async getTokenInfo(tokenIds) {
|
|
94
|
+
return this.request(this.proxyUrl, "set_proxy_getTokenInfo", { tokenIds: [Array.from(tokenIds)] });
|
|
93
95
|
}
|
|
94
96
|
async getNextNonce(address) {
|
|
95
97
|
const addressBytes = typeof address === "string" ? this.addressToBytes(address) : address;
|
|
@@ -99,10 +101,10 @@ var FastsetClient = class {
|
|
|
99
101
|
addressToBytes(address) {
|
|
100
102
|
try {
|
|
101
103
|
const decoded = bech32.bech32m.decode(address);
|
|
102
|
-
return
|
|
104
|
+
return new Uint8Array(bech32.bech32m.fromWords(decoded.words));
|
|
103
105
|
} catch {
|
|
104
106
|
const decoded = bech32.bech32.decode(address);
|
|
105
|
-
return
|
|
107
|
+
return new Uint8Array(bech32.bech32.fromWords(decoded.words));
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
static decodeBech32Address(address) {
|
|
@@ -126,6 +128,61 @@ var getConfiguredFastsetClient = (config, chain2) => {
|
|
|
126
128
|
return new FastsetClient(proxyUrl);
|
|
127
129
|
};
|
|
128
130
|
|
|
131
|
+
// src/tokens/fastset.ts
|
|
132
|
+
var FastsetTokens = [
|
|
133
|
+
{
|
|
134
|
+
chain: "fastset",
|
|
135
|
+
identifier: "08413efc81f99e5b8e03b852b3756674083110c6b65e6b7836b39a26e3908d3c",
|
|
136
|
+
name: "Ethereum",
|
|
137
|
+
symbol: "ETH",
|
|
138
|
+
decimals: 18,
|
|
139
|
+
logoUrl: "https://assets.coingecko.com/coins/images/279/small/ethereum.png",
|
|
140
|
+
amount: 0n
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
chain: "fastset",
|
|
144
|
+
identifier: "0ee63eaa3ff9bf6e1c84a70133c5461e6e06d3787ed93200b924a6b82f0f35ff",
|
|
145
|
+
name: "Bitcoin",
|
|
146
|
+
symbol: "BTC",
|
|
147
|
+
decimals: 8,
|
|
148
|
+
logoUrl: "https://assets.coingecko.com/coins/images/1/small/bitcoin.png",
|
|
149
|
+
amount: 0n
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
chain: "fastset",
|
|
153
|
+
identifier: "b69f0d3a4d7609367bd893ee3191e48b3047f2c4ccd21728c2441bcc2154f70c",
|
|
154
|
+
name: "Solana",
|
|
155
|
+
symbol: "SOL",
|
|
156
|
+
decimals: 9,
|
|
157
|
+
logoUrl: "https://assets.coingecko.com/coins/images/4128/small/solana.png",
|
|
158
|
+
amount: 0n
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
chain: "fastset",
|
|
162
|
+
identifier: "c83166ed4e5e3ca88f7b2cf0ce2d310fa8c4d2ee2fc90d741f7b2040279b2687",
|
|
163
|
+
name: "USD Coin",
|
|
164
|
+
symbol: "USDC",
|
|
165
|
+
decimals: 6,
|
|
166
|
+
logoUrl: "https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png",
|
|
167
|
+
amount: 0n
|
|
168
|
+
}
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
// src/tokens.ts
|
|
172
|
+
var KnownTokens = {
|
|
173
|
+
mainnet: FastsetTokens,
|
|
174
|
+
testnet: FastsetTokens,
|
|
175
|
+
devnet: FastsetTokens
|
|
176
|
+
};
|
|
177
|
+
var findKnownTokenBySymbol = (symbol, env = "mainnet") => {
|
|
178
|
+
const tokens = KnownTokens[env] || [];
|
|
179
|
+
return tokens.find((token) => token.symbol === symbol) || null;
|
|
180
|
+
};
|
|
181
|
+
var findKnownTokenById = (id2, env = "mainnet") => {
|
|
182
|
+
const tokens = KnownTokens[env] || [];
|
|
183
|
+
return tokens.find((token) => token.identifier === id2) || null;
|
|
184
|
+
};
|
|
185
|
+
|
|
129
186
|
// src/WarpFastsetDataLoader.ts
|
|
130
187
|
var WarpFastsetDataLoader = class {
|
|
131
188
|
constructor(config, chain2) {
|
|
@@ -134,15 +191,14 @@ var WarpFastsetDataLoader = class {
|
|
|
134
191
|
this.client = getConfiguredFastsetClient(config, chain2);
|
|
135
192
|
}
|
|
136
193
|
async getAccount(address) {
|
|
137
|
-
const addressBytes =
|
|
194
|
+
const addressBytes = FastsetClient.decodeBech32Address(address);
|
|
138
195
|
const accountInfo = await this.client.getAccountInfo(addressBytes);
|
|
139
196
|
return { chain: this.chain.name, address, balance: BigInt(parseInt(accountInfo.result?.balance ?? "0", 16)) };
|
|
140
197
|
}
|
|
141
198
|
async getAccountAssets(address) {
|
|
142
|
-
const addressBytes =
|
|
199
|
+
const addressBytes = FastsetClient.decodeBech32Address(address);
|
|
143
200
|
const accountInfo = await this.client.getAccountInfo(addressBytes);
|
|
144
201
|
const assets = [];
|
|
145
|
-
console.log("accountInfo", accountInfo);
|
|
146
202
|
const balance = BigInt(parseInt(accountInfo.result?.balance ?? "0", 16));
|
|
147
203
|
if (balance > 0n) {
|
|
148
204
|
assets.push({ ...this.chain.nativeToken, amount: balance });
|
|
@@ -150,15 +206,15 @@ var WarpFastsetDataLoader = class {
|
|
|
150
206
|
for (const [tokenId, tokenBalance] of accountInfo.result?.token_balance ?? []) {
|
|
151
207
|
const amount = BigInt(parseInt(tokenBalance, 16));
|
|
152
208
|
if (amount > 0n) {
|
|
153
|
-
const
|
|
154
|
-
|
|
209
|
+
const assetInfo = await this.getAssetInfo(Buffer.from(tokenId).toString("hex"));
|
|
210
|
+
if (!assetInfo) continue;
|
|
155
211
|
assets.push({
|
|
156
212
|
chain: this.chain.name,
|
|
157
213
|
identifier: Buffer.from(tokenId).toString("hex"),
|
|
158
|
-
symbol:
|
|
159
|
-
name:
|
|
160
|
-
decimals:
|
|
161
|
-
logoUrl:
|
|
214
|
+
symbol: assetInfo.symbol,
|
|
215
|
+
name: assetInfo.name,
|
|
216
|
+
decimals: assetInfo.decimals,
|
|
217
|
+
logoUrl: assetInfo.logoUrl || "",
|
|
162
218
|
amount
|
|
163
219
|
});
|
|
164
220
|
}
|
|
@@ -169,18 +225,18 @@ var WarpFastsetDataLoader = class {
|
|
|
169
225
|
if (identifier === this.chain.nativeToken.identifier) {
|
|
170
226
|
return this.chain.nativeToken;
|
|
171
227
|
}
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
228
|
+
const assetInfo = await this.getAssetInfo(identifier);
|
|
229
|
+
if (!assetInfo) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
176
232
|
return {
|
|
177
233
|
chain: this.chain.name,
|
|
178
234
|
identifier,
|
|
179
|
-
symbol:
|
|
180
|
-
name:
|
|
181
|
-
decimals:
|
|
182
|
-
logoUrl:
|
|
183
|
-
amount:
|
|
235
|
+
symbol: assetInfo.symbol,
|
|
236
|
+
name: assetInfo.name,
|
|
237
|
+
decimals: assetInfo.decimals,
|
|
238
|
+
logoUrl: assetInfo.logoUrl || null,
|
|
239
|
+
amount: 0n
|
|
184
240
|
};
|
|
185
241
|
}
|
|
186
242
|
async getAction(identifier, awaitCompleted = false) {
|
|
@@ -189,18 +245,24 @@ var WarpFastsetDataLoader = class {
|
|
|
189
245
|
async getAccountActions(address, options) {
|
|
190
246
|
return [];
|
|
191
247
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return
|
|
196
|
-
} catch {
|
|
197
|
-
try {
|
|
198
|
-
const decoded = bech323.bech32.decode(address);
|
|
199
|
-
return Array.from(bech323.bech32.fromWords(decoded.words));
|
|
200
|
-
} catch {
|
|
201
|
-
throw new Error(`Invalid FastSet address: ${address}`);
|
|
202
|
-
}
|
|
248
|
+
async getAssetInfo(identifier) {
|
|
249
|
+
const knownToken = findKnownTokenById(identifier, this.config.env) || findKnownTokenBySymbol(identifier, this.config.env);
|
|
250
|
+
if (knownToken) {
|
|
251
|
+
return knownToken;
|
|
203
252
|
}
|
|
253
|
+
const tokenInfo = await this.client.getTokenInfo(hexToUint8Array(identifier));
|
|
254
|
+
const metadata = tokenInfo.result?.requested_token_metadata[0]?.[1];
|
|
255
|
+
if (metadata) {
|
|
256
|
+
return {
|
|
257
|
+
chain: this.chain.name,
|
|
258
|
+
identifier,
|
|
259
|
+
symbol: metadata.token_name,
|
|
260
|
+
name: metadata.token_name,
|
|
261
|
+
decimals: metadata.decimals,
|
|
262
|
+
logoUrl: null
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
return null;
|
|
204
266
|
}
|
|
205
267
|
};
|
|
206
268
|
|
|
@@ -256,8 +318,8 @@ var WarpFastsetExplorer = class {
|
|
|
256
318
|
getAccountUrl(address) {
|
|
257
319
|
return `${this.explorerUrl}/account/${address}`;
|
|
258
320
|
}
|
|
259
|
-
getTransactionUrl(
|
|
260
|
-
return `${this.explorerUrl}/transaction/${
|
|
321
|
+
getTransactionUrl(hash2) {
|
|
322
|
+
return `${this.explorerUrl}/transaction/${hash2}`;
|
|
261
323
|
}
|
|
262
324
|
getAssetUrl(identifier) {
|
|
263
325
|
return `${this.explorerUrl}/asset/${identifier}`;
|
|
@@ -469,15 +531,549 @@ var WarpFastsetResults = class {
|
|
|
469
531
|
var bip39 = __toESM(require("@scure/bip39"), 1);
|
|
470
532
|
var import_warps5 = require("@vleap/warps");
|
|
471
533
|
|
|
472
|
-
//
|
|
473
|
-
var
|
|
534
|
+
// ../../node_modules/@noble/ed25519/index.js
|
|
535
|
+
var ed25519_exports = {};
|
|
536
|
+
__export(ed25519_exports, {
|
|
537
|
+
Point: () => Point,
|
|
538
|
+
etc: () => etc,
|
|
539
|
+
getPublicKey: () => getPublicKey,
|
|
540
|
+
getPublicKeyAsync: () => getPublicKeyAsync,
|
|
541
|
+
hash: () => hash,
|
|
542
|
+
hashes: () => hashes,
|
|
543
|
+
keygen: () => keygen,
|
|
544
|
+
keygenAsync: () => keygenAsync,
|
|
545
|
+
sign: () => sign,
|
|
546
|
+
signAsync: () => signAsync,
|
|
547
|
+
utils: () => utils,
|
|
548
|
+
verify: () => verify,
|
|
549
|
+
verifyAsync: () => verifyAsync
|
|
550
|
+
});
|
|
551
|
+
var ed25519_CURVE = {
|
|
552
|
+
p: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,
|
|
553
|
+
n: 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,
|
|
554
|
+
h: 8n,
|
|
555
|
+
a: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,
|
|
556
|
+
d: 0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,
|
|
557
|
+
Gx: 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,
|
|
558
|
+
Gy: 0x6666666666666666666666666666666666666666666666666666666666666658n
|
|
559
|
+
};
|
|
560
|
+
var { p: P, n: N, Gx, Gy, a: _a, d: _d, h } = ed25519_CURVE;
|
|
561
|
+
var L = 32;
|
|
562
|
+
var L2 = 64;
|
|
563
|
+
var captureTrace = (...args) => {
|
|
564
|
+
if ("captureStackTrace" in Error && typeof Error.captureStackTrace === "function") {
|
|
565
|
+
Error.captureStackTrace(...args);
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
var err = (message = "") => {
|
|
569
|
+
const e = new Error(message);
|
|
570
|
+
captureTrace(e, err);
|
|
571
|
+
throw e;
|
|
572
|
+
};
|
|
573
|
+
var isBig = (n) => typeof n === "bigint";
|
|
574
|
+
var isStr = (s) => typeof s === "string";
|
|
575
|
+
var isBytes = (a) => a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
576
|
+
var abytes = (value, length, title = "") => {
|
|
577
|
+
const bytes = isBytes(value);
|
|
578
|
+
const len = value?.length;
|
|
579
|
+
const needsLen = length !== void 0;
|
|
580
|
+
if (!bytes || needsLen && len !== length) {
|
|
581
|
+
const prefix = title && `"${title}" `;
|
|
582
|
+
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
583
|
+
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
584
|
+
err(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
585
|
+
}
|
|
586
|
+
return value;
|
|
587
|
+
};
|
|
588
|
+
var u8n = (len) => new Uint8Array(len);
|
|
589
|
+
var u8fr = (buf) => Uint8Array.from(buf);
|
|
590
|
+
var padh = (n, pad) => n.toString(16).padStart(pad, "0");
|
|
591
|
+
var bytesToHex = (b) => Array.from(abytes(b)).map((e) => padh(e, 2)).join("");
|
|
592
|
+
var C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
593
|
+
var _ch = (ch) => {
|
|
594
|
+
if (ch >= C._0 && ch <= C._9)
|
|
595
|
+
return ch - C._0;
|
|
596
|
+
if (ch >= C.A && ch <= C.F)
|
|
597
|
+
return ch - (C.A - 10);
|
|
598
|
+
if (ch >= C.a && ch <= C.f)
|
|
599
|
+
return ch - (C.a - 10);
|
|
600
|
+
return;
|
|
601
|
+
};
|
|
602
|
+
var hexToBytes = (hex) => {
|
|
603
|
+
const e = "hex invalid";
|
|
604
|
+
if (!isStr(hex))
|
|
605
|
+
return err(e);
|
|
606
|
+
const hl = hex.length;
|
|
607
|
+
const al = hl / 2;
|
|
608
|
+
if (hl % 2)
|
|
609
|
+
return err(e);
|
|
610
|
+
const array = u8n(al);
|
|
611
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
612
|
+
const n1 = _ch(hex.charCodeAt(hi));
|
|
613
|
+
const n2 = _ch(hex.charCodeAt(hi + 1));
|
|
614
|
+
if (n1 === void 0 || n2 === void 0)
|
|
615
|
+
return err(e);
|
|
616
|
+
array[ai] = n1 * 16 + n2;
|
|
617
|
+
}
|
|
618
|
+
return array;
|
|
619
|
+
};
|
|
620
|
+
var cr = () => globalThis?.crypto;
|
|
621
|
+
var subtle = () => cr()?.subtle ?? err("crypto.subtle must be defined, consider polyfill");
|
|
622
|
+
var concatBytes = (...arrs) => {
|
|
623
|
+
const r = u8n(arrs.reduce((sum, a) => sum + abytes(a).length, 0));
|
|
624
|
+
let pad = 0;
|
|
625
|
+
arrs.forEach((a) => {
|
|
626
|
+
r.set(a, pad);
|
|
627
|
+
pad += a.length;
|
|
628
|
+
});
|
|
629
|
+
return r;
|
|
630
|
+
};
|
|
631
|
+
var randomBytes = (len = L) => {
|
|
632
|
+
const c = cr();
|
|
633
|
+
return c.getRandomValues(u8n(len));
|
|
634
|
+
};
|
|
635
|
+
var big = BigInt;
|
|
636
|
+
var assertRange = (n, min, max, msg = "bad number: out of range") => isBig(n) && min <= n && n < max ? n : err(msg);
|
|
637
|
+
var M = (a, b = P) => {
|
|
638
|
+
const r = a % b;
|
|
639
|
+
return r >= 0n ? r : b + r;
|
|
640
|
+
};
|
|
641
|
+
var modN = (a) => M(a, N);
|
|
642
|
+
var invert = (num, md) => {
|
|
643
|
+
if (num === 0n || md <= 0n)
|
|
644
|
+
err("no inverse n=" + num + " mod=" + md);
|
|
645
|
+
let a = M(num, md), b = md, x = 0n, y = 1n, u = 1n, v = 0n;
|
|
646
|
+
while (a !== 0n) {
|
|
647
|
+
const q = b / a, r = b % a;
|
|
648
|
+
const m = x - u * q, n = y - v * q;
|
|
649
|
+
b = a, a = r, x = u, y = v, u = m, v = n;
|
|
650
|
+
}
|
|
651
|
+
return b === 1n ? M(x, md) : err("no inverse");
|
|
652
|
+
};
|
|
653
|
+
var callHash = (name2) => {
|
|
654
|
+
const fn = hashes[name2];
|
|
655
|
+
if (typeof fn !== "function")
|
|
656
|
+
err("hashes." + name2 + " not set");
|
|
657
|
+
return fn;
|
|
658
|
+
};
|
|
659
|
+
var hash = (msg) => callHash("sha512")(msg);
|
|
660
|
+
var apoint = (p) => p instanceof Point ? p : err("Point expected");
|
|
661
|
+
var B256 = 2n ** 256n;
|
|
662
|
+
var _Point = class _Point {
|
|
663
|
+
constructor(X, Y, Z, T) {
|
|
664
|
+
__publicField(this, "X");
|
|
665
|
+
__publicField(this, "Y");
|
|
666
|
+
__publicField(this, "Z");
|
|
667
|
+
__publicField(this, "T");
|
|
668
|
+
const max = B256;
|
|
669
|
+
this.X = assertRange(X, 0n, max);
|
|
670
|
+
this.Y = assertRange(Y, 0n, max);
|
|
671
|
+
this.Z = assertRange(Z, 1n, max);
|
|
672
|
+
this.T = assertRange(T, 0n, max);
|
|
673
|
+
Object.freeze(this);
|
|
674
|
+
}
|
|
675
|
+
static CURVE() {
|
|
676
|
+
return ed25519_CURVE;
|
|
677
|
+
}
|
|
678
|
+
static fromAffine(p) {
|
|
679
|
+
return new _Point(p.x, p.y, 1n, M(p.x * p.y));
|
|
680
|
+
}
|
|
681
|
+
/** RFC8032 5.1.3: Uint8Array to Point. */
|
|
682
|
+
static fromBytes(hex, zip215 = false) {
|
|
683
|
+
const d = _d;
|
|
684
|
+
const normed = u8fr(abytes(hex, L));
|
|
685
|
+
const lastByte = hex[31];
|
|
686
|
+
normed[31] = lastByte & ~128;
|
|
687
|
+
const y = bytesToNumLE(normed);
|
|
688
|
+
const max = zip215 ? B256 : P;
|
|
689
|
+
assertRange(y, 0n, max);
|
|
690
|
+
const y2 = M(y * y);
|
|
691
|
+
const u = M(y2 - 1n);
|
|
692
|
+
const v = M(d * y2 + 1n);
|
|
693
|
+
let { isValid, value: x } = uvRatio(u, v);
|
|
694
|
+
if (!isValid)
|
|
695
|
+
err("bad point: y not sqrt");
|
|
696
|
+
const isXOdd = (x & 1n) === 1n;
|
|
697
|
+
const isLastByteOdd = (lastByte & 128) !== 0;
|
|
698
|
+
if (!zip215 && x === 0n && isLastByteOdd)
|
|
699
|
+
err("bad point: x==0, isLastByteOdd");
|
|
700
|
+
if (isLastByteOdd !== isXOdd)
|
|
701
|
+
x = M(-x);
|
|
702
|
+
return new _Point(x, y, 1n, M(x * y));
|
|
703
|
+
}
|
|
704
|
+
static fromHex(hex, zip215) {
|
|
705
|
+
return _Point.fromBytes(hexToBytes(hex), zip215);
|
|
706
|
+
}
|
|
707
|
+
get x() {
|
|
708
|
+
return this.toAffine().x;
|
|
709
|
+
}
|
|
710
|
+
get y() {
|
|
711
|
+
return this.toAffine().y;
|
|
712
|
+
}
|
|
713
|
+
/** Checks if the point is valid and on-curve. */
|
|
714
|
+
assertValidity() {
|
|
715
|
+
const a = _a;
|
|
716
|
+
const d = _d;
|
|
717
|
+
const p = this;
|
|
718
|
+
if (p.is0())
|
|
719
|
+
return err("bad point: ZERO");
|
|
720
|
+
const { X, Y, Z, T } = p;
|
|
721
|
+
const X2 = M(X * X);
|
|
722
|
+
const Y2 = M(Y * Y);
|
|
723
|
+
const Z2 = M(Z * Z);
|
|
724
|
+
const Z4 = M(Z2 * Z2);
|
|
725
|
+
const aX2 = M(X2 * a);
|
|
726
|
+
const left = M(Z2 * M(aX2 + Y2));
|
|
727
|
+
const right = M(Z4 + M(d * M(X2 * Y2)));
|
|
728
|
+
if (left !== right)
|
|
729
|
+
return err("bad point: equation left != right (1)");
|
|
730
|
+
const XY = M(X * Y);
|
|
731
|
+
const ZT = M(Z * T);
|
|
732
|
+
if (XY !== ZT)
|
|
733
|
+
return err("bad point: equation left != right (2)");
|
|
734
|
+
return this;
|
|
735
|
+
}
|
|
736
|
+
/** Equality check: compare points P&Q. */
|
|
737
|
+
equals(other) {
|
|
738
|
+
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
739
|
+
const { X: X2, Y: Y2, Z: Z2 } = apoint(other);
|
|
740
|
+
const X1Z2 = M(X1 * Z2);
|
|
741
|
+
const X2Z1 = M(X2 * Z1);
|
|
742
|
+
const Y1Z2 = M(Y1 * Z2);
|
|
743
|
+
const Y2Z1 = M(Y2 * Z1);
|
|
744
|
+
return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
|
|
745
|
+
}
|
|
746
|
+
is0() {
|
|
747
|
+
return this.equals(I);
|
|
748
|
+
}
|
|
749
|
+
/** Flip point over y coordinate. */
|
|
750
|
+
negate() {
|
|
751
|
+
return new _Point(M(-this.X), this.Y, this.Z, M(-this.T));
|
|
752
|
+
}
|
|
753
|
+
/** Point doubling. Complete formula. Cost: `4M + 4S + 1*a + 6add + 1*2`. */
|
|
754
|
+
double() {
|
|
755
|
+
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
756
|
+
const a = _a;
|
|
757
|
+
const A = M(X1 * X1);
|
|
758
|
+
const B = M(Y1 * Y1);
|
|
759
|
+
const C2 = M(2n * M(Z1 * Z1));
|
|
760
|
+
const D = M(a * A);
|
|
761
|
+
const x1y1 = X1 + Y1;
|
|
762
|
+
const E = M(M(x1y1 * x1y1) - A - B);
|
|
763
|
+
const G2 = D + B;
|
|
764
|
+
const F = G2 - C2;
|
|
765
|
+
const H = D - B;
|
|
766
|
+
const X3 = M(E * F);
|
|
767
|
+
const Y3 = M(G2 * H);
|
|
768
|
+
const T3 = M(E * H);
|
|
769
|
+
const Z3 = M(F * G2);
|
|
770
|
+
return new _Point(X3, Y3, Z3, T3);
|
|
771
|
+
}
|
|
772
|
+
/** Point addition. Complete formula. Cost: `8M + 1*k + 8add + 1*2`. */
|
|
773
|
+
add(other) {
|
|
774
|
+
const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
|
|
775
|
+
const { X: X2, Y: Y2, Z: Z2, T: T2 } = apoint(other);
|
|
776
|
+
const a = _a;
|
|
777
|
+
const d = _d;
|
|
778
|
+
const A = M(X1 * X2);
|
|
779
|
+
const B = M(Y1 * Y2);
|
|
780
|
+
const C2 = M(T1 * d * T2);
|
|
781
|
+
const D = M(Z1 * Z2);
|
|
782
|
+
const E = M((X1 + Y1) * (X2 + Y2) - A - B);
|
|
783
|
+
const F = M(D - C2);
|
|
784
|
+
const G2 = M(D + C2);
|
|
785
|
+
const H = M(B - a * A);
|
|
786
|
+
const X3 = M(E * F);
|
|
787
|
+
const Y3 = M(G2 * H);
|
|
788
|
+
const T3 = M(E * H);
|
|
789
|
+
const Z3 = M(F * G2);
|
|
790
|
+
return new _Point(X3, Y3, Z3, T3);
|
|
791
|
+
}
|
|
792
|
+
subtract(other) {
|
|
793
|
+
return this.add(apoint(other).negate());
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
|
|
797
|
+
* Uses {@link wNAF} for base point.
|
|
798
|
+
* Uses fake point to mitigate side-channel leakage.
|
|
799
|
+
* @param n scalar by which point is multiplied
|
|
800
|
+
* @param safe safe mode guards against timing attacks; unsafe mode is faster
|
|
801
|
+
*/
|
|
802
|
+
multiply(n, safe = true) {
|
|
803
|
+
if (!safe && (n === 0n || this.is0()))
|
|
804
|
+
return I;
|
|
805
|
+
assertRange(n, 1n, N);
|
|
806
|
+
if (n === 1n)
|
|
807
|
+
return this;
|
|
808
|
+
if (this.equals(G))
|
|
809
|
+
return wNAF(n).p;
|
|
810
|
+
let p = I;
|
|
811
|
+
let f = G;
|
|
812
|
+
for (let d = this; n > 0n; d = d.double(), n >>= 1n) {
|
|
813
|
+
if (n & 1n)
|
|
814
|
+
p = p.add(d);
|
|
815
|
+
else if (safe)
|
|
816
|
+
f = f.add(d);
|
|
817
|
+
}
|
|
818
|
+
return p;
|
|
819
|
+
}
|
|
820
|
+
multiplyUnsafe(scalar) {
|
|
821
|
+
return this.multiply(scalar, false);
|
|
822
|
+
}
|
|
823
|
+
/** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
|
|
824
|
+
toAffine() {
|
|
825
|
+
const { X, Y, Z } = this;
|
|
826
|
+
if (this.equals(I))
|
|
827
|
+
return { x: 0n, y: 1n };
|
|
828
|
+
const iz = invert(Z, P);
|
|
829
|
+
if (M(Z * iz) !== 1n)
|
|
830
|
+
err("invalid inverse");
|
|
831
|
+
const x = M(X * iz);
|
|
832
|
+
const y = M(Y * iz);
|
|
833
|
+
return { x, y };
|
|
834
|
+
}
|
|
835
|
+
toBytes() {
|
|
836
|
+
const { x, y } = this.assertValidity().toAffine();
|
|
837
|
+
const b = numTo32bLE(y);
|
|
838
|
+
b[31] |= x & 1n ? 128 : 0;
|
|
839
|
+
return b;
|
|
840
|
+
}
|
|
841
|
+
toHex() {
|
|
842
|
+
return bytesToHex(this.toBytes());
|
|
843
|
+
}
|
|
844
|
+
clearCofactor() {
|
|
845
|
+
return this.multiply(big(h), false);
|
|
846
|
+
}
|
|
847
|
+
isSmallOrder() {
|
|
848
|
+
return this.clearCofactor().is0();
|
|
849
|
+
}
|
|
850
|
+
isTorsionFree() {
|
|
851
|
+
let p = this.multiply(N / 2n, false).double();
|
|
852
|
+
if (N % 2n)
|
|
853
|
+
p = p.add(this);
|
|
854
|
+
return p.is0();
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
__publicField(_Point, "BASE");
|
|
858
|
+
__publicField(_Point, "ZERO");
|
|
859
|
+
var Point = _Point;
|
|
860
|
+
var G = new Point(Gx, Gy, 1n, M(Gx * Gy));
|
|
861
|
+
var I = new Point(0n, 1n, 1n, 0n);
|
|
862
|
+
Point.BASE = G;
|
|
863
|
+
Point.ZERO = I;
|
|
864
|
+
var numTo32bLE = (num) => hexToBytes(padh(assertRange(num, 0n, B256), L2)).reverse();
|
|
865
|
+
var bytesToNumLE = (b) => big("0x" + bytesToHex(u8fr(abytes(b)).reverse()));
|
|
866
|
+
var pow2 = (x, power) => {
|
|
867
|
+
let r = x;
|
|
868
|
+
while (power-- > 0n) {
|
|
869
|
+
r *= r;
|
|
870
|
+
r %= P;
|
|
871
|
+
}
|
|
872
|
+
return r;
|
|
873
|
+
};
|
|
874
|
+
var pow_2_252_3 = (x) => {
|
|
875
|
+
const x2 = x * x % P;
|
|
876
|
+
const b2 = x2 * x % P;
|
|
877
|
+
const b4 = pow2(b2, 2n) * b2 % P;
|
|
878
|
+
const b5 = pow2(b4, 1n) * x % P;
|
|
879
|
+
const b10 = pow2(b5, 5n) * b5 % P;
|
|
880
|
+
const b20 = pow2(b10, 10n) * b10 % P;
|
|
881
|
+
const b40 = pow2(b20, 20n) * b20 % P;
|
|
882
|
+
const b80 = pow2(b40, 40n) * b40 % P;
|
|
883
|
+
const b160 = pow2(b80, 80n) * b80 % P;
|
|
884
|
+
const b240 = pow2(b160, 80n) * b80 % P;
|
|
885
|
+
const b250 = pow2(b240, 10n) * b10 % P;
|
|
886
|
+
const pow_p_5_8 = pow2(b250, 2n) * x % P;
|
|
887
|
+
return { pow_p_5_8, b2 };
|
|
888
|
+
};
|
|
889
|
+
var RM1 = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n;
|
|
890
|
+
var uvRatio = (u, v) => {
|
|
891
|
+
const v3 = M(v * v * v);
|
|
892
|
+
const v7 = M(v3 * v3 * v);
|
|
893
|
+
const pow = pow_2_252_3(u * v7).pow_p_5_8;
|
|
894
|
+
let x = M(u * v3 * pow);
|
|
895
|
+
const vx2 = M(v * x * x);
|
|
896
|
+
const root1 = x;
|
|
897
|
+
const root2 = M(x * RM1);
|
|
898
|
+
const useRoot1 = vx2 === u;
|
|
899
|
+
const useRoot2 = vx2 === M(-u);
|
|
900
|
+
const noRoot = vx2 === M(-u * RM1);
|
|
901
|
+
if (useRoot1)
|
|
902
|
+
x = root1;
|
|
903
|
+
if (useRoot2 || noRoot)
|
|
904
|
+
x = root2;
|
|
905
|
+
if ((M(x) & 1n) === 1n)
|
|
906
|
+
x = M(-x);
|
|
907
|
+
return { isValid: useRoot1 || useRoot2, value: x };
|
|
908
|
+
};
|
|
909
|
+
var modL_LE = (hash2) => modN(bytesToNumLE(hash2));
|
|
910
|
+
var sha512a = (...m) => hashes.sha512Async(concatBytes(...m));
|
|
911
|
+
var sha512s = (...m) => callHash("sha512")(concatBytes(...m));
|
|
912
|
+
var hash2extK = (hashed) => {
|
|
913
|
+
const head = hashed.slice(0, L);
|
|
914
|
+
head[0] &= 248;
|
|
915
|
+
head[31] &= 127;
|
|
916
|
+
head[31] |= 64;
|
|
917
|
+
const prefix = hashed.slice(L, L2);
|
|
918
|
+
const scalar = modL_LE(head);
|
|
919
|
+
const point = G.multiply(scalar);
|
|
920
|
+
const pointBytes = point.toBytes();
|
|
921
|
+
return { head, prefix, scalar, point, pointBytes };
|
|
922
|
+
};
|
|
923
|
+
var getExtendedPublicKeyAsync = (secretKey) => sha512a(abytes(secretKey, L)).then(hash2extK);
|
|
924
|
+
var getExtendedPublicKey = (secretKey) => hash2extK(sha512s(abytes(secretKey, L)));
|
|
925
|
+
var getPublicKeyAsync = (secretKey) => getExtendedPublicKeyAsync(secretKey).then((p) => p.pointBytes);
|
|
926
|
+
var getPublicKey = (priv) => getExtendedPublicKey(priv).pointBytes;
|
|
927
|
+
var hashFinishA = (res) => sha512a(res.hashable).then(res.finish);
|
|
928
|
+
var hashFinishS = (res) => res.finish(sha512s(res.hashable));
|
|
929
|
+
var _sign = (e, rBytes, msg) => {
|
|
930
|
+
const { pointBytes: P2, scalar: s } = e;
|
|
931
|
+
const r = modL_LE(rBytes);
|
|
932
|
+
const R = G.multiply(r).toBytes();
|
|
933
|
+
const hashable = concatBytes(R, P2, msg);
|
|
934
|
+
const finish = (hashed) => {
|
|
935
|
+
const S = modN(r + modL_LE(hashed) * s);
|
|
936
|
+
return abytes(concatBytes(R, numTo32bLE(S)), L2);
|
|
937
|
+
};
|
|
938
|
+
return { hashable, finish };
|
|
939
|
+
};
|
|
940
|
+
var signAsync = async (message, secretKey) => {
|
|
941
|
+
const m = abytes(message);
|
|
942
|
+
const e = await getExtendedPublicKeyAsync(secretKey);
|
|
943
|
+
const rBytes = await sha512a(e.prefix, m);
|
|
944
|
+
return hashFinishA(_sign(e, rBytes, m));
|
|
945
|
+
};
|
|
946
|
+
var sign = (message, secretKey) => {
|
|
947
|
+
const m = abytes(message);
|
|
948
|
+
const e = getExtendedPublicKey(secretKey);
|
|
949
|
+
const rBytes = sha512s(e.prefix, m);
|
|
950
|
+
return hashFinishS(_sign(e, rBytes, m));
|
|
951
|
+
};
|
|
952
|
+
var defaultVerifyOpts = { zip215: true };
|
|
953
|
+
var _verify = (sig, msg, pub, opts = defaultVerifyOpts) => {
|
|
954
|
+
sig = abytes(sig, L2);
|
|
955
|
+
msg = abytes(msg);
|
|
956
|
+
pub = abytes(pub, L);
|
|
957
|
+
const { zip215 } = opts;
|
|
958
|
+
let A;
|
|
959
|
+
let R;
|
|
960
|
+
let s;
|
|
961
|
+
let SB;
|
|
962
|
+
let hashable = Uint8Array.of();
|
|
963
|
+
try {
|
|
964
|
+
A = Point.fromBytes(pub, zip215);
|
|
965
|
+
R = Point.fromBytes(sig.slice(0, L), zip215);
|
|
966
|
+
s = bytesToNumLE(sig.slice(L, L2));
|
|
967
|
+
SB = G.multiply(s, false);
|
|
968
|
+
hashable = concatBytes(R.toBytes(), A.toBytes(), msg);
|
|
969
|
+
} catch (error) {
|
|
970
|
+
}
|
|
971
|
+
const finish = (hashed) => {
|
|
972
|
+
if (SB == null)
|
|
973
|
+
return false;
|
|
974
|
+
if (!zip215 && A.isSmallOrder())
|
|
975
|
+
return false;
|
|
976
|
+
const k = modL_LE(hashed);
|
|
977
|
+
const RkA = R.add(A.multiply(k, false));
|
|
978
|
+
return RkA.add(SB.negate()).clearCofactor().is0();
|
|
979
|
+
};
|
|
980
|
+
return { hashable, finish };
|
|
981
|
+
};
|
|
982
|
+
var verifyAsync = async (signature, message, publicKey, opts = defaultVerifyOpts) => hashFinishA(_verify(signature, message, publicKey, opts));
|
|
983
|
+
var verify = (signature, message, publicKey, opts = defaultVerifyOpts) => hashFinishS(_verify(signature, message, publicKey, opts));
|
|
984
|
+
var etc = {
|
|
985
|
+
bytesToHex,
|
|
986
|
+
hexToBytes,
|
|
987
|
+
concatBytes,
|
|
988
|
+
mod: M,
|
|
989
|
+
invert,
|
|
990
|
+
randomBytes
|
|
991
|
+
};
|
|
992
|
+
var hashes = {
|
|
993
|
+
sha512Async: async (message) => {
|
|
994
|
+
const s = subtle();
|
|
995
|
+
const m = concatBytes(message);
|
|
996
|
+
return u8n(await s.digest("SHA-512", m.buffer));
|
|
997
|
+
},
|
|
998
|
+
sha512: void 0
|
|
999
|
+
};
|
|
1000
|
+
var randomSecretKey = (seed = randomBytes(L)) => seed;
|
|
1001
|
+
var keygen = (seed) => {
|
|
1002
|
+
const secretKey = randomSecretKey(seed);
|
|
1003
|
+
const publicKey = getPublicKey(secretKey);
|
|
1004
|
+
return { secretKey, publicKey };
|
|
1005
|
+
};
|
|
1006
|
+
var keygenAsync = async (seed) => {
|
|
1007
|
+
const secretKey = randomSecretKey(seed);
|
|
1008
|
+
const publicKey = await getPublicKeyAsync(secretKey);
|
|
1009
|
+
return { secretKey, publicKey };
|
|
1010
|
+
};
|
|
1011
|
+
var utils = {
|
|
1012
|
+
getExtendedPublicKeyAsync,
|
|
1013
|
+
getExtendedPublicKey,
|
|
1014
|
+
randomSecretKey
|
|
1015
|
+
};
|
|
1016
|
+
var W = 8;
|
|
1017
|
+
var scalarBits = 256;
|
|
1018
|
+
var pwindows = Math.ceil(scalarBits / W) + 1;
|
|
1019
|
+
var pwindowSize = 2 ** (W - 1);
|
|
1020
|
+
var precompute = () => {
|
|
1021
|
+
const points = [];
|
|
1022
|
+
let p = G;
|
|
1023
|
+
let b = p;
|
|
1024
|
+
for (let w = 0; w < pwindows; w++) {
|
|
1025
|
+
b = p;
|
|
1026
|
+
points.push(b);
|
|
1027
|
+
for (let i = 1; i < pwindowSize; i++) {
|
|
1028
|
+
b = b.add(p);
|
|
1029
|
+
points.push(b);
|
|
1030
|
+
}
|
|
1031
|
+
p = b.double();
|
|
1032
|
+
}
|
|
1033
|
+
return points;
|
|
1034
|
+
};
|
|
1035
|
+
var Gpows = void 0;
|
|
1036
|
+
var ctneg = (cnd, p) => {
|
|
1037
|
+
const n = p.negate();
|
|
1038
|
+
return cnd ? n : p;
|
|
1039
|
+
};
|
|
1040
|
+
var wNAF = (n) => {
|
|
1041
|
+
const comp = Gpows || (Gpows = precompute());
|
|
1042
|
+
let p = I;
|
|
1043
|
+
let f = G;
|
|
1044
|
+
const pow_2_w = 2 ** W;
|
|
1045
|
+
const maxNum = pow_2_w;
|
|
1046
|
+
const mask = big(pow_2_w - 1);
|
|
1047
|
+
const shiftBy = big(W);
|
|
1048
|
+
for (let w = 0; w < pwindows; w++) {
|
|
1049
|
+
let wbits = Number(n & mask);
|
|
1050
|
+
n >>= shiftBy;
|
|
1051
|
+
if (wbits > pwindowSize) {
|
|
1052
|
+
wbits -= maxNum;
|
|
1053
|
+
n += 1n;
|
|
1054
|
+
}
|
|
1055
|
+
const off = w * pwindowSize;
|
|
1056
|
+
const offF = off;
|
|
1057
|
+
const offP = off + Math.abs(wbits) - 1;
|
|
1058
|
+
const isEven = w % 2 !== 0;
|
|
1059
|
+
const isNeg = wbits < 0;
|
|
1060
|
+
if (wbits === 0) {
|
|
1061
|
+
f = f.add(ctneg(isEven, comp[offF]));
|
|
1062
|
+
} else {
|
|
1063
|
+
p = p.add(ctneg(isNeg, comp[offP]));
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
if (n !== 0n)
|
|
1067
|
+
err("invalid wnaf");
|
|
1068
|
+
return { p, f };
|
|
1069
|
+
};
|
|
474
1070
|
|
|
475
1071
|
// ../../node_modules/@noble/hashes/esm/utils.js
|
|
476
|
-
function
|
|
1072
|
+
function isBytes2(a) {
|
|
477
1073
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
478
1074
|
}
|
|
479
|
-
function
|
|
480
|
-
if (!
|
|
1075
|
+
function abytes2(b, ...lengths) {
|
|
1076
|
+
if (!isBytes2(b))
|
|
481
1077
|
throw new Error("Uint8Array expected");
|
|
482
1078
|
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
483
1079
|
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
@@ -489,7 +1085,7 @@ function aexists(instance, checkFinished = true) {
|
|
|
489
1085
|
throw new Error("Hash#digest() has already been called");
|
|
490
1086
|
}
|
|
491
1087
|
function aoutput(out, instance) {
|
|
492
|
-
|
|
1088
|
+
abytes2(out);
|
|
493
1089
|
const min = instance.outputLen;
|
|
494
1090
|
if (out.length < min) {
|
|
495
1091
|
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
@@ -511,7 +1107,7 @@ function utf8ToBytes(str) {
|
|
|
511
1107
|
function toBytes(data) {
|
|
512
1108
|
if (typeof data === "string")
|
|
513
1109
|
data = utf8ToBytes(data);
|
|
514
|
-
|
|
1110
|
+
abytes2(data);
|
|
515
1111
|
return data;
|
|
516
1112
|
}
|
|
517
1113
|
var Hash = class {
|
|
@@ -533,9 +1129,9 @@ function setBigUint64(view, byteOffset, value, isLE) {
|
|
|
533
1129
|
const _u32_max = BigInt(4294967295);
|
|
534
1130
|
const wh = Number(value >> _32n2 & _u32_max);
|
|
535
1131
|
const wl = Number(value & _u32_max);
|
|
536
|
-
const
|
|
1132
|
+
const h2 = isLE ? 4 : 0;
|
|
537
1133
|
const l = isLE ? 0 : 4;
|
|
538
|
-
view.setUint32(byteOffset +
|
|
1134
|
+
view.setUint32(byteOffset + h2, wh, isLE);
|
|
539
1135
|
view.setUint32(byteOffset + l, wl, isLE);
|
|
540
1136
|
}
|
|
541
1137
|
var HashMD = class extends Hash {
|
|
@@ -555,7 +1151,7 @@ var HashMD = class extends Hash {
|
|
|
555
1151
|
update(data) {
|
|
556
1152
|
aexists(this);
|
|
557
1153
|
data = toBytes(data);
|
|
558
|
-
|
|
1154
|
+
abytes2(data);
|
|
559
1155
|
const { view, buffer, blockLen } = this;
|
|
560
1156
|
const len = data.length;
|
|
561
1157
|
for (let pos = 0; pos < len; ) {
|
|
@@ -660,17 +1256,17 @@ function split(lst, le = false) {
|
|
|
660
1256
|
let Ah = new Uint32Array(len);
|
|
661
1257
|
let Al = new Uint32Array(len);
|
|
662
1258
|
for (let i = 0; i < len; i++) {
|
|
663
|
-
const { h, l } = fromBig(lst[i], le);
|
|
664
|
-
[Ah[i], Al[i]] = [
|
|
1259
|
+
const { h: h2, l } = fromBig(lst[i], le);
|
|
1260
|
+
[Ah[i], Al[i]] = [h2, l];
|
|
665
1261
|
}
|
|
666
1262
|
return [Ah, Al];
|
|
667
1263
|
}
|
|
668
|
-
var shrSH = (
|
|
669
|
-
var shrSL = (
|
|
670
|
-
var rotrSH = (
|
|
671
|
-
var rotrSL = (
|
|
672
|
-
var rotrBH = (
|
|
673
|
-
var rotrBL = (
|
|
1264
|
+
var shrSH = (h2, _l, s) => h2 >>> s;
|
|
1265
|
+
var shrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
|
|
1266
|
+
var rotrSH = (h2, l, s) => h2 >>> s | l << 32 - s;
|
|
1267
|
+
var rotrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
|
|
1268
|
+
var rotrBH = (h2, l, s) => h2 << 64 - s | l >>> s - 32;
|
|
1269
|
+
var rotrBL = (h2, l, s) => h2 >>> s - 32 | l << 64 - s;
|
|
674
1270
|
function add(Ah, Al, Bh, Bl) {
|
|
675
1271
|
const l = (Al >>> 0) + (Bl >>> 0);
|
|
676
1272
|
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
@@ -886,10 +1482,10 @@ var sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
|
|
|
886
1482
|
var sha5122 = sha512;
|
|
887
1483
|
|
|
888
1484
|
// src/sdk/ed25519-setup.ts
|
|
889
|
-
|
|
1485
|
+
hashes.sha512 = sha5122;
|
|
890
1486
|
|
|
891
1487
|
// ../../node_modules/@scure/base/lib/esm/index.js
|
|
892
|
-
function
|
|
1488
|
+
function isBytes3(a) {
|
|
893
1489
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
894
1490
|
}
|
|
895
1491
|
function isArrayOf(isString, arr) {
|
|
@@ -1027,7 +1623,7 @@ function radix(num) {
|
|
|
1027
1623
|
const _256 = 2 ** 8;
|
|
1028
1624
|
return {
|
|
1029
1625
|
encode: (bytes) => {
|
|
1030
|
-
if (!
|
|
1626
|
+
if (!isBytes3(bytes))
|
|
1031
1627
|
throw new Error("radix.encode input should be Uint8Array");
|
|
1032
1628
|
return convertRadix(Array.from(bytes), _256, num);
|
|
1033
1629
|
},
|
|
@@ -2236,9 +2832,6 @@ var WarpFastsetWallet = class {
|
|
|
2236
2832
|
this.config = config;
|
|
2237
2833
|
this.chain = chain2;
|
|
2238
2834
|
this.client = getConfiguredFastsetClient(this.config, this.chain);
|
|
2239
|
-
const privateKey = (0, import_warps5.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
|
|
2240
|
-
if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
|
|
2241
|
-
this.privateKey = privateKey;
|
|
2242
2835
|
}
|
|
2243
2836
|
async signTransaction(tx) {
|
|
2244
2837
|
const msg = Transaction.serialize(tx);
|
|
@@ -2247,14 +2840,18 @@ var WarpFastsetWallet = class {
|
|
|
2247
2840
|
const dataToSign = new Uint8Array(prefix.length + msgBytes.length);
|
|
2248
2841
|
dataToSign.set(prefix, 0);
|
|
2249
2842
|
dataToSign.set(msgBytes, prefix.length);
|
|
2250
|
-
const
|
|
2251
|
-
|
|
2843
|
+
const privateKey = (0, import_warps5.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
|
|
2844
|
+
if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
|
|
2845
|
+
const privateKeyBytes = hexToUint8Array(privateKey);
|
|
2846
|
+
const signature = ed25519_exports.sign(dataToSign, privateKeyBytes);
|
|
2252
2847
|
return { ...tx, signature };
|
|
2253
2848
|
}
|
|
2254
2849
|
async signMessage(message) {
|
|
2255
2850
|
const messageBytes = stringToUint8Array(message);
|
|
2256
|
-
const
|
|
2257
|
-
|
|
2851
|
+
const privateKey = (0, import_warps5.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
|
|
2852
|
+
if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
|
|
2853
|
+
const privateKeyBytes = hexToUint8Array(privateKey);
|
|
2854
|
+
const signature = ed25519_exports.sign(messageBytes, privateKeyBytes);
|
|
2258
2855
|
return uint8ArrayToHex(signature);
|
|
2259
2856
|
}
|
|
2260
2857
|
async sendTransaction(tx) {
|
|
@@ -2263,19 +2860,18 @@ var WarpFastsetWallet = class {
|
|
|
2263
2860
|
const proxyUrl = (0, import_warps5.getProviderUrl)(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
2264
2861
|
const response = await this.client.request(proxyUrl, "set_proxy_submitTransaction", submitTxReq);
|
|
2265
2862
|
if (response.error) throw new Error(`JSON-RPC error ${response.error.code}: ${response.error.message}`);
|
|
2266
|
-
console.log("submitTransaction response", response.result);
|
|
2267
2863
|
return "TODO";
|
|
2268
2864
|
}
|
|
2269
2865
|
create(mnemonic) {
|
|
2270
2866
|
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
2271
2867
|
const privateKey = seed.slice(0, 32);
|
|
2272
|
-
const publicKey =
|
|
2868
|
+
const publicKey = ed25519_exports.getPublicKey(privateKey);
|
|
2273
2869
|
const address = FastsetClient.encodeBech32Address(publicKey);
|
|
2274
2870
|
return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic };
|
|
2275
2871
|
}
|
|
2276
2872
|
generate() {
|
|
2277
|
-
const privateKey =
|
|
2278
|
-
const publicKey =
|
|
2873
|
+
const privateKey = ed25519_exports.utils.randomPrivateKey();
|
|
2874
|
+
const publicKey = ed25519_exports.getPublicKey(privateKey);
|
|
2279
2875
|
const address = FastsetClient.encodeBech32Address(publicKey);
|
|
2280
2876
|
return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic: null };
|
|
2281
2877
|
}
|
|
@@ -2356,6 +2952,9 @@ var getFastsetAdapter = createFastsetAdapter(import_warps6.WarpChainName.Fastset
|
|
|
2356
2952
|
});
|
|
2357
2953
|
/*! Bundled license information:
|
|
2358
2954
|
|
|
2955
|
+
@noble/ed25519/index.js:
|
|
2956
|
+
(*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
|
|
2957
|
+
|
|
2359
2958
|
@noble/hashes/esm/utils.js:
|
|
2360
2959
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
2361
2960
|
|