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