@vleap/warps-adapter-fastset 0.1.0-beta.46 → 0.1.0-beta.48
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 +12 -6
- package/dist/index.d.ts +12 -6
- package/dist/index.js +258 -610
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +253 -610
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
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 name in all)
|
|
5
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
|
-
};
|
|
7
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
4
|
|
|
9
5
|
// src/main.ts
|
|
@@ -20,9 +16,6 @@ function uint8ArrayToHex(uint8Array) {
|
|
|
20
16
|
function hexToUint8Array(hex) {
|
|
21
17
|
return new Uint8Array(Buffer.from(hex, "hex"));
|
|
22
18
|
}
|
|
23
|
-
function stringToUint8Array(str) {
|
|
24
|
-
return new Uint8Array(Buffer.from(str, "utf8"));
|
|
25
|
-
}
|
|
26
19
|
|
|
27
20
|
// src/helpers/general.ts
|
|
28
21
|
import { getProviderConfig } from "@vleap/warps";
|
|
@@ -1705,8 +1698,8 @@ var WarpFastsetExplorer = class {
|
|
|
1705
1698
|
getAccountUrl(address) {
|
|
1706
1699
|
return `${this.explorerUrl}/account/${address}`;
|
|
1707
1700
|
}
|
|
1708
|
-
getTransactionUrl(
|
|
1709
|
-
return `${this.explorerUrl}/txs/${HEX_PREFIX}${
|
|
1701
|
+
getTransactionUrl(hash) {
|
|
1702
|
+
return `${this.explorerUrl}/txs/${HEX_PREFIX}${hash}`;
|
|
1710
1703
|
}
|
|
1711
1704
|
getAssetUrl(identifier) {
|
|
1712
1705
|
return `${this.explorerUrl}/asset/${HEX_PREFIX}${identifier}`;
|
|
@@ -1936,555 +1929,24 @@ var WarpFastsetOutput = class {
|
|
|
1936
1929
|
};
|
|
1937
1930
|
|
|
1938
1931
|
// src/WarpFastsetWallet.ts
|
|
1939
|
-
import * as bip39 from "@scure/bip39";
|
|
1940
1932
|
import {
|
|
1941
|
-
|
|
1942
|
-
getWarpWalletPrivateKeyFromConfig
|
|
1933
|
+
initializeWalletCache
|
|
1943
1934
|
} from "@vleap/warps";
|
|
1944
1935
|
|
|
1945
|
-
//
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
hash: () => hash,
|
|
1953
|
-
hashes: () => hashes,
|
|
1954
|
-
keygen: () => keygen,
|
|
1955
|
-
keygenAsync: () => keygenAsync,
|
|
1956
|
-
sign: () => sign,
|
|
1957
|
-
signAsync: () => signAsync,
|
|
1958
|
-
utils: () => utils,
|
|
1959
|
-
verify: () => verify,
|
|
1960
|
-
verifyAsync: () => verifyAsync
|
|
1961
|
-
});
|
|
1962
|
-
var ed25519_CURVE = {
|
|
1963
|
-
p: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,
|
|
1964
|
-
n: 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,
|
|
1965
|
-
h: 8n,
|
|
1966
|
-
a: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,
|
|
1967
|
-
d: 0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,
|
|
1968
|
-
Gx: 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,
|
|
1969
|
-
Gy: 0x6666666666666666666666666666666666666666666666666666666666666658n
|
|
1970
|
-
};
|
|
1971
|
-
var { p: P, n: N, Gx, Gy, a: _a, d: _d, h } = ed25519_CURVE;
|
|
1972
|
-
var L = 32;
|
|
1973
|
-
var L2 = 64;
|
|
1974
|
-
var captureTrace = (...args) => {
|
|
1975
|
-
if ("captureStackTrace" in Error && typeof Error.captureStackTrace === "function") {
|
|
1976
|
-
Error.captureStackTrace(...args);
|
|
1977
|
-
}
|
|
1978
|
-
};
|
|
1979
|
-
var err = (message = "") => {
|
|
1980
|
-
const e = new Error(message);
|
|
1981
|
-
captureTrace(e, err);
|
|
1982
|
-
throw e;
|
|
1983
|
-
};
|
|
1984
|
-
var isBig = (n) => typeof n === "bigint";
|
|
1985
|
-
var isStr = (s) => typeof s === "string";
|
|
1986
|
-
var isBytes2 = (a) => a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
1987
|
-
var abytes = (value, length, title = "") => {
|
|
1988
|
-
const bytes = isBytes2(value);
|
|
1989
|
-
const len = value?.length;
|
|
1990
|
-
const needsLen = length !== void 0;
|
|
1991
|
-
if (!bytes || needsLen && len !== length) {
|
|
1992
|
-
const prefix = title && `"${title}" `;
|
|
1993
|
-
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
1994
|
-
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
1995
|
-
err(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
1996
|
-
}
|
|
1997
|
-
return value;
|
|
1998
|
-
};
|
|
1999
|
-
var u8n = (len) => new Uint8Array(len);
|
|
2000
|
-
var u8fr = (buf) => Uint8Array.from(buf);
|
|
2001
|
-
var padh = (n, pad) => n.toString(16).padStart(pad, "0");
|
|
2002
|
-
var bytesToHex = (b) => Array.from(abytes(b)).map((e) => padh(e, 2)).join("");
|
|
2003
|
-
var C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
2004
|
-
var _ch = (ch) => {
|
|
2005
|
-
if (ch >= C._0 && ch <= C._9)
|
|
2006
|
-
return ch - C._0;
|
|
2007
|
-
if (ch >= C.A && ch <= C.F)
|
|
2008
|
-
return ch - (C.A - 10);
|
|
2009
|
-
if (ch >= C.a && ch <= C.f)
|
|
2010
|
-
return ch - (C.a - 10);
|
|
2011
|
-
return;
|
|
2012
|
-
};
|
|
2013
|
-
var hexToBytes = (hex) => {
|
|
2014
|
-
const e = "hex invalid";
|
|
2015
|
-
if (!isStr(hex))
|
|
2016
|
-
return err(e);
|
|
2017
|
-
const hl = hex.length;
|
|
2018
|
-
const al = hl / 2;
|
|
2019
|
-
if (hl % 2)
|
|
2020
|
-
return err(e);
|
|
2021
|
-
const array = u8n(al);
|
|
2022
|
-
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
2023
|
-
const n1 = _ch(hex.charCodeAt(hi));
|
|
2024
|
-
const n2 = _ch(hex.charCodeAt(hi + 1));
|
|
2025
|
-
if (n1 === void 0 || n2 === void 0)
|
|
2026
|
-
return err(e);
|
|
2027
|
-
array[ai] = n1 * 16 + n2;
|
|
2028
|
-
}
|
|
2029
|
-
return array;
|
|
2030
|
-
};
|
|
2031
|
-
var cr = () => globalThis?.crypto;
|
|
2032
|
-
var subtle = () => cr()?.subtle ?? err("crypto.subtle must be defined, consider polyfill");
|
|
2033
|
-
var concatBytes = (...arrs) => {
|
|
2034
|
-
const r = u8n(arrs.reduce((sum, a) => sum + abytes(a).length, 0));
|
|
2035
|
-
let pad = 0;
|
|
2036
|
-
arrs.forEach((a) => {
|
|
2037
|
-
r.set(a, pad);
|
|
2038
|
-
pad += a.length;
|
|
2039
|
-
});
|
|
2040
|
-
return r;
|
|
2041
|
-
};
|
|
2042
|
-
var randomBytes = (len = L) => {
|
|
2043
|
-
const c = cr();
|
|
2044
|
-
return c.getRandomValues(u8n(len));
|
|
2045
|
-
};
|
|
2046
|
-
var big = BigInt;
|
|
2047
|
-
var assertRange = (n, min, max, msg = "bad number: out of range") => isBig(n) && min <= n && n < max ? n : err(msg);
|
|
2048
|
-
var M = (a, b = P) => {
|
|
2049
|
-
const r = a % b;
|
|
2050
|
-
return r >= 0n ? r : b + r;
|
|
2051
|
-
};
|
|
2052
|
-
var modN = (a) => M(a, N);
|
|
2053
|
-
var invert = (num, md) => {
|
|
2054
|
-
if (num === 0n || md <= 0n)
|
|
2055
|
-
err("no inverse n=" + num + " mod=" + md);
|
|
2056
|
-
let a = M(num, md), b = md, x = 0n, y = 1n, u = 1n, v = 0n;
|
|
2057
|
-
while (a !== 0n) {
|
|
2058
|
-
const q = b / a, r = b % a;
|
|
2059
|
-
const m = x - u * q, n = y - v * q;
|
|
2060
|
-
b = a, a = r, x = u, y = v, u = m, v = n;
|
|
2061
|
-
}
|
|
2062
|
-
return b === 1n ? M(x, md) : err("no inverse");
|
|
2063
|
-
};
|
|
2064
|
-
var callHash = (name) => {
|
|
2065
|
-
const fn = hashes[name];
|
|
2066
|
-
if (typeof fn !== "function")
|
|
2067
|
-
err("hashes." + name + " not set");
|
|
2068
|
-
return fn;
|
|
2069
|
-
};
|
|
2070
|
-
var hash = (msg) => callHash("sha512")(msg);
|
|
2071
|
-
var apoint = (p) => p instanceof Point ? p : err("Point expected");
|
|
2072
|
-
var B256 = 2n ** 256n;
|
|
2073
|
-
var _Point = class _Point {
|
|
2074
|
-
constructor(X, Y, Z, T) {
|
|
2075
|
-
__publicField(this, "X");
|
|
2076
|
-
__publicField(this, "Y");
|
|
2077
|
-
__publicField(this, "Z");
|
|
2078
|
-
__publicField(this, "T");
|
|
2079
|
-
const max = B256;
|
|
2080
|
-
this.X = assertRange(X, 0n, max);
|
|
2081
|
-
this.Y = assertRange(Y, 0n, max);
|
|
2082
|
-
this.Z = assertRange(Z, 1n, max);
|
|
2083
|
-
this.T = assertRange(T, 0n, max);
|
|
2084
|
-
Object.freeze(this);
|
|
2085
|
-
}
|
|
2086
|
-
static CURVE() {
|
|
2087
|
-
return ed25519_CURVE;
|
|
2088
|
-
}
|
|
2089
|
-
static fromAffine(p) {
|
|
2090
|
-
return new _Point(p.x, p.y, 1n, M(p.x * p.y));
|
|
2091
|
-
}
|
|
2092
|
-
/** RFC8032 5.1.3: Uint8Array to Point. */
|
|
2093
|
-
static fromBytes(hex, zip215 = false) {
|
|
2094
|
-
const d = _d;
|
|
2095
|
-
const normed = u8fr(abytes(hex, L));
|
|
2096
|
-
const lastByte = hex[31];
|
|
2097
|
-
normed[31] = lastByte & ~128;
|
|
2098
|
-
const y = bytesToNumLE(normed);
|
|
2099
|
-
const max = zip215 ? B256 : P;
|
|
2100
|
-
assertRange(y, 0n, max);
|
|
2101
|
-
const y2 = M(y * y);
|
|
2102
|
-
const u = M(y2 - 1n);
|
|
2103
|
-
const v = M(d * y2 + 1n);
|
|
2104
|
-
let { isValid, value: x } = uvRatio(u, v);
|
|
2105
|
-
if (!isValid)
|
|
2106
|
-
err("bad point: y not sqrt");
|
|
2107
|
-
const isXOdd = (x & 1n) === 1n;
|
|
2108
|
-
const isLastByteOdd = (lastByte & 128) !== 0;
|
|
2109
|
-
if (!zip215 && x === 0n && isLastByteOdd)
|
|
2110
|
-
err("bad point: x==0, isLastByteOdd");
|
|
2111
|
-
if (isLastByteOdd !== isXOdd)
|
|
2112
|
-
x = M(-x);
|
|
2113
|
-
return new _Point(x, y, 1n, M(x * y));
|
|
2114
|
-
}
|
|
2115
|
-
static fromHex(hex, zip215) {
|
|
2116
|
-
return _Point.fromBytes(hexToBytes(hex), zip215);
|
|
2117
|
-
}
|
|
2118
|
-
get x() {
|
|
2119
|
-
return this.toAffine().x;
|
|
2120
|
-
}
|
|
2121
|
-
get y() {
|
|
2122
|
-
return this.toAffine().y;
|
|
2123
|
-
}
|
|
2124
|
-
/** Checks if the point is valid and on-curve. */
|
|
2125
|
-
assertValidity() {
|
|
2126
|
-
const a = _a;
|
|
2127
|
-
const d = _d;
|
|
2128
|
-
const p = this;
|
|
2129
|
-
if (p.is0())
|
|
2130
|
-
return err("bad point: ZERO");
|
|
2131
|
-
const { X, Y, Z, T } = p;
|
|
2132
|
-
const X2 = M(X * X);
|
|
2133
|
-
const Y2 = M(Y * Y);
|
|
2134
|
-
const Z2 = M(Z * Z);
|
|
2135
|
-
const Z4 = M(Z2 * Z2);
|
|
2136
|
-
const aX2 = M(X2 * a);
|
|
2137
|
-
const left = M(Z2 * M(aX2 + Y2));
|
|
2138
|
-
const right = M(Z4 + M(d * M(X2 * Y2)));
|
|
2139
|
-
if (left !== right)
|
|
2140
|
-
return err("bad point: equation left != right (1)");
|
|
2141
|
-
const XY = M(X * Y);
|
|
2142
|
-
const ZT = M(Z * T);
|
|
2143
|
-
if (XY !== ZT)
|
|
2144
|
-
return err("bad point: equation left != right (2)");
|
|
2145
|
-
return this;
|
|
2146
|
-
}
|
|
2147
|
-
/** Equality check: compare points P&Q. */
|
|
2148
|
-
equals(other) {
|
|
2149
|
-
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
2150
|
-
const { X: X2, Y: Y2, Z: Z2 } = apoint(other);
|
|
2151
|
-
const X1Z2 = M(X1 * Z2);
|
|
2152
|
-
const X2Z1 = M(X2 * Z1);
|
|
2153
|
-
const Y1Z2 = M(Y1 * Z2);
|
|
2154
|
-
const Y2Z1 = M(Y2 * Z1);
|
|
2155
|
-
return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
|
|
2156
|
-
}
|
|
2157
|
-
is0() {
|
|
2158
|
-
return this.equals(I);
|
|
2159
|
-
}
|
|
2160
|
-
/** Flip point over y coordinate. */
|
|
2161
|
-
negate() {
|
|
2162
|
-
return new _Point(M(-this.X), this.Y, this.Z, M(-this.T));
|
|
2163
|
-
}
|
|
2164
|
-
/** Point doubling. Complete formula. Cost: `4M + 4S + 1*a + 6add + 1*2`. */
|
|
2165
|
-
double() {
|
|
2166
|
-
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
2167
|
-
const a = _a;
|
|
2168
|
-
const A = M(X1 * X1);
|
|
2169
|
-
const B = M(Y1 * Y1);
|
|
2170
|
-
const C2 = M(2n * M(Z1 * Z1));
|
|
2171
|
-
const D = M(a * A);
|
|
2172
|
-
const x1y1 = X1 + Y1;
|
|
2173
|
-
const E = M(M(x1y1 * x1y1) - A - B);
|
|
2174
|
-
const G2 = D + B;
|
|
2175
|
-
const F = G2 - C2;
|
|
2176
|
-
const H = D - B;
|
|
2177
|
-
const X3 = M(E * F);
|
|
2178
|
-
const Y3 = M(G2 * H);
|
|
2179
|
-
const T3 = M(E * H);
|
|
2180
|
-
const Z3 = M(F * G2);
|
|
2181
|
-
return new _Point(X3, Y3, Z3, T3);
|
|
2182
|
-
}
|
|
2183
|
-
/** Point addition. Complete formula. Cost: `8M + 1*k + 8add + 1*2`. */
|
|
2184
|
-
add(other) {
|
|
2185
|
-
const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
|
|
2186
|
-
const { X: X2, Y: Y2, Z: Z2, T: T2 } = apoint(other);
|
|
2187
|
-
const a = _a;
|
|
2188
|
-
const d = _d;
|
|
2189
|
-
const A = M(X1 * X2);
|
|
2190
|
-
const B = M(Y1 * Y2);
|
|
2191
|
-
const C2 = M(T1 * d * T2);
|
|
2192
|
-
const D = M(Z1 * Z2);
|
|
2193
|
-
const E = M((X1 + Y1) * (X2 + Y2) - A - B);
|
|
2194
|
-
const F = M(D - C2);
|
|
2195
|
-
const G2 = M(D + C2);
|
|
2196
|
-
const H = M(B - a * A);
|
|
2197
|
-
const X3 = M(E * F);
|
|
2198
|
-
const Y3 = M(G2 * H);
|
|
2199
|
-
const T3 = M(E * H);
|
|
2200
|
-
const Z3 = M(F * G2);
|
|
2201
|
-
return new _Point(X3, Y3, Z3, T3);
|
|
2202
|
-
}
|
|
2203
|
-
subtract(other) {
|
|
2204
|
-
return this.add(apoint(other).negate());
|
|
2205
|
-
}
|
|
2206
|
-
/**
|
|
2207
|
-
* Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
|
|
2208
|
-
* Uses {@link wNAF} for base point.
|
|
2209
|
-
* Uses fake point to mitigate side-channel leakage.
|
|
2210
|
-
* @param n scalar by which point is multiplied
|
|
2211
|
-
* @param safe safe mode guards against timing attacks; unsafe mode is faster
|
|
2212
|
-
*/
|
|
2213
|
-
multiply(n, safe = true) {
|
|
2214
|
-
if (!safe && (n === 0n || this.is0()))
|
|
2215
|
-
return I;
|
|
2216
|
-
assertRange(n, 1n, N);
|
|
2217
|
-
if (n === 1n)
|
|
2218
|
-
return this;
|
|
2219
|
-
if (this.equals(G))
|
|
2220
|
-
return wNAF(n).p;
|
|
2221
|
-
let p = I;
|
|
2222
|
-
let f = G;
|
|
2223
|
-
for (let d = this; n > 0n; d = d.double(), n >>= 1n) {
|
|
2224
|
-
if (n & 1n)
|
|
2225
|
-
p = p.add(d);
|
|
2226
|
-
else if (safe)
|
|
2227
|
-
f = f.add(d);
|
|
2228
|
-
}
|
|
2229
|
-
return p;
|
|
2230
|
-
}
|
|
2231
|
-
multiplyUnsafe(scalar) {
|
|
2232
|
-
return this.multiply(scalar, false);
|
|
2233
|
-
}
|
|
2234
|
-
/** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
|
|
2235
|
-
toAffine() {
|
|
2236
|
-
const { X, Y, Z } = this;
|
|
2237
|
-
if (this.equals(I))
|
|
2238
|
-
return { x: 0n, y: 1n };
|
|
2239
|
-
const iz = invert(Z, P);
|
|
2240
|
-
if (M(Z * iz) !== 1n)
|
|
2241
|
-
err("invalid inverse");
|
|
2242
|
-
const x = M(X * iz);
|
|
2243
|
-
const y = M(Y * iz);
|
|
2244
|
-
return { x, y };
|
|
2245
|
-
}
|
|
2246
|
-
toBytes() {
|
|
2247
|
-
const { x, y } = this.assertValidity().toAffine();
|
|
2248
|
-
const b = numTo32bLE(y);
|
|
2249
|
-
b[31] |= x & 1n ? 128 : 0;
|
|
2250
|
-
return b;
|
|
2251
|
-
}
|
|
2252
|
-
toHex() {
|
|
2253
|
-
return bytesToHex(this.toBytes());
|
|
2254
|
-
}
|
|
2255
|
-
clearCofactor() {
|
|
2256
|
-
return this.multiply(big(h), false);
|
|
2257
|
-
}
|
|
2258
|
-
isSmallOrder() {
|
|
2259
|
-
return this.clearCofactor().is0();
|
|
2260
|
-
}
|
|
2261
|
-
isTorsionFree() {
|
|
2262
|
-
let p = this.multiply(N / 2n, false).double();
|
|
2263
|
-
if (N % 2n)
|
|
2264
|
-
p = p.add(this);
|
|
2265
|
-
return p.is0();
|
|
2266
|
-
}
|
|
2267
|
-
};
|
|
2268
|
-
__publicField(_Point, "BASE");
|
|
2269
|
-
__publicField(_Point, "ZERO");
|
|
2270
|
-
var Point = _Point;
|
|
2271
|
-
var G = new Point(Gx, Gy, 1n, M(Gx * Gy));
|
|
2272
|
-
var I = new Point(0n, 1n, 1n, 0n);
|
|
2273
|
-
Point.BASE = G;
|
|
2274
|
-
Point.ZERO = I;
|
|
2275
|
-
var numTo32bLE = (num) => hexToBytes(padh(assertRange(num, 0n, B256), L2)).reverse();
|
|
2276
|
-
var bytesToNumLE = (b) => big("0x" + bytesToHex(u8fr(abytes(b)).reverse()));
|
|
2277
|
-
var pow2 = (x, power) => {
|
|
2278
|
-
let r = x;
|
|
2279
|
-
while (power-- > 0n) {
|
|
2280
|
-
r *= r;
|
|
2281
|
-
r %= P;
|
|
2282
|
-
}
|
|
2283
|
-
return r;
|
|
2284
|
-
};
|
|
2285
|
-
var pow_2_252_3 = (x) => {
|
|
2286
|
-
const x2 = x * x % P;
|
|
2287
|
-
const b2 = x2 * x % P;
|
|
2288
|
-
const b4 = pow2(b2, 2n) * b2 % P;
|
|
2289
|
-
const b5 = pow2(b4, 1n) * x % P;
|
|
2290
|
-
const b10 = pow2(b5, 5n) * b5 % P;
|
|
2291
|
-
const b20 = pow2(b10, 10n) * b10 % P;
|
|
2292
|
-
const b40 = pow2(b20, 20n) * b20 % P;
|
|
2293
|
-
const b80 = pow2(b40, 40n) * b40 % P;
|
|
2294
|
-
const b160 = pow2(b80, 80n) * b80 % P;
|
|
2295
|
-
const b240 = pow2(b160, 80n) * b80 % P;
|
|
2296
|
-
const b250 = pow2(b240, 10n) * b10 % P;
|
|
2297
|
-
const pow_p_5_8 = pow2(b250, 2n) * x % P;
|
|
2298
|
-
return { pow_p_5_8, b2 };
|
|
2299
|
-
};
|
|
2300
|
-
var RM1 = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n;
|
|
2301
|
-
var uvRatio = (u, v) => {
|
|
2302
|
-
const v3 = M(v * v * v);
|
|
2303
|
-
const v7 = M(v3 * v3 * v);
|
|
2304
|
-
const pow = pow_2_252_3(u * v7).pow_p_5_8;
|
|
2305
|
-
let x = M(u * v3 * pow);
|
|
2306
|
-
const vx2 = M(v * x * x);
|
|
2307
|
-
const root1 = x;
|
|
2308
|
-
const root2 = M(x * RM1);
|
|
2309
|
-
const useRoot1 = vx2 === u;
|
|
2310
|
-
const useRoot2 = vx2 === M(-u);
|
|
2311
|
-
const noRoot = vx2 === M(-u * RM1);
|
|
2312
|
-
if (useRoot1)
|
|
2313
|
-
x = root1;
|
|
2314
|
-
if (useRoot2 || noRoot)
|
|
2315
|
-
x = root2;
|
|
2316
|
-
if ((M(x) & 1n) === 1n)
|
|
2317
|
-
x = M(-x);
|
|
2318
|
-
return { isValid: useRoot1 || useRoot2, value: x };
|
|
2319
|
-
};
|
|
2320
|
-
var modL_LE = (hash2) => modN(bytesToNumLE(hash2));
|
|
2321
|
-
var sha512a = (...m) => hashes.sha512Async(concatBytes(...m));
|
|
2322
|
-
var sha512s = (...m) => callHash("sha512")(concatBytes(...m));
|
|
2323
|
-
var hash2extK = (hashed) => {
|
|
2324
|
-
const head = hashed.slice(0, L);
|
|
2325
|
-
head[0] &= 248;
|
|
2326
|
-
head[31] &= 127;
|
|
2327
|
-
head[31] |= 64;
|
|
2328
|
-
const prefix = hashed.slice(L, L2);
|
|
2329
|
-
const scalar = modL_LE(head);
|
|
2330
|
-
const point = G.multiply(scalar);
|
|
2331
|
-
const pointBytes = point.toBytes();
|
|
2332
|
-
return { head, prefix, scalar, point, pointBytes };
|
|
2333
|
-
};
|
|
2334
|
-
var getExtendedPublicKeyAsync = (secretKey) => sha512a(abytes(secretKey, L)).then(hash2extK);
|
|
2335
|
-
var getExtendedPublicKey = (secretKey) => hash2extK(sha512s(abytes(secretKey, L)));
|
|
2336
|
-
var getPublicKeyAsync = (secretKey) => getExtendedPublicKeyAsync(secretKey).then((p) => p.pointBytes);
|
|
2337
|
-
var getPublicKey = (priv) => getExtendedPublicKey(priv).pointBytes;
|
|
2338
|
-
var hashFinishA = (res) => sha512a(res.hashable).then(res.finish);
|
|
2339
|
-
var hashFinishS = (res) => res.finish(sha512s(res.hashable));
|
|
2340
|
-
var _sign = (e, rBytes, msg) => {
|
|
2341
|
-
const { pointBytes: P2, scalar: s } = e;
|
|
2342
|
-
const r = modL_LE(rBytes);
|
|
2343
|
-
const R = G.multiply(r).toBytes();
|
|
2344
|
-
const hashable = concatBytes(R, P2, msg);
|
|
2345
|
-
const finish = (hashed) => {
|
|
2346
|
-
const S = modN(r + modL_LE(hashed) * s);
|
|
2347
|
-
return abytes(concatBytes(R, numTo32bLE(S)), L2);
|
|
2348
|
-
};
|
|
2349
|
-
return { hashable, finish };
|
|
2350
|
-
};
|
|
2351
|
-
var signAsync = async (message, secretKey) => {
|
|
2352
|
-
const m = abytes(message);
|
|
2353
|
-
const e = await getExtendedPublicKeyAsync(secretKey);
|
|
2354
|
-
const rBytes = await sha512a(e.prefix, m);
|
|
2355
|
-
return hashFinishA(_sign(e, rBytes, m));
|
|
2356
|
-
};
|
|
2357
|
-
var sign = (message, secretKey) => {
|
|
2358
|
-
const m = abytes(message);
|
|
2359
|
-
const e = getExtendedPublicKey(secretKey);
|
|
2360
|
-
const rBytes = sha512s(e.prefix, m);
|
|
2361
|
-
return hashFinishS(_sign(e, rBytes, m));
|
|
2362
|
-
};
|
|
2363
|
-
var defaultVerifyOpts = { zip215: true };
|
|
2364
|
-
var _verify = (sig, msg, pub, opts = defaultVerifyOpts) => {
|
|
2365
|
-
sig = abytes(sig, L2);
|
|
2366
|
-
msg = abytes(msg);
|
|
2367
|
-
pub = abytes(pub, L);
|
|
2368
|
-
const { zip215 } = opts;
|
|
2369
|
-
let A;
|
|
2370
|
-
let R;
|
|
2371
|
-
let s;
|
|
2372
|
-
let SB;
|
|
2373
|
-
let hashable = Uint8Array.of();
|
|
2374
|
-
try {
|
|
2375
|
-
A = Point.fromBytes(pub, zip215);
|
|
2376
|
-
R = Point.fromBytes(sig.slice(0, L), zip215);
|
|
2377
|
-
s = bytesToNumLE(sig.slice(L, L2));
|
|
2378
|
-
SB = G.multiply(s, false);
|
|
2379
|
-
hashable = concatBytes(R.toBytes(), A.toBytes(), msg);
|
|
2380
|
-
} catch (error) {
|
|
2381
|
-
}
|
|
2382
|
-
const finish = (hashed) => {
|
|
2383
|
-
if (SB == null)
|
|
2384
|
-
return false;
|
|
2385
|
-
if (!zip215 && A.isSmallOrder())
|
|
2386
|
-
return false;
|
|
2387
|
-
const k = modL_LE(hashed);
|
|
2388
|
-
const RkA = R.add(A.multiply(k, false));
|
|
2389
|
-
return RkA.add(SB.negate()).clearCofactor().is0();
|
|
2390
|
-
};
|
|
2391
|
-
return { hashable, finish };
|
|
2392
|
-
};
|
|
2393
|
-
var verifyAsync = async (signature, message, publicKey, opts = defaultVerifyOpts) => hashFinishA(_verify(signature, message, publicKey, opts));
|
|
2394
|
-
var verify = (signature, message, publicKey, opts = defaultVerifyOpts) => hashFinishS(_verify(signature, message, publicKey, opts));
|
|
2395
|
-
var etc = {
|
|
2396
|
-
bytesToHex,
|
|
2397
|
-
hexToBytes,
|
|
2398
|
-
concatBytes,
|
|
2399
|
-
mod: M,
|
|
2400
|
-
invert,
|
|
2401
|
-
randomBytes
|
|
2402
|
-
};
|
|
2403
|
-
var hashes = {
|
|
2404
|
-
sha512Async: async (message) => {
|
|
2405
|
-
const s = subtle();
|
|
2406
|
-
const m = concatBytes(message);
|
|
2407
|
-
return u8n(await s.digest("SHA-512", m.buffer));
|
|
2408
|
-
},
|
|
2409
|
-
sha512: void 0
|
|
2410
|
-
};
|
|
2411
|
-
var randomSecretKey = (seed = randomBytes(L)) => seed;
|
|
2412
|
-
var keygen = (seed) => {
|
|
2413
|
-
const secretKey = randomSecretKey(seed);
|
|
2414
|
-
const publicKey = getPublicKey(secretKey);
|
|
2415
|
-
return { secretKey, publicKey };
|
|
2416
|
-
};
|
|
2417
|
-
var keygenAsync = async (seed) => {
|
|
2418
|
-
const secretKey = randomSecretKey(seed);
|
|
2419
|
-
const publicKey = await getPublicKeyAsync(secretKey);
|
|
2420
|
-
return { secretKey, publicKey };
|
|
2421
|
-
};
|
|
2422
|
-
var utils = {
|
|
2423
|
-
getExtendedPublicKeyAsync,
|
|
2424
|
-
getExtendedPublicKey,
|
|
2425
|
-
randomSecretKey
|
|
2426
|
-
};
|
|
2427
|
-
var W = 8;
|
|
2428
|
-
var scalarBits = 256;
|
|
2429
|
-
var pwindows = Math.ceil(scalarBits / W) + 1;
|
|
2430
|
-
var pwindowSize = 2 ** (W - 1);
|
|
2431
|
-
var precompute = () => {
|
|
2432
|
-
const points = [];
|
|
2433
|
-
let p = G;
|
|
2434
|
-
let b = p;
|
|
2435
|
-
for (let w = 0; w < pwindows; w++) {
|
|
2436
|
-
b = p;
|
|
2437
|
-
points.push(b);
|
|
2438
|
-
for (let i = 1; i < pwindowSize; i++) {
|
|
2439
|
-
b = b.add(p);
|
|
2440
|
-
points.push(b);
|
|
2441
|
-
}
|
|
2442
|
-
p = b.double();
|
|
2443
|
-
}
|
|
2444
|
-
return points;
|
|
2445
|
-
};
|
|
2446
|
-
var Gpows = void 0;
|
|
2447
|
-
var ctneg = (cnd, p) => {
|
|
2448
|
-
const n = p.negate();
|
|
2449
|
-
return cnd ? n : p;
|
|
2450
|
-
};
|
|
2451
|
-
var wNAF = (n) => {
|
|
2452
|
-
const comp = Gpows || (Gpows = precompute());
|
|
2453
|
-
let p = I;
|
|
2454
|
-
let f = G;
|
|
2455
|
-
const pow_2_w = 2 ** W;
|
|
2456
|
-
const maxNum = pow_2_w;
|
|
2457
|
-
const mask = big(pow_2_w - 1);
|
|
2458
|
-
const shiftBy = big(W);
|
|
2459
|
-
for (let w = 0; w < pwindows; w++) {
|
|
2460
|
-
let wbits = Number(n & mask);
|
|
2461
|
-
n >>= shiftBy;
|
|
2462
|
-
if (wbits > pwindowSize) {
|
|
2463
|
-
wbits -= maxNum;
|
|
2464
|
-
n += 1n;
|
|
2465
|
-
}
|
|
2466
|
-
const off = w * pwindowSize;
|
|
2467
|
-
const offF = off;
|
|
2468
|
-
const offP = off + Math.abs(wbits) - 1;
|
|
2469
|
-
const isEven = w % 2 !== 0;
|
|
2470
|
-
const isNeg = wbits < 0;
|
|
2471
|
-
if (wbits === 0) {
|
|
2472
|
-
f = f.add(ctneg(isEven, comp[offF]));
|
|
2473
|
-
} else {
|
|
2474
|
-
p = p.add(ctneg(isNeg, comp[offP]));
|
|
2475
|
-
}
|
|
2476
|
-
}
|
|
2477
|
-
if (n !== 0n)
|
|
2478
|
-
err("invalid wnaf");
|
|
2479
|
-
return { p, f };
|
|
2480
|
-
};
|
|
1936
|
+
// src/providers/MnemonicWalletProvider.ts
|
|
1937
|
+
import * as bip39 from "@scure/bip39";
|
|
1938
|
+
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
1939
|
+
import { getWarpWalletMnemonicFromConfig } from "@vleap/warps";
|
|
1940
|
+
|
|
1941
|
+
// src/sdk/ed25519-setup.ts
|
|
1942
|
+
import * as ed25519 from "@noble/ed25519";
|
|
2481
1943
|
|
|
2482
|
-
// node_modules/@noble/hashes/utils.js
|
|
2483
|
-
function
|
|
1944
|
+
// ../../node_modules/@noble/hashes/utils.js
|
|
1945
|
+
function isBytes2(a) {
|
|
2484
1946
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
2485
1947
|
}
|
|
2486
|
-
function
|
|
2487
|
-
const bytes =
|
|
1948
|
+
function abytes(value, length, title = "") {
|
|
1949
|
+
const bytes = isBytes2(value);
|
|
2488
1950
|
const len = value?.length;
|
|
2489
1951
|
const needsLen = length !== void 0;
|
|
2490
1952
|
if (!bytes || needsLen && len !== length) {
|
|
@@ -2502,7 +1964,7 @@ function aexists(instance, checkFinished = true) {
|
|
|
2502
1964
|
throw new Error("Hash#digest() has already been called");
|
|
2503
1965
|
}
|
|
2504
1966
|
function aoutput(out, instance) {
|
|
2505
|
-
|
|
1967
|
+
abytes(out, void 0, "digestInto() output");
|
|
2506
1968
|
const min = instance.outputLen;
|
|
2507
1969
|
if (out.length < min) {
|
|
2508
1970
|
throw new Error('"digestInto() output" expected to be of length >=' + min);
|
|
@@ -2529,7 +1991,7 @@ var oidNist = (suffix) => ({
|
|
|
2529
1991
|
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
|
|
2530
1992
|
});
|
|
2531
1993
|
|
|
2532
|
-
// node_modules/@noble/hashes/_md.js
|
|
1994
|
+
// ../../node_modules/@noble/hashes/_md.js
|
|
2533
1995
|
var HashMD = class {
|
|
2534
1996
|
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
2535
1997
|
__publicField(this, "blockLen");
|
|
@@ -2552,7 +2014,7 @@ var HashMD = class {
|
|
|
2552
2014
|
}
|
|
2553
2015
|
update(data) {
|
|
2554
2016
|
aexists(this);
|
|
2555
|
-
|
|
2017
|
+
abytes(data);
|
|
2556
2018
|
const { view, buffer, blockLen } = this;
|
|
2557
2019
|
const len = data.length;
|
|
2558
2020
|
for (let pos = 0; pos < len; ) {
|
|
@@ -2644,7 +2106,7 @@ var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
|
2644
2106
|
327033209
|
|
2645
2107
|
]);
|
|
2646
2108
|
|
|
2647
|
-
// node_modules/@noble/hashes/_u64.js
|
|
2109
|
+
// ../../node_modules/@noble/hashes/_u64.js
|
|
2648
2110
|
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
2649
2111
|
var _32n = /* @__PURE__ */ BigInt(32);
|
|
2650
2112
|
function fromBig(n, le = false) {
|
|
@@ -2657,17 +2119,17 @@ function split(lst, le = false) {
|
|
|
2657
2119
|
let Ah = new Uint32Array(len);
|
|
2658
2120
|
let Al = new Uint32Array(len);
|
|
2659
2121
|
for (let i = 0; i < len; i++) {
|
|
2660
|
-
const { h
|
|
2661
|
-
[Ah[i], Al[i]] = [
|
|
2122
|
+
const { h, l } = fromBig(lst[i], le);
|
|
2123
|
+
[Ah[i], Al[i]] = [h, l];
|
|
2662
2124
|
}
|
|
2663
2125
|
return [Ah, Al];
|
|
2664
2126
|
}
|
|
2665
|
-
var shrSH = (
|
|
2666
|
-
var shrSL = (
|
|
2667
|
-
var rotrSH = (
|
|
2668
|
-
var rotrSL = (
|
|
2669
|
-
var rotrBH = (
|
|
2670
|
-
var rotrBL = (
|
|
2127
|
+
var shrSH = (h, _l, s) => h >>> s;
|
|
2128
|
+
var shrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
2129
|
+
var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
2130
|
+
var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
2131
|
+
var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
2132
|
+
var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
2671
2133
|
function add(Ah, Al, Bh, Bl) {
|
|
2672
2134
|
const l = (Al >>> 0) + (Bl >>> 0);
|
|
2673
2135
|
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
@@ -2679,7 +2141,7 @@ var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0
|
|
|
2679
2141
|
var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
2680
2142
|
var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
2681
2143
|
|
|
2682
|
-
// node_modules/@noble/hashes/sha2.js
|
|
2144
|
+
// ../../node_modules/@noble/hashes/sha2.js
|
|
2683
2145
|
var K512 = /* @__PURE__ */ (() => split([
|
|
2684
2146
|
"0x428a2f98d728ae22",
|
|
2685
2147
|
"0x7137449123ef65cd",
|
|
@@ -2888,38 +2350,216 @@ var sha512 = /* @__PURE__ */ createHasher(
|
|
|
2888
2350
|
);
|
|
2889
2351
|
|
|
2890
2352
|
// src/sdk/ed25519-setup.ts
|
|
2891
|
-
hashes.sha512 = sha512;
|
|
2353
|
+
ed25519.hashes.sha512 = sha512;
|
|
2354
|
+
var ed = ed25519;
|
|
2892
2355
|
|
|
2893
|
-
// src/
|
|
2894
|
-
var
|
|
2356
|
+
// src/providers/MnemonicWalletProvider.ts
|
|
2357
|
+
var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
2895
2358
|
constructor(config, chain2) {
|
|
2896
2359
|
this.config = config;
|
|
2897
2360
|
this.chain = chain2;
|
|
2898
|
-
this.
|
|
2361
|
+
this.privateKey = null;
|
|
2362
|
+
}
|
|
2363
|
+
async getAddress() {
|
|
2364
|
+
try {
|
|
2365
|
+
const privateKey = this.getPrivateKey();
|
|
2366
|
+
const publicKey = ed.getPublicKey(privateKey);
|
|
2367
|
+
return FastsetClient.encodeBech32Address(publicKey);
|
|
2368
|
+
} catch {
|
|
2369
|
+
return null;
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
async getPublicKey() {
|
|
2373
|
+
try {
|
|
2374
|
+
const privateKey = this.getPrivateKey();
|
|
2375
|
+
const publicKey = ed.getPublicKey(privateKey);
|
|
2376
|
+
return uint8ArrayToHex(publicKey);
|
|
2377
|
+
} catch {
|
|
2378
|
+
return null;
|
|
2379
|
+
}
|
|
2899
2380
|
}
|
|
2900
2381
|
async signTransaction(tx) {
|
|
2382
|
+
const privateKey = this.getPrivateKey();
|
|
2901
2383
|
const msg = Transaction.serialize(tx);
|
|
2902
2384
|
const msgBytes = msg.toBytes();
|
|
2903
2385
|
const prefix = new TextEncoder().encode("Transaction::");
|
|
2904
2386
|
const dataToSign = new Uint8Array(prefix.length + msgBytes.length);
|
|
2905
2387
|
dataToSign.set(prefix, 0);
|
|
2906
2388
|
dataToSign.set(msgBytes, prefix.length);
|
|
2907
|
-
const
|
|
2908
|
-
if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
|
|
2909
|
-
const privateKeyBytes = hexToUint8Array(privateKey);
|
|
2910
|
-
const signature = ed25519_exports.sign(dataToSign, privateKeyBytes);
|
|
2389
|
+
const signature = ed.sign(dataToSign, privateKey);
|
|
2911
2390
|
return { ...tx, signature };
|
|
2912
2391
|
}
|
|
2913
2392
|
async signMessage(message) {
|
|
2914
|
-
const
|
|
2915
|
-
const
|
|
2916
|
-
|
|
2917
|
-
const privateKeyBytes = hexToUint8Array(privateKey);
|
|
2918
|
-
const signature = ed25519_exports.sign(messageBytes, privateKeyBytes);
|
|
2393
|
+
const privateKey = this.getPrivateKey();
|
|
2394
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
2395
|
+
const signature = ed.sign(messageBytes, privateKey);
|
|
2919
2396
|
return uint8ArrayToHex(signature);
|
|
2920
2397
|
}
|
|
2398
|
+
create(mnemonic) {
|
|
2399
|
+
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
2400
|
+
const privateKey = seed.slice(0, 32);
|
|
2401
|
+
const publicKey = ed.getPublicKey(privateKey);
|
|
2402
|
+
const address = FastsetClient.encodeBech32Address(publicKey);
|
|
2403
|
+
return {
|
|
2404
|
+
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
2405
|
+
address,
|
|
2406
|
+
privateKey: null,
|
|
2407
|
+
mnemonic
|
|
2408
|
+
};
|
|
2409
|
+
}
|
|
2410
|
+
generate() {
|
|
2411
|
+
const mnemonic = bip39.generateMnemonic(wordlist);
|
|
2412
|
+
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
2413
|
+
const privateKey = seed.slice(0, 32);
|
|
2414
|
+
const publicKey = ed.getPublicKey(privateKey);
|
|
2415
|
+
const address = FastsetClient.encodeBech32Address(publicKey);
|
|
2416
|
+
return {
|
|
2417
|
+
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
2418
|
+
address,
|
|
2419
|
+
privateKey: null,
|
|
2420
|
+
mnemonic
|
|
2421
|
+
};
|
|
2422
|
+
}
|
|
2423
|
+
getPrivateKey() {
|
|
2424
|
+
if (this.privateKey) return this.privateKey;
|
|
2425
|
+
const mnemonic = getWarpWalletMnemonicFromConfig(this.config, this.chain.name);
|
|
2426
|
+
if (!mnemonic) throw new Error("No mnemonic provided");
|
|
2427
|
+
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
2428
|
+
this.privateKey = seed.slice(0, 32);
|
|
2429
|
+
return this.privateKey;
|
|
2430
|
+
}
|
|
2431
|
+
};
|
|
2432
|
+
_MnemonicWalletProvider.PROVIDER_NAME = "mnemonic";
|
|
2433
|
+
var MnemonicWalletProvider = _MnemonicWalletProvider;
|
|
2434
|
+
|
|
2435
|
+
// src/providers/PrivateKeyWalletProvider.ts
|
|
2436
|
+
import { getWarpWalletPrivateKeyFromConfig } from "@vleap/warps";
|
|
2437
|
+
var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
2438
|
+
constructor(config, chain2) {
|
|
2439
|
+
this.config = config;
|
|
2440
|
+
this.chain = chain2;
|
|
2441
|
+
this.privateKey = null;
|
|
2442
|
+
}
|
|
2443
|
+
async getAddress() {
|
|
2444
|
+
try {
|
|
2445
|
+
const privateKey = this.getPrivateKey();
|
|
2446
|
+
const publicKey = ed.getPublicKey(privateKey);
|
|
2447
|
+
return FastsetClient.encodeBech32Address(publicKey);
|
|
2448
|
+
} catch {
|
|
2449
|
+
return null;
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
async getPublicKey() {
|
|
2453
|
+
try {
|
|
2454
|
+
const privateKey = this.getPrivateKey();
|
|
2455
|
+
const publicKey = ed.getPublicKey(privateKey);
|
|
2456
|
+
return uint8ArrayToHex(publicKey);
|
|
2457
|
+
} catch {
|
|
2458
|
+
return null;
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
async signTransaction(tx) {
|
|
2462
|
+
const privateKey = this.getPrivateKey();
|
|
2463
|
+
const msg = Transaction.serialize(tx);
|
|
2464
|
+
const msgBytes = msg.toBytes();
|
|
2465
|
+
const prefix = new TextEncoder().encode("Transaction::");
|
|
2466
|
+
const dataToSign = new Uint8Array(prefix.length + msgBytes.length);
|
|
2467
|
+
dataToSign.set(prefix, 0);
|
|
2468
|
+
dataToSign.set(msgBytes, prefix.length);
|
|
2469
|
+
const signature = ed.sign(dataToSign, privateKey);
|
|
2470
|
+
return { ...tx, signature };
|
|
2471
|
+
}
|
|
2472
|
+
async signMessage(message) {
|
|
2473
|
+
const privateKey = this.getPrivateKey();
|
|
2474
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
2475
|
+
const signature = ed.sign(messageBytes, privateKey);
|
|
2476
|
+
return uint8ArrayToHex(signature);
|
|
2477
|
+
}
|
|
2478
|
+
create(mnemonic) {
|
|
2479
|
+
throw new Error("PrivateKeyWalletProvider does not support creating wallets from mnemonics. Use MnemonicWalletProvider instead.");
|
|
2480
|
+
}
|
|
2481
|
+
generate() {
|
|
2482
|
+
const privateKey = ed.utils.randomSecretKey();
|
|
2483
|
+
const publicKey = ed.getPublicKey(privateKey);
|
|
2484
|
+
const address = FastsetClient.encodeBech32Address(publicKey);
|
|
2485
|
+
return {
|
|
2486
|
+
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
2487
|
+
address,
|
|
2488
|
+
privateKey: uint8ArrayToHex(privateKey),
|
|
2489
|
+
mnemonic: null
|
|
2490
|
+
};
|
|
2491
|
+
}
|
|
2492
|
+
getPrivateKey() {
|
|
2493
|
+
if (this.privateKey) return this.privateKey;
|
|
2494
|
+
const privateKeyHex = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
|
|
2495
|
+
if (!privateKeyHex) throw new Error("No private key provided");
|
|
2496
|
+
this.privateKey = hexToUint8Array(privateKeyHex);
|
|
2497
|
+
return this.privateKey;
|
|
2498
|
+
}
|
|
2499
|
+
};
|
|
2500
|
+
_PrivateKeyWalletProvider.PROVIDER_NAME = "privateKey";
|
|
2501
|
+
var PrivateKeyWalletProvider = _PrivateKeyWalletProvider;
|
|
2502
|
+
|
|
2503
|
+
// src/providers/ReadOnlyWalletProvider.ts
|
|
2504
|
+
import { getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig3 } from "@vleap/warps";
|
|
2505
|
+
var ReadOnlyWalletProvider = class {
|
|
2506
|
+
constructor(config, chain2) {
|
|
2507
|
+
this.config = config;
|
|
2508
|
+
this.chain = chain2;
|
|
2509
|
+
}
|
|
2510
|
+
async getAddress() {
|
|
2511
|
+
return getWarpWalletAddressFromConfig3(this.config, this.chain.name);
|
|
2512
|
+
}
|
|
2513
|
+
async getPublicKey() {
|
|
2514
|
+
return null;
|
|
2515
|
+
}
|
|
2516
|
+
async signTransaction(tx) {
|
|
2517
|
+
const address = await this.getAddress();
|
|
2518
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
2519
|
+
}
|
|
2520
|
+
async signMessage(message) {
|
|
2521
|
+
const address = await this.getAddress();
|
|
2522
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
2523
|
+
}
|
|
2524
|
+
create(mnemonic) {
|
|
2525
|
+
const address = getWarpWalletAddressFromConfig3(this.config, this.chain.name);
|
|
2526
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
2527
|
+
}
|
|
2528
|
+
generate() {
|
|
2529
|
+
const address = getWarpWalletAddressFromConfig3(this.config, this.chain.name);
|
|
2530
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
2531
|
+
}
|
|
2532
|
+
};
|
|
2533
|
+
|
|
2534
|
+
// src/WarpFastsetWallet.ts
|
|
2535
|
+
var WarpFastsetWallet = class {
|
|
2536
|
+
constructor(config, chain2) {
|
|
2537
|
+
this.config = config;
|
|
2538
|
+
this.chain = chain2;
|
|
2539
|
+
this.cachedAddress = null;
|
|
2540
|
+
this.cachedPublicKey = null;
|
|
2541
|
+
this.client = getConfiguredFastsetClient(this.config, this.chain);
|
|
2542
|
+
this.walletProvider = this.createProvider();
|
|
2543
|
+
this.initializeCache();
|
|
2544
|
+
}
|
|
2545
|
+
async signTransaction(tx) {
|
|
2546
|
+
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
2547
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
2548
|
+
if (this.walletProvider instanceof ReadOnlyWalletProvider) throw new Error(`Wallet (${this.chain.name}) is read-only`);
|
|
2549
|
+
return await this.walletProvider.signTransaction(tx);
|
|
2550
|
+
}
|
|
2921
2551
|
async signTransactions(txs) {
|
|
2922
|
-
|
|
2552
|
+
if (txs.length === 0) return [];
|
|
2553
|
+
const signedTxs = [];
|
|
2554
|
+
for (const tx of txs) {
|
|
2555
|
+
signedTxs.push(await this.signTransaction(tx));
|
|
2556
|
+
}
|
|
2557
|
+
return signedTxs;
|
|
2558
|
+
}
|
|
2559
|
+
async signMessage(message) {
|
|
2560
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
2561
|
+
if (this.walletProvider instanceof ReadOnlyWalletProvider) throw new Error(`Wallet (${this.chain.name}) is read-only`);
|
|
2562
|
+
return await this.walletProvider.signMessage(message);
|
|
2923
2563
|
}
|
|
2924
2564
|
async sendTransaction(tx) {
|
|
2925
2565
|
const { signature, ...transactionWithoutSignature } = tx;
|
|
@@ -2929,37 +2569,43 @@ var WarpFastsetWallet = class {
|
|
|
2929
2569
|
async sendTransactions(txs) {
|
|
2930
2570
|
return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
|
|
2931
2571
|
}
|
|
2932
|
-
create(mnemonic) {
|
|
2933
|
-
const
|
|
2934
|
-
|
|
2935
|
-
const publicKey = ed25519_exports.getPublicKey(privateKey);
|
|
2936
|
-
const address = FastsetClient.encodeBech32Address(publicKey);
|
|
2937
|
-
return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic };
|
|
2572
|
+
create(mnemonic, provider) {
|
|
2573
|
+
const walletProvider = this.createProviderForOperation(provider);
|
|
2574
|
+
return walletProvider.create(mnemonic);
|
|
2938
2575
|
}
|
|
2939
|
-
generate() {
|
|
2940
|
-
const
|
|
2941
|
-
|
|
2942
|
-
const address = FastsetClient.encodeBech32Address(publicKey);
|
|
2943
|
-
return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic: null };
|
|
2576
|
+
generate(provider) {
|
|
2577
|
+
const walletProvider = this.createProviderForOperation(provider);
|
|
2578
|
+
return walletProvider.generate();
|
|
2944
2579
|
}
|
|
2945
2580
|
getAddress() {
|
|
2946
|
-
return
|
|
2581
|
+
return this.cachedAddress;
|
|
2947
2582
|
}
|
|
2948
2583
|
getPublicKey() {
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2584
|
+
return this.cachedPublicKey;
|
|
2585
|
+
}
|
|
2586
|
+
createProvider() {
|
|
2587
|
+
const wallet = this.config.user?.wallets?.[this.chain.name];
|
|
2588
|
+
if (!wallet) return null;
|
|
2589
|
+
if (typeof wallet === "string") return new ReadOnlyWalletProvider(this.config, this.chain);
|
|
2590
|
+
return this.createProviderForOperation(wallet.provider);
|
|
2591
|
+
}
|
|
2592
|
+
initializeCache() {
|
|
2593
|
+
initializeWalletCache(this.walletProvider).then((cache) => {
|
|
2594
|
+
this.cachedAddress = cache.address;
|
|
2595
|
+
this.cachedPublicKey = cache.publicKey;
|
|
2596
|
+
});
|
|
2597
|
+
}
|
|
2598
|
+
createProviderForOperation(provider) {
|
|
2599
|
+
const customWalletProviders = this.config.walletProviders?.[this.chain.name];
|
|
2600
|
+
const providerFactory = customWalletProviders?.[provider];
|
|
2601
|
+
if (providerFactory) {
|
|
2602
|
+
const walletProvider = providerFactory(this.config, this.chain);
|
|
2603
|
+
if (!walletProvider) throw new Error(`Custom wallet provider factory returned null for ${provider}`);
|
|
2604
|
+
return walletProvider;
|
|
2962
2605
|
}
|
|
2606
|
+
if (provider === "privateKey") return new PrivateKeyWalletProvider(this.config, this.chain);
|
|
2607
|
+
if (provider === "mnemonic") return new MnemonicWalletProvider(this.config, this.chain);
|
|
2608
|
+
throw new Error(`Unsupported wallet provider for ${this.chain.name}: ${provider}`);
|
|
2963
2609
|
}
|
|
2964
2610
|
};
|
|
2965
2611
|
|
|
@@ -2992,7 +2638,7 @@ function createFastsetAdapter(chainName, chainInfos) {
|
|
|
2992
2638
|
};
|
|
2993
2639
|
};
|
|
2994
2640
|
}
|
|
2995
|
-
var
|
|
2641
|
+
var FastsetAdapter = createFastsetAdapter(WarpChainName.Fastset, {
|
|
2996
2642
|
mainnet: {
|
|
2997
2643
|
name: WarpChainName.Fastset,
|
|
2998
2644
|
displayName: "FastSet",
|
|
@@ -3025,19 +2671,16 @@ var getFastsetAdapter = createFastsetAdapter(WarpChainName.Fastset, {
|
|
|
3025
2671
|
}
|
|
3026
2672
|
});
|
|
3027
2673
|
export {
|
|
2674
|
+
FastsetAdapter,
|
|
3028
2675
|
NativeTokenSet,
|
|
3029
2676
|
WarpFastsetExecutor,
|
|
3030
|
-
WarpFastsetWallet
|
|
3031
|
-
getFastsetAdapter
|
|
2677
|
+
WarpFastsetWallet
|
|
3032
2678
|
};
|
|
3033
2679
|
/*! Bundled license information:
|
|
3034
2680
|
|
|
3035
2681
|
@scure/base/lib/esm/index.js:
|
|
3036
2682
|
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
3037
2683
|
|
|
3038
|
-
@noble/ed25519/index.js:
|
|
3039
|
-
(*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
|
|
3040
|
-
|
|
3041
2684
|
@noble/hashes/utils.js:
|
|
3042
2685
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
3043
2686
|
*/
|