@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.mjs
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name2 in all)
|
|
5
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
6
|
+
};
|
|
7
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
+
|
|
1
9
|
// src/main.ts
|
|
2
10
|
import { WarpChainName } from "@vleap/warps";
|
|
3
11
|
|
|
4
|
-
// src/WarpFastsetDataLoader.ts
|
|
5
|
-
import * as bech323 from "bech32";
|
|
6
|
-
|
|
7
12
|
// src/helpers/encode.ts
|
|
8
13
|
var encoder = new TextEncoder();
|
|
9
14
|
var decoder = new TextDecoder();
|
|
@@ -50,7 +55,10 @@ var FastsetClient = class {
|
|
|
50
55
|
});
|
|
51
56
|
}
|
|
52
57
|
async getAccountInfo(address) {
|
|
53
|
-
return this.request(this.proxyUrl, "set_proxy_getAccountInfo", { address });
|
|
58
|
+
return this.request(this.proxyUrl, "set_proxy_getAccountInfo", { address, token_balances_filter: [] });
|
|
59
|
+
}
|
|
60
|
+
async getTokenInfo(tokenIds) {
|
|
61
|
+
return this.request(this.proxyUrl, "set_proxy_getTokenInfo", { tokenIds: [Array.from(tokenIds)] });
|
|
54
62
|
}
|
|
55
63
|
async getNextNonce(address) {
|
|
56
64
|
const addressBytes = typeof address === "string" ? this.addressToBytes(address) : address;
|
|
@@ -60,10 +68,10 @@ var FastsetClient = class {
|
|
|
60
68
|
addressToBytes(address) {
|
|
61
69
|
try {
|
|
62
70
|
const decoded = bech32.bech32m.decode(address);
|
|
63
|
-
return
|
|
71
|
+
return new Uint8Array(bech32.bech32m.fromWords(decoded.words));
|
|
64
72
|
} catch {
|
|
65
73
|
const decoded = bech32.bech32.decode(address);
|
|
66
|
-
return
|
|
74
|
+
return new Uint8Array(bech32.bech32.fromWords(decoded.words));
|
|
67
75
|
}
|
|
68
76
|
}
|
|
69
77
|
static decodeBech32Address(address) {
|
|
@@ -87,6 +95,61 @@ var getConfiguredFastsetClient = (config, chain2) => {
|
|
|
87
95
|
return new FastsetClient(proxyUrl);
|
|
88
96
|
};
|
|
89
97
|
|
|
98
|
+
// src/tokens/fastset.ts
|
|
99
|
+
var FastsetTokens = [
|
|
100
|
+
{
|
|
101
|
+
chain: "fastset",
|
|
102
|
+
identifier: "08413efc81f99e5b8e03b852b3756674083110c6b65e6b7836b39a26e3908d3c",
|
|
103
|
+
name: "Ethereum",
|
|
104
|
+
symbol: "ETH",
|
|
105
|
+
decimals: 18,
|
|
106
|
+
logoUrl: "https://assets.coingecko.com/coins/images/279/small/ethereum.png",
|
|
107
|
+
amount: 0n
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
chain: "fastset",
|
|
111
|
+
identifier: "0ee63eaa3ff9bf6e1c84a70133c5461e6e06d3787ed93200b924a6b82f0f35ff",
|
|
112
|
+
name: "Bitcoin",
|
|
113
|
+
symbol: "BTC",
|
|
114
|
+
decimals: 8,
|
|
115
|
+
logoUrl: "https://assets.coingecko.com/coins/images/1/small/bitcoin.png",
|
|
116
|
+
amount: 0n
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
chain: "fastset",
|
|
120
|
+
identifier: "b69f0d3a4d7609367bd893ee3191e48b3047f2c4ccd21728c2441bcc2154f70c",
|
|
121
|
+
name: "Solana",
|
|
122
|
+
symbol: "SOL",
|
|
123
|
+
decimals: 9,
|
|
124
|
+
logoUrl: "https://assets.coingecko.com/coins/images/4128/small/solana.png",
|
|
125
|
+
amount: 0n
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
chain: "fastset",
|
|
129
|
+
identifier: "c83166ed4e5e3ca88f7b2cf0ce2d310fa8c4d2ee2fc90d741f7b2040279b2687",
|
|
130
|
+
name: "USD Coin",
|
|
131
|
+
symbol: "USDC",
|
|
132
|
+
decimals: 6,
|
|
133
|
+
logoUrl: "https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png",
|
|
134
|
+
amount: 0n
|
|
135
|
+
}
|
|
136
|
+
];
|
|
137
|
+
|
|
138
|
+
// src/tokens.ts
|
|
139
|
+
var KnownTokens = {
|
|
140
|
+
mainnet: FastsetTokens,
|
|
141
|
+
testnet: FastsetTokens,
|
|
142
|
+
devnet: FastsetTokens
|
|
143
|
+
};
|
|
144
|
+
var findKnownTokenBySymbol = (symbol, env = "mainnet") => {
|
|
145
|
+
const tokens = KnownTokens[env] || [];
|
|
146
|
+
return tokens.find((token) => token.symbol === symbol) || null;
|
|
147
|
+
};
|
|
148
|
+
var findKnownTokenById = (id2, env = "mainnet") => {
|
|
149
|
+
const tokens = KnownTokens[env] || [];
|
|
150
|
+
return tokens.find((token) => token.identifier === id2) || null;
|
|
151
|
+
};
|
|
152
|
+
|
|
90
153
|
// src/WarpFastsetDataLoader.ts
|
|
91
154
|
var WarpFastsetDataLoader = class {
|
|
92
155
|
constructor(config, chain2) {
|
|
@@ -95,15 +158,14 @@ var WarpFastsetDataLoader = class {
|
|
|
95
158
|
this.client = getConfiguredFastsetClient(config, chain2);
|
|
96
159
|
}
|
|
97
160
|
async getAccount(address) {
|
|
98
|
-
const addressBytes =
|
|
161
|
+
const addressBytes = FastsetClient.decodeBech32Address(address);
|
|
99
162
|
const accountInfo = await this.client.getAccountInfo(addressBytes);
|
|
100
163
|
return { chain: this.chain.name, address, balance: BigInt(parseInt(accountInfo.result?.balance ?? "0", 16)) };
|
|
101
164
|
}
|
|
102
165
|
async getAccountAssets(address) {
|
|
103
|
-
const addressBytes =
|
|
166
|
+
const addressBytes = FastsetClient.decodeBech32Address(address);
|
|
104
167
|
const accountInfo = await this.client.getAccountInfo(addressBytes);
|
|
105
168
|
const assets = [];
|
|
106
|
-
console.log("accountInfo", accountInfo);
|
|
107
169
|
const balance = BigInt(parseInt(accountInfo.result?.balance ?? "0", 16));
|
|
108
170
|
if (balance > 0n) {
|
|
109
171
|
assets.push({ ...this.chain.nativeToken, amount: balance });
|
|
@@ -111,15 +173,15 @@ var WarpFastsetDataLoader = class {
|
|
|
111
173
|
for (const [tokenId, tokenBalance] of accountInfo.result?.token_balance ?? []) {
|
|
112
174
|
const amount = BigInt(parseInt(tokenBalance, 16));
|
|
113
175
|
if (amount > 0n) {
|
|
114
|
-
const
|
|
115
|
-
|
|
176
|
+
const assetInfo = await this.getAssetInfo(Buffer.from(tokenId).toString("hex"));
|
|
177
|
+
if (!assetInfo) continue;
|
|
116
178
|
assets.push({
|
|
117
179
|
chain: this.chain.name,
|
|
118
180
|
identifier: Buffer.from(tokenId).toString("hex"),
|
|
119
|
-
symbol:
|
|
120
|
-
name:
|
|
121
|
-
decimals:
|
|
122
|
-
logoUrl:
|
|
181
|
+
symbol: assetInfo.symbol,
|
|
182
|
+
name: assetInfo.name,
|
|
183
|
+
decimals: assetInfo.decimals,
|
|
184
|
+
logoUrl: assetInfo.logoUrl || "",
|
|
123
185
|
amount
|
|
124
186
|
});
|
|
125
187
|
}
|
|
@@ -130,18 +192,18 @@ var WarpFastsetDataLoader = class {
|
|
|
130
192
|
if (identifier === this.chain.nativeToken.identifier) {
|
|
131
193
|
return this.chain.nativeToken;
|
|
132
194
|
}
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
195
|
+
const assetInfo = await this.getAssetInfo(identifier);
|
|
196
|
+
if (!assetInfo) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
137
199
|
return {
|
|
138
200
|
chain: this.chain.name,
|
|
139
201
|
identifier,
|
|
140
|
-
symbol:
|
|
141
|
-
name:
|
|
142
|
-
decimals:
|
|
143
|
-
logoUrl:
|
|
144
|
-
amount:
|
|
202
|
+
symbol: assetInfo.symbol,
|
|
203
|
+
name: assetInfo.name,
|
|
204
|
+
decimals: assetInfo.decimals,
|
|
205
|
+
logoUrl: assetInfo.logoUrl || null,
|
|
206
|
+
amount: 0n
|
|
145
207
|
};
|
|
146
208
|
}
|
|
147
209
|
async getAction(identifier, awaitCompleted = false) {
|
|
@@ -150,18 +212,24 @@ var WarpFastsetDataLoader = class {
|
|
|
150
212
|
async getAccountActions(address, options) {
|
|
151
213
|
return [];
|
|
152
214
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
215
|
+
async getAssetInfo(identifier) {
|
|
216
|
+
const knownToken = findKnownTokenById(identifier, this.config.env) || findKnownTokenBySymbol(identifier, this.config.env);
|
|
217
|
+
if (knownToken) {
|
|
218
|
+
return knownToken;
|
|
219
|
+
}
|
|
220
|
+
const tokenInfo = await this.client.getTokenInfo(hexToUint8Array(identifier));
|
|
221
|
+
const metadata = tokenInfo.result?.requested_token_metadata[0]?.[1];
|
|
222
|
+
if (metadata) {
|
|
223
|
+
return {
|
|
224
|
+
chain: this.chain.name,
|
|
225
|
+
identifier,
|
|
226
|
+
symbol: metadata.token_name,
|
|
227
|
+
name: metadata.token_name,
|
|
228
|
+
decimals: metadata.decimals,
|
|
229
|
+
logoUrl: null
|
|
230
|
+
};
|
|
164
231
|
}
|
|
232
|
+
return null;
|
|
165
233
|
}
|
|
166
234
|
};
|
|
167
235
|
|
|
@@ -220,8 +288,8 @@ var WarpFastsetExplorer = class {
|
|
|
220
288
|
getAccountUrl(address) {
|
|
221
289
|
return `${this.explorerUrl}/account/${address}`;
|
|
222
290
|
}
|
|
223
|
-
getTransactionUrl(
|
|
224
|
-
return `${this.explorerUrl}/transaction/${
|
|
291
|
+
getTransactionUrl(hash2) {
|
|
292
|
+
return `${this.explorerUrl}/transaction/${hash2}`;
|
|
225
293
|
}
|
|
226
294
|
getAssetUrl(identifier) {
|
|
227
295
|
return `${this.explorerUrl}/asset/${identifier}`;
|
|
@@ -444,15 +512,549 @@ import {
|
|
|
444
512
|
getWarpWalletPrivateKeyFromConfig
|
|
445
513
|
} from "@vleap/warps";
|
|
446
514
|
|
|
447
|
-
//
|
|
448
|
-
|
|
515
|
+
// ../../node_modules/@noble/ed25519/index.js
|
|
516
|
+
var ed25519_exports = {};
|
|
517
|
+
__export(ed25519_exports, {
|
|
518
|
+
Point: () => Point,
|
|
519
|
+
etc: () => etc,
|
|
520
|
+
getPublicKey: () => getPublicKey,
|
|
521
|
+
getPublicKeyAsync: () => getPublicKeyAsync,
|
|
522
|
+
hash: () => hash,
|
|
523
|
+
hashes: () => hashes,
|
|
524
|
+
keygen: () => keygen,
|
|
525
|
+
keygenAsync: () => keygenAsync,
|
|
526
|
+
sign: () => sign,
|
|
527
|
+
signAsync: () => signAsync,
|
|
528
|
+
utils: () => utils,
|
|
529
|
+
verify: () => verify,
|
|
530
|
+
verifyAsync: () => verifyAsync
|
|
531
|
+
});
|
|
532
|
+
var ed25519_CURVE = {
|
|
533
|
+
p: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,
|
|
534
|
+
n: 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,
|
|
535
|
+
h: 8n,
|
|
536
|
+
a: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,
|
|
537
|
+
d: 0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,
|
|
538
|
+
Gx: 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,
|
|
539
|
+
Gy: 0x6666666666666666666666666666666666666666666666666666666666666658n
|
|
540
|
+
};
|
|
541
|
+
var { p: P, n: N, Gx, Gy, a: _a, d: _d, h } = ed25519_CURVE;
|
|
542
|
+
var L = 32;
|
|
543
|
+
var L2 = 64;
|
|
544
|
+
var captureTrace = (...args) => {
|
|
545
|
+
if ("captureStackTrace" in Error && typeof Error.captureStackTrace === "function") {
|
|
546
|
+
Error.captureStackTrace(...args);
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
var err = (message = "") => {
|
|
550
|
+
const e = new Error(message);
|
|
551
|
+
captureTrace(e, err);
|
|
552
|
+
throw e;
|
|
553
|
+
};
|
|
554
|
+
var isBig = (n) => typeof n === "bigint";
|
|
555
|
+
var isStr = (s) => typeof s === "string";
|
|
556
|
+
var isBytes = (a) => a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
557
|
+
var abytes = (value, length, title = "") => {
|
|
558
|
+
const bytes = isBytes(value);
|
|
559
|
+
const len = value?.length;
|
|
560
|
+
const needsLen = length !== void 0;
|
|
561
|
+
if (!bytes || needsLen && len !== length) {
|
|
562
|
+
const prefix = title && `"${title}" `;
|
|
563
|
+
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
564
|
+
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
565
|
+
err(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
566
|
+
}
|
|
567
|
+
return value;
|
|
568
|
+
};
|
|
569
|
+
var u8n = (len) => new Uint8Array(len);
|
|
570
|
+
var u8fr = (buf) => Uint8Array.from(buf);
|
|
571
|
+
var padh = (n, pad) => n.toString(16).padStart(pad, "0");
|
|
572
|
+
var bytesToHex = (b) => Array.from(abytes(b)).map((e) => padh(e, 2)).join("");
|
|
573
|
+
var C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
574
|
+
var _ch = (ch) => {
|
|
575
|
+
if (ch >= C._0 && ch <= C._9)
|
|
576
|
+
return ch - C._0;
|
|
577
|
+
if (ch >= C.A && ch <= C.F)
|
|
578
|
+
return ch - (C.A - 10);
|
|
579
|
+
if (ch >= C.a && ch <= C.f)
|
|
580
|
+
return ch - (C.a - 10);
|
|
581
|
+
return;
|
|
582
|
+
};
|
|
583
|
+
var hexToBytes = (hex) => {
|
|
584
|
+
const e = "hex invalid";
|
|
585
|
+
if (!isStr(hex))
|
|
586
|
+
return err(e);
|
|
587
|
+
const hl = hex.length;
|
|
588
|
+
const al = hl / 2;
|
|
589
|
+
if (hl % 2)
|
|
590
|
+
return err(e);
|
|
591
|
+
const array = u8n(al);
|
|
592
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
593
|
+
const n1 = _ch(hex.charCodeAt(hi));
|
|
594
|
+
const n2 = _ch(hex.charCodeAt(hi + 1));
|
|
595
|
+
if (n1 === void 0 || n2 === void 0)
|
|
596
|
+
return err(e);
|
|
597
|
+
array[ai] = n1 * 16 + n2;
|
|
598
|
+
}
|
|
599
|
+
return array;
|
|
600
|
+
};
|
|
601
|
+
var cr = () => globalThis?.crypto;
|
|
602
|
+
var subtle = () => cr()?.subtle ?? err("crypto.subtle must be defined, consider polyfill");
|
|
603
|
+
var concatBytes = (...arrs) => {
|
|
604
|
+
const r = u8n(arrs.reduce((sum, a) => sum + abytes(a).length, 0));
|
|
605
|
+
let pad = 0;
|
|
606
|
+
arrs.forEach((a) => {
|
|
607
|
+
r.set(a, pad);
|
|
608
|
+
pad += a.length;
|
|
609
|
+
});
|
|
610
|
+
return r;
|
|
611
|
+
};
|
|
612
|
+
var randomBytes = (len = L) => {
|
|
613
|
+
const c = cr();
|
|
614
|
+
return c.getRandomValues(u8n(len));
|
|
615
|
+
};
|
|
616
|
+
var big = BigInt;
|
|
617
|
+
var assertRange = (n, min, max, msg = "bad number: out of range") => isBig(n) && min <= n && n < max ? n : err(msg);
|
|
618
|
+
var M = (a, b = P) => {
|
|
619
|
+
const r = a % b;
|
|
620
|
+
return r >= 0n ? r : b + r;
|
|
621
|
+
};
|
|
622
|
+
var modN = (a) => M(a, N);
|
|
623
|
+
var invert = (num, md) => {
|
|
624
|
+
if (num === 0n || md <= 0n)
|
|
625
|
+
err("no inverse n=" + num + " mod=" + md);
|
|
626
|
+
let a = M(num, md), b = md, x = 0n, y = 1n, u = 1n, v = 0n;
|
|
627
|
+
while (a !== 0n) {
|
|
628
|
+
const q = b / a, r = b % a;
|
|
629
|
+
const m = x - u * q, n = y - v * q;
|
|
630
|
+
b = a, a = r, x = u, y = v, u = m, v = n;
|
|
631
|
+
}
|
|
632
|
+
return b === 1n ? M(x, md) : err("no inverse");
|
|
633
|
+
};
|
|
634
|
+
var callHash = (name2) => {
|
|
635
|
+
const fn = hashes[name2];
|
|
636
|
+
if (typeof fn !== "function")
|
|
637
|
+
err("hashes." + name2 + " not set");
|
|
638
|
+
return fn;
|
|
639
|
+
};
|
|
640
|
+
var hash = (msg) => callHash("sha512")(msg);
|
|
641
|
+
var apoint = (p) => p instanceof Point ? p : err("Point expected");
|
|
642
|
+
var B256 = 2n ** 256n;
|
|
643
|
+
var _Point = class _Point {
|
|
644
|
+
constructor(X, Y, Z, T) {
|
|
645
|
+
__publicField(this, "X");
|
|
646
|
+
__publicField(this, "Y");
|
|
647
|
+
__publicField(this, "Z");
|
|
648
|
+
__publicField(this, "T");
|
|
649
|
+
const max = B256;
|
|
650
|
+
this.X = assertRange(X, 0n, max);
|
|
651
|
+
this.Y = assertRange(Y, 0n, max);
|
|
652
|
+
this.Z = assertRange(Z, 1n, max);
|
|
653
|
+
this.T = assertRange(T, 0n, max);
|
|
654
|
+
Object.freeze(this);
|
|
655
|
+
}
|
|
656
|
+
static CURVE() {
|
|
657
|
+
return ed25519_CURVE;
|
|
658
|
+
}
|
|
659
|
+
static fromAffine(p) {
|
|
660
|
+
return new _Point(p.x, p.y, 1n, M(p.x * p.y));
|
|
661
|
+
}
|
|
662
|
+
/** RFC8032 5.1.3: Uint8Array to Point. */
|
|
663
|
+
static fromBytes(hex, zip215 = false) {
|
|
664
|
+
const d = _d;
|
|
665
|
+
const normed = u8fr(abytes(hex, L));
|
|
666
|
+
const lastByte = hex[31];
|
|
667
|
+
normed[31] = lastByte & ~128;
|
|
668
|
+
const y = bytesToNumLE(normed);
|
|
669
|
+
const max = zip215 ? B256 : P;
|
|
670
|
+
assertRange(y, 0n, max);
|
|
671
|
+
const y2 = M(y * y);
|
|
672
|
+
const u = M(y2 - 1n);
|
|
673
|
+
const v = M(d * y2 + 1n);
|
|
674
|
+
let { isValid, value: x } = uvRatio(u, v);
|
|
675
|
+
if (!isValid)
|
|
676
|
+
err("bad point: y not sqrt");
|
|
677
|
+
const isXOdd = (x & 1n) === 1n;
|
|
678
|
+
const isLastByteOdd = (lastByte & 128) !== 0;
|
|
679
|
+
if (!zip215 && x === 0n && isLastByteOdd)
|
|
680
|
+
err("bad point: x==0, isLastByteOdd");
|
|
681
|
+
if (isLastByteOdd !== isXOdd)
|
|
682
|
+
x = M(-x);
|
|
683
|
+
return new _Point(x, y, 1n, M(x * y));
|
|
684
|
+
}
|
|
685
|
+
static fromHex(hex, zip215) {
|
|
686
|
+
return _Point.fromBytes(hexToBytes(hex), zip215);
|
|
687
|
+
}
|
|
688
|
+
get x() {
|
|
689
|
+
return this.toAffine().x;
|
|
690
|
+
}
|
|
691
|
+
get y() {
|
|
692
|
+
return this.toAffine().y;
|
|
693
|
+
}
|
|
694
|
+
/** Checks if the point is valid and on-curve. */
|
|
695
|
+
assertValidity() {
|
|
696
|
+
const a = _a;
|
|
697
|
+
const d = _d;
|
|
698
|
+
const p = this;
|
|
699
|
+
if (p.is0())
|
|
700
|
+
return err("bad point: ZERO");
|
|
701
|
+
const { X, Y, Z, T } = p;
|
|
702
|
+
const X2 = M(X * X);
|
|
703
|
+
const Y2 = M(Y * Y);
|
|
704
|
+
const Z2 = M(Z * Z);
|
|
705
|
+
const Z4 = M(Z2 * Z2);
|
|
706
|
+
const aX2 = M(X2 * a);
|
|
707
|
+
const left = M(Z2 * M(aX2 + Y2));
|
|
708
|
+
const right = M(Z4 + M(d * M(X2 * Y2)));
|
|
709
|
+
if (left !== right)
|
|
710
|
+
return err("bad point: equation left != right (1)");
|
|
711
|
+
const XY = M(X * Y);
|
|
712
|
+
const ZT = M(Z * T);
|
|
713
|
+
if (XY !== ZT)
|
|
714
|
+
return err("bad point: equation left != right (2)");
|
|
715
|
+
return this;
|
|
716
|
+
}
|
|
717
|
+
/** Equality check: compare points P&Q. */
|
|
718
|
+
equals(other) {
|
|
719
|
+
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
720
|
+
const { X: X2, Y: Y2, Z: Z2 } = apoint(other);
|
|
721
|
+
const X1Z2 = M(X1 * Z2);
|
|
722
|
+
const X2Z1 = M(X2 * Z1);
|
|
723
|
+
const Y1Z2 = M(Y1 * Z2);
|
|
724
|
+
const Y2Z1 = M(Y2 * Z1);
|
|
725
|
+
return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
|
|
726
|
+
}
|
|
727
|
+
is0() {
|
|
728
|
+
return this.equals(I);
|
|
729
|
+
}
|
|
730
|
+
/** Flip point over y coordinate. */
|
|
731
|
+
negate() {
|
|
732
|
+
return new _Point(M(-this.X), this.Y, this.Z, M(-this.T));
|
|
733
|
+
}
|
|
734
|
+
/** Point doubling. Complete formula. Cost: `4M + 4S + 1*a + 6add + 1*2`. */
|
|
735
|
+
double() {
|
|
736
|
+
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
737
|
+
const a = _a;
|
|
738
|
+
const A = M(X1 * X1);
|
|
739
|
+
const B = M(Y1 * Y1);
|
|
740
|
+
const C2 = M(2n * M(Z1 * Z1));
|
|
741
|
+
const D = M(a * A);
|
|
742
|
+
const x1y1 = X1 + Y1;
|
|
743
|
+
const E = M(M(x1y1 * x1y1) - A - B);
|
|
744
|
+
const G2 = D + B;
|
|
745
|
+
const F = G2 - C2;
|
|
746
|
+
const H = D - B;
|
|
747
|
+
const X3 = M(E * F);
|
|
748
|
+
const Y3 = M(G2 * H);
|
|
749
|
+
const T3 = M(E * H);
|
|
750
|
+
const Z3 = M(F * G2);
|
|
751
|
+
return new _Point(X3, Y3, Z3, T3);
|
|
752
|
+
}
|
|
753
|
+
/** Point addition. Complete formula. Cost: `8M + 1*k + 8add + 1*2`. */
|
|
754
|
+
add(other) {
|
|
755
|
+
const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
|
|
756
|
+
const { X: X2, Y: Y2, Z: Z2, T: T2 } = apoint(other);
|
|
757
|
+
const a = _a;
|
|
758
|
+
const d = _d;
|
|
759
|
+
const A = M(X1 * X2);
|
|
760
|
+
const B = M(Y1 * Y2);
|
|
761
|
+
const C2 = M(T1 * d * T2);
|
|
762
|
+
const D = M(Z1 * Z2);
|
|
763
|
+
const E = M((X1 + Y1) * (X2 + Y2) - A - B);
|
|
764
|
+
const F = M(D - C2);
|
|
765
|
+
const G2 = M(D + C2);
|
|
766
|
+
const H = M(B - a * A);
|
|
767
|
+
const X3 = M(E * F);
|
|
768
|
+
const Y3 = M(G2 * H);
|
|
769
|
+
const T3 = M(E * H);
|
|
770
|
+
const Z3 = M(F * G2);
|
|
771
|
+
return new _Point(X3, Y3, Z3, T3);
|
|
772
|
+
}
|
|
773
|
+
subtract(other) {
|
|
774
|
+
return this.add(apoint(other).negate());
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
|
|
778
|
+
* Uses {@link wNAF} for base point.
|
|
779
|
+
* Uses fake point to mitigate side-channel leakage.
|
|
780
|
+
* @param n scalar by which point is multiplied
|
|
781
|
+
* @param safe safe mode guards against timing attacks; unsafe mode is faster
|
|
782
|
+
*/
|
|
783
|
+
multiply(n, safe = true) {
|
|
784
|
+
if (!safe && (n === 0n || this.is0()))
|
|
785
|
+
return I;
|
|
786
|
+
assertRange(n, 1n, N);
|
|
787
|
+
if (n === 1n)
|
|
788
|
+
return this;
|
|
789
|
+
if (this.equals(G))
|
|
790
|
+
return wNAF(n).p;
|
|
791
|
+
let p = I;
|
|
792
|
+
let f = G;
|
|
793
|
+
for (let d = this; n > 0n; d = d.double(), n >>= 1n) {
|
|
794
|
+
if (n & 1n)
|
|
795
|
+
p = p.add(d);
|
|
796
|
+
else if (safe)
|
|
797
|
+
f = f.add(d);
|
|
798
|
+
}
|
|
799
|
+
return p;
|
|
800
|
+
}
|
|
801
|
+
multiplyUnsafe(scalar) {
|
|
802
|
+
return this.multiply(scalar, false);
|
|
803
|
+
}
|
|
804
|
+
/** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
|
|
805
|
+
toAffine() {
|
|
806
|
+
const { X, Y, Z } = this;
|
|
807
|
+
if (this.equals(I))
|
|
808
|
+
return { x: 0n, y: 1n };
|
|
809
|
+
const iz = invert(Z, P);
|
|
810
|
+
if (M(Z * iz) !== 1n)
|
|
811
|
+
err("invalid inverse");
|
|
812
|
+
const x = M(X * iz);
|
|
813
|
+
const y = M(Y * iz);
|
|
814
|
+
return { x, y };
|
|
815
|
+
}
|
|
816
|
+
toBytes() {
|
|
817
|
+
const { x, y } = this.assertValidity().toAffine();
|
|
818
|
+
const b = numTo32bLE(y);
|
|
819
|
+
b[31] |= x & 1n ? 128 : 0;
|
|
820
|
+
return b;
|
|
821
|
+
}
|
|
822
|
+
toHex() {
|
|
823
|
+
return bytesToHex(this.toBytes());
|
|
824
|
+
}
|
|
825
|
+
clearCofactor() {
|
|
826
|
+
return this.multiply(big(h), false);
|
|
827
|
+
}
|
|
828
|
+
isSmallOrder() {
|
|
829
|
+
return this.clearCofactor().is0();
|
|
830
|
+
}
|
|
831
|
+
isTorsionFree() {
|
|
832
|
+
let p = this.multiply(N / 2n, false).double();
|
|
833
|
+
if (N % 2n)
|
|
834
|
+
p = p.add(this);
|
|
835
|
+
return p.is0();
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
__publicField(_Point, "BASE");
|
|
839
|
+
__publicField(_Point, "ZERO");
|
|
840
|
+
var Point = _Point;
|
|
841
|
+
var G = new Point(Gx, Gy, 1n, M(Gx * Gy));
|
|
842
|
+
var I = new Point(0n, 1n, 1n, 0n);
|
|
843
|
+
Point.BASE = G;
|
|
844
|
+
Point.ZERO = I;
|
|
845
|
+
var numTo32bLE = (num) => hexToBytes(padh(assertRange(num, 0n, B256), L2)).reverse();
|
|
846
|
+
var bytesToNumLE = (b) => big("0x" + bytesToHex(u8fr(abytes(b)).reverse()));
|
|
847
|
+
var pow2 = (x, power) => {
|
|
848
|
+
let r = x;
|
|
849
|
+
while (power-- > 0n) {
|
|
850
|
+
r *= r;
|
|
851
|
+
r %= P;
|
|
852
|
+
}
|
|
853
|
+
return r;
|
|
854
|
+
};
|
|
855
|
+
var pow_2_252_3 = (x) => {
|
|
856
|
+
const x2 = x * x % P;
|
|
857
|
+
const b2 = x2 * x % P;
|
|
858
|
+
const b4 = pow2(b2, 2n) * b2 % P;
|
|
859
|
+
const b5 = pow2(b4, 1n) * x % P;
|
|
860
|
+
const b10 = pow2(b5, 5n) * b5 % P;
|
|
861
|
+
const b20 = pow2(b10, 10n) * b10 % P;
|
|
862
|
+
const b40 = pow2(b20, 20n) * b20 % P;
|
|
863
|
+
const b80 = pow2(b40, 40n) * b40 % P;
|
|
864
|
+
const b160 = pow2(b80, 80n) * b80 % P;
|
|
865
|
+
const b240 = pow2(b160, 80n) * b80 % P;
|
|
866
|
+
const b250 = pow2(b240, 10n) * b10 % P;
|
|
867
|
+
const pow_p_5_8 = pow2(b250, 2n) * x % P;
|
|
868
|
+
return { pow_p_5_8, b2 };
|
|
869
|
+
};
|
|
870
|
+
var RM1 = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n;
|
|
871
|
+
var uvRatio = (u, v) => {
|
|
872
|
+
const v3 = M(v * v * v);
|
|
873
|
+
const v7 = M(v3 * v3 * v);
|
|
874
|
+
const pow = pow_2_252_3(u * v7).pow_p_5_8;
|
|
875
|
+
let x = M(u * v3 * pow);
|
|
876
|
+
const vx2 = M(v * x * x);
|
|
877
|
+
const root1 = x;
|
|
878
|
+
const root2 = M(x * RM1);
|
|
879
|
+
const useRoot1 = vx2 === u;
|
|
880
|
+
const useRoot2 = vx2 === M(-u);
|
|
881
|
+
const noRoot = vx2 === M(-u * RM1);
|
|
882
|
+
if (useRoot1)
|
|
883
|
+
x = root1;
|
|
884
|
+
if (useRoot2 || noRoot)
|
|
885
|
+
x = root2;
|
|
886
|
+
if ((M(x) & 1n) === 1n)
|
|
887
|
+
x = M(-x);
|
|
888
|
+
return { isValid: useRoot1 || useRoot2, value: x };
|
|
889
|
+
};
|
|
890
|
+
var modL_LE = (hash2) => modN(bytesToNumLE(hash2));
|
|
891
|
+
var sha512a = (...m) => hashes.sha512Async(concatBytes(...m));
|
|
892
|
+
var sha512s = (...m) => callHash("sha512")(concatBytes(...m));
|
|
893
|
+
var hash2extK = (hashed) => {
|
|
894
|
+
const head = hashed.slice(0, L);
|
|
895
|
+
head[0] &= 248;
|
|
896
|
+
head[31] &= 127;
|
|
897
|
+
head[31] |= 64;
|
|
898
|
+
const prefix = hashed.slice(L, L2);
|
|
899
|
+
const scalar = modL_LE(head);
|
|
900
|
+
const point = G.multiply(scalar);
|
|
901
|
+
const pointBytes = point.toBytes();
|
|
902
|
+
return { head, prefix, scalar, point, pointBytes };
|
|
903
|
+
};
|
|
904
|
+
var getExtendedPublicKeyAsync = (secretKey) => sha512a(abytes(secretKey, L)).then(hash2extK);
|
|
905
|
+
var getExtendedPublicKey = (secretKey) => hash2extK(sha512s(abytes(secretKey, L)));
|
|
906
|
+
var getPublicKeyAsync = (secretKey) => getExtendedPublicKeyAsync(secretKey).then((p) => p.pointBytes);
|
|
907
|
+
var getPublicKey = (priv) => getExtendedPublicKey(priv).pointBytes;
|
|
908
|
+
var hashFinishA = (res) => sha512a(res.hashable).then(res.finish);
|
|
909
|
+
var hashFinishS = (res) => res.finish(sha512s(res.hashable));
|
|
910
|
+
var _sign = (e, rBytes, msg) => {
|
|
911
|
+
const { pointBytes: P2, scalar: s } = e;
|
|
912
|
+
const r = modL_LE(rBytes);
|
|
913
|
+
const R = G.multiply(r).toBytes();
|
|
914
|
+
const hashable = concatBytes(R, P2, msg);
|
|
915
|
+
const finish = (hashed) => {
|
|
916
|
+
const S = modN(r + modL_LE(hashed) * s);
|
|
917
|
+
return abytes(concatBytes(R, numTo32bLE(S)), L2);
|
|
918
|
+
};
|
|
919
|
+
return { hashable, finish };
|
|
920
|
+
};
|
|
921
|
+
var signAsync = async (message, secretKey) => {
|
|
922
|
+
const m = abytes(message);
|
|
923
|
+
const e = await getExtendedPublicKeyAsync(secretKey);
|
|
924
|
+
const rBytes = await sha512a(e.prefix, m);
|
|
925
|
+
return hashFinishA(_sign(e, rBytes, m));
|
|
926
|
+
};
|
|
927
|
+
var sign = (message, secretKey) => {
|
|
928
|
+
const m = abytes(message);
|
|
929
|
+
const e = getExtendedPublicKey(secretKey);
|
|
930
|
+
const rBytes = sha512s(e.prefix, m);
|
|
931
|
+
return hashFinishS(_sign(e, rBytes, m));
|
|
932
|
+
};
|
|
933
|
+
var defaultVerifyOpts = { zip215: true };
|
|
934
|
+
var _verify = (sig, msg, pub, opts = defaultVerifyOpts) => {
|
|
935
|
+
sig = abytes(sig, L2);
|
|
936
|
+
msg = abytes(msg);
|
|
937
|
+
pub = abytes(pub, L);
|
|
938
|
+
const { zip215 } = opts;
|
|
939
|
+
let A;
|
|
940
|
+
let R;
|
|
941
|
+
let s;
|
|
942
|
+
let SB;
|
|
943
|
+
let hashable = Uint8Array.of();
|
|
944
|
+
try {
|
|
945
|
+
A = Point.fromBytes(pub, zip215);
|
|
946
|
+
R = Point.fromBytes(sig.slice(0, L), zip215);
|
|
947
|
+
s = bytesToNumLE(sig.slice(L, L2));
|
|
948
|
+
SB = G.multiply(s, false);
|
|
949
|
+
hashable = concatBytes(R.toBytes(), A.toBytes(), msg);
|
|
950
|
+
} catch (error) {
|
|
951
|
+
}
|
|
952
|
+
const finish = (hashed) => {
|
|
953
|
+
if (SB == null)
|
|
954
|
+
return false;
|
|
955
|
+
if (!zip215 && A.isSmallOrder())
|
|
956
|
+
return false;
|
|
957
|
+
const k = modL_LE(hashed);
|
|
958
|
+
const RkA = R.add(A.multiply(k, false));
|
|
959
|
+
return RkA.add(SB.negate()).clearCofactor().is0();
|
|
960
|
+
};
|
|
961
|
+
return { hashable, finish };
|
|
962
|
+
};
|
|
963
|
+
var verifyAsync = async (signature, message, publicKey, opts = defaultVerifyOpts) => hashFinishA(_verify(signature, message, publicKey, opts));
|
|
964
|
+
var verify = (signature, message, publicKey, opts = defaultVerifyOpts) => hashFinishS(_verify(signature, message, publicKey, opts));
|
|
965
|
+
var etc = {
|
|
966
|
+
bytesToHex,
|
|
967
|
+
hexToBytes,
|
|
968
|
+
concatBytes,
|
|
969
|
+
mod: M,
|
|
970
|
+
invert,
|
|
971
|
+
randomBytes
|
|
972
|
+
};
|
|
973
|
+
var hashes = {
|
|
974
|
+
sha512Async: async (message) => {
|
|
975
|
+
const s = subtle();
|
|
976
|
+
const m = concatBytes(message);
|
|
977
|
+
return u8n(await s.digest("SHA-512", m.buffer));
|
|
978
|
+
},
|
|
979
|
+
sha512: void 0
|
|
980
|
+
};
|
|
981
|
+
var randomSecretKey = (seed = randomBytes(L)) => seed;
|
|
982
|
+
var keygen = (seed) => {
|
|
983
|
+
const secretKey = randomSecretKey(seed);
|
|
984
|
+
const publicKey = getPublicKey(secretKey);
|
|
985
|
+
return { secretKey, publicKey };
|
|
986
|
+
};
|
|
987
|
+
var keygenAsync = async (seed) => {
|
|
988
|
+
const secretKey = randomSecretKey(seed);
|
|
989
|
+
const publicKey = await getPublicKeyAsync(secretKey);
|
|
990
|
+
return { secretKey, publicKey };
|
|
991
|
+
};
|
|
992
|
+
var utils = {
|
|
993
|
+
getExtendedPublicKeyAsync,
|
|
994
|
+
getExtendedPublicKey,
|
|
995
|
+
randomSecretKey
|
|
996
|
+
};
|
|
997
|
+
var W = 8;
|
|
998
|
+
var scalarBits = 256;
|
|
999
|
+
var pwindows = Math.ceil(scalarBits / W) + 1;
|
|
1000
|
+
var pwindowSize = 2 ** (W - 1);
|
|
1001
|
+
var precompute = () => {
|
|
1002
|
+
const points = [];
|
|
1003
|
+
let p = G;
|
|
1004
|
+
let b = p;
|
|
1005
|
+
for (let w = 0; w < pwindows; w++) {
|
|
1006
|
+
b = p;
|
|
1007
|
+
points.push(b);
|
|
1008
|
+
for (let i = 1; i < pwindowSize; i++) {
|
|
1009
|
+
b = b.add(p);
|
|
1010
|
+
points.push(b);
|
|
1011
|
+
}
|
|
1012
|
+
p = b.double();
|
|
1013
|
+
}
|
|
1014
|
+
return points;
|
|
1015
|
+
};
|
|
1016
|
+
var Gpows = void 0;
|
|
1017
|
+
var ctneg = (cnd, p) => {
|
|
1018
|
+
const n = p.negate();
|
|
1019
|
+
return cnd ? n : p;
|
|
1020
|
+
};
|
|
1021
|
+
var wNAF = (n) => {
|
|
1022
|
+
const comp = Gpows || (Gpows = precompute());
|
|
1023
|
+
let p = I;
|
|
1024
|
+
let f = G;
|
|
1025
|
+
const pow_2_w = 2 ** W;
|
|
1026
|
+
const maxNum = pow_2_w;
|
|
1027
|
+
const mask = big(pow_2_w - 1);
|
|
1028
|
+
const shiftBy = big(W);
|
|
1029
|
+
for (let w = 0; w < pwindows; w++) {
|
|
1030
|
+
let wbits = Number(n & mask);
|
|
1031
|
+
n >>= shiftBy;
|
|
1032
|
+
if (wbits > pwindowSize) {
|
|
1033
|
+
wbits -= maxNum;
|
|
1034
|
+
n += 1n;
|
|
1035
|
+
}
|
|
1036
|
+
const off = w * pwindowSize;
|
|
1037
|
+
const offF = off;
|
|
1038
|
+
const offP = off + Math.abs(wbits) - 1;
|
|
1039
|
+
const isEven = w % 2 !== 0;
|
|
1040
|
+
const isNeg = wbits < 0;
|
|
1041
|
+
if (wbits === 0) {
|
|
1042
|
+
f = f.add(ctneg(isEven, comp[offF]));
|
|
1043
|
+
} else {
|
|
1044
|
+
p = p.add(ctneg(isNeg, comp[offP]));
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
if (n !== 0n)
|
|
1048
|
+
err("invalid wnaf");
|
|
1049
|
+
return { p, f };
|
|
1050
|
+
};
|
|
449
1051
|
|
|
450
1052
|
// ../../node_modules/@noble/hashes/esm/utils.js
|
|
451
|
-
function
|
|
1053
|
+
function isBytes2(a) {
|
|
452
1054
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
453
1055
|
}
|
|
454
|
-
function
|
|
455
|
-
if (!
|
|
1056
|
+
function abytes2(b, ...lengths) {
|
|
1057
|
+
if (!isBytes2(b))
|
|
456
1058
|
throw new Error("Uint8Array expected");
|
|
457
1059
|
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
458
1060
|
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
@@ -464,7 +1066,7 @@ function aexists(instance, checkFinished = true) {
|
|
|
464
1066
|
throw new Error("Hash#digest() has already been called");
|
|
465
1067
|
}
|
|
466
1068
|
function aoutput(out, instance) {
|
|
467
|
-
|
|
1069
|
+
abytes2(out);
|
|
468
1070
|
const min = instance.outputLen;
|
|
469
1071
|
if (out.length < min) {
|
|
470
1072
|
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
@@ -486,7 +1088,7 @@ function utf8ToBytes(str) {
|
|
|
486
1088
|
function toBytes(data) {
|
|
487
1089
|
if (typeof data === "string")
|
|
488
1090
|
data = utf8ToBytes(data);
|
|
489
|
-
|
|
1091
|
+
abytes2(data);
|
|
490
1092
|
return data;
|
|
491
1093
|
}
|
|
492
1094
|
var Hash = class {
|
|
@@ -508,9 +1110,9 @@ function setBigUint64(view, byteOffset, value, isLE) {
|
|
|
508
1110
|
const _u32_max = BigInt(4294967295);
|
|
509
1111
|
const wh = Number(value >> _32n2 & _u32_max);
|
|
510
1112
|
const wl = Number(value & _u32_max);
|
|
511
|
-
const
|
|
1113
|
+
const h2 = isLE ? 4 : 0;
|
|
512
1114
|
const l = isLE ? 0 : 4;
|
|
513
|
-
view.setUint32(byteOffset +
|
|
1115
|
+
view.setUint32(byteOffset + h2, wh, isLE);
|
|
514
1116
|
view.setUint32(byteOffset + l, wl, isLE);
|
|
515
1117
|
}
|
|
516
1118
|
var HashMD = class extends Hash {
|
|
@@ -530,7 +1132,7 @@ var HashMD = class extends Hash {
|
|
|
530
1132
|
update(data) {
|
|
531
1133
|
aexists(this);
|
|
532
1134
|
data = toBytes(data);
|
|
533
|
-
|
|
1135
|
+
abytes2(data);
|
|
534
1136
|
const { view, buffer, blockLen } = this;
|
|
535
1137
|
const len = data.length;
|
|
536
1138
|
for (let pos = 0; pos < len; ) {
|
|
@@ -635,17 +1237,17 @@ function split(lst, le = false) {
|
|
|
635
1237
|
let Ah = new Uint32Array(len);
|
|
636
1238
|
let Al = new Uint32Array(len);
|
|
637
1239
|
for (let i = 0; i < len; i++) {
|
|
638
|
-
const { h, l } = fromBig(lst[i], le);
|
|
639
|
-
[Ah[i], Al[i]] = [
|
|
1240
|
+
const { h: h2, l } = fromBig(lst[i], le);
|
|
1241
|
+
[Ah[i], Al[i]] = [h2, l];
|
|
640
1242
|
}
|
|
641
1243
|
return [Ah, Al];
|
|
642
1244
|
}
|
|
643
|
-
var shrSH = (
|
|
644
|
-
var shrSL = (
|
|
645
|
-
var rotrSH = (
|
|
646
|
-
var rotrSL = (
|
|
647
|
-
var rotrBH = (
|
|
648
|
-
var rotrBL = (
|
|
1245
|
+
var shrSH = (h2, _l, s) => h2 >>> s;
|
|
1246
|
+
var shrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
|
|
1247
|
+
var rotrSH = (h2, l, s) => h2 >>> s | l << 32 - s;
|
|
1248
|
+
var rotrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
|
|
1249
|
+
var rotrBH = (h2, l, s) => h2 << 64 - s | l >>> s - 32;
|
|
1250
|
+
var rotrBL = (h2, l, s) => h2 >>> s - 32 | l << 64 - s;
|
|
649
1251
|
function add(Ah, Al, Bh, Bl) {
|
|
650
1252
|
const l = (Al >>> 0) + (Bl >>> 0);
|
|
651
1253
|
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
@@ -861,10 +1463,10 @@ var sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
|
|
|
861
1463
|
var sha5122 = sha512;
|
|
862
1464
|
|
|
863
1465
|
// src/sdk/ed25519-setup.ts
|
|
864
|
-
|
|
1466
|
+
hashes.sha512 = sha5122;
|
|
865
1467
|
|
|
866
1468
|
// ../../node_modules/@scure/base/lib/esm/index.js
|
|
867
|
-
function
|
|
1469
|
+
function isBytes3(a) {
|
|
868
1470
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
869
1471
|
}
|
|
870
1472
|
function isArrayOf(isString, arr) {
|
|
@@ -1002,7 +1604,7 @@ function radix(num) {
|
|
|
1002
1604
|
const _256 = 2 ** 8;
|
|
1003
1605
|
return {
|
|
1004
1606
|
encode: (bytes) => {
|
|
1005
|
-
if (!
|
|
1607
|
+
if (!isBytes3(bytes))
|
|
1006
1608
|
throw new Error("radix.encode input should be Uint8Array");
|
|
1007
1609
|
return convertRadix(Array.from(bytes), _256, num);
|
|
1008
1610
|
},
|
|
@@ -2211,9 +2813,6 @@ var WarpFastsetWallet = class {
|
|
|
2211
2813
|
this.config = config;
|
|
2212
2814
|
this.chain = chain2;
|
|
2213
2815
|
this.client = getConfiguredFastsetClient(this.config, this.chain);
|
|
2214
|
-
const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
|
|
2215
|
-
if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
|
|
2216
|
-
this.privateKey = privateKey;
|
|
2217
2816
|
}
|
|
2218
2817
|
async signTransaction(tx) {
|
|
2219
2818
|
const msg = Transaction.serialize(tx);
|
|
@@ -2222,14 +2821,18 @@ var WarpFastsetWallet = class {
|
|
|
2222
2821
|
const dataToSign = new Uint8Array(prefix.length + msgBytes.length);
|
|
2223
2822
|
dataToSign.set(prefix, 0);
|
|
2224
2823
|
dataToSign.set(msgBytes, prefix.length);
|
|
2225
|
-
const
|
|
2226
|
-
|
|
2824
|
+
const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
|
|
2825
|
+
if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
|
|
2826
|
+
const privateKeyBytes = hexToUint8Array(privateKey);
|
|
2827
|
+
const signature = ed25519_exports.sign(dataToSign, privateKeyBytes);
|
|
2227
2828
|
return { ...tx, signature };
|
|
2228
2829
|
}
|
|
2229
2830
|
async signMessage(message) {
|
|
2230
2831
|
const messageBytes = stringToUint8Array(message);
|
|
2231
|
-
const
|
|
2232
|
-
|
|
2832
|
+
const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
|
|
2833
|
+
if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
|
|
2834
|
+
const privateKeyBytes = hexToUint8Array(privateKey);
|
|
2835
|
+
const signature = ed25519_exports.sign(messageBytes, privateKeyBytes);
|
|
2233
2836
|
return uint8ArrayToHex(signature);
|
|
2234
2837
|
}
|
|
2235
2838
|
async sendTransaction(tx) {
|
|
@@ -2238,19 +2841,18 @@ var WarpFastsetWallet = class {
|
|
|
2238
2841
|
const proxyUrl = getProviderUrl2(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
2239
2842
|
const response = await this.client.request(proxyUrl, "set_proxy_submitTransaction", submitTxReq);
|
|
2240
2843
|
if (response.error) throw new Error(`JSON-RPC error ${response.error.code}: ${response.error.message}`);
|
|
2241
|
-
console.log("submitTransaction response", response.result);
|
|
2242
2844
|
return "TODO";
|
|
2243
2845
|
}
|
|
2244
2846
|
create(mnemonic) {
|
|
2245
2847
|
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
2246
2848
|
const privateKey = seed.slice(0, 32);
|
|
2247
|
-
const publicKey =
|
|
2849
|
+
const publicKey = ed25519_exports.getPublicKey(privateKey);
|
|
2248
2850
|
const address = FastsetClient.encodeBech32Address(publicKey);
|
|
2249
2851
|
return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic };
|
|
2250
2852
|
}
|
|
2251
2853
|
generate() {
|
|
2252
|
-
const privateKey =
|
|
2253
|
-
const publicKey =
|
|
2854
|
+
const privateKey = ed25519_exports.utils.randomPrivateKey();
|
|
2855
|
+
const publicKey = ed25519_exports.getPublicKey(privateKey);
|
|
2254
2856
|
const address = FastsetClient.encodeBech32Address(publicKey);
|
|
2255
2857
|
return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic: null };
|
|
2256
2858
|
}
|
|
@@ -2330,6 +2932,9 @@ export {
|
|
|
2330
2932
|
};
|
|
2331
2933
|
/*! Bundled license information:
|
|
2332
2934
|
|
|
2935
|
+
@noble/ed25519/index.js:
|
|
2936
|
+
(*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
|
|
2937
|
+
|
|
2333
2938
|
@noble/hashes/esm/utils.js:
|
|
2334
2939
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
2335
2940
|
|