@meshsdk/wallet 1.7.19 → 1.7.21
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.cjs +102 -71
- package/dist/index.js +102 -71
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -42,13 +42,45 @@ module.exports = __toCommonJS(src_exports);
|
|
|
42
42
|
var import_core_cst2 = require("@meshsdk/core-cst");
|
|
43
43
|
|
|
44
44
|
// ../../node_modules/@scure/base/lib/esm/index.js
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
function isBytes(a) {
|
|
46
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
47
|
+
}
|
|
48
|
+
function isArrayOf(isString, arr) {
|
|
49
|
+
if (!Array.isArray(arr))
|
|
50
|
+
return false;
|
|
51
|
+
if (arr.length === 0)
|
|
52
|
+
return true;
|
|
53
|
+
if (isString) {
|
|
54
|
+
return arr.every((item) => typeof item === "string");
|
|
55
|
+
} else {
|
|
56
|
+
return arr.every((item) => Number.isSafeInteger(item));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function afn(input) {
|
|
60
|
+
if (typeof input !== "function")
|
|
61
|
+
throw new Error("function expected");
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
function astr(label, input) {
|
|
65
|
+
if (typeof input !== "string")
|
|
66
|
+
throw new Error(`${label}: string expected`);
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
function anumber(n) {
|
|
47
70
|
if (!Number.isSafeInteger(n))
|
|
48
|
-
throw new Error(`
|
|
71
|
+
throw new Error(`invalid integer: ${n}`);
|
|
49
72
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
73
|
+
function aArr(input) {
|
|
74
|
+
if (!Array.isArray(input))
|
|
75
|
+
throw new Error("array expected");
|
|
76
|
+
}
|
|
77
|
+
function astrArr(label, input) {
|
|
78
|
+
if (!isArrayOf(true, input))
|
|
79
|
+
throw new Error(`${label}: array of strings expected`);
|
|
80
|
+
}
|
|
81
|
+
function anumArr(label, input) {
|
|
82
|
+
if (!isArrayOf(false, input))
|
|
83
|
+
throw new Error(`${label}: array of numbers expected`);
|
|
52
84
|
}
|
|
53
85
|
// @__NO_SIDE_EFFECTS__
|
|
54
86
|
function chain(...args) {
|
|
@@ -59,58 +91,56 @@ function chain(...args) {
|
|
|
59
91
|
return { encode, decode };
|
|
60
92
|
}
|
|
61
93
|
// @__NO_SIDE_EFFECTS__
|
|
62
|
-
function alphabet(
|
|
94
|
+
function alphabet(letters) {
|
|
95
|
+
const lettersA = typeof letters === "string" ? letters.split("") : letters;
|
|
96
|
+
const len = lettersA.length;
|
|
97
|
+
astrArr("alphabet", lettersA);
|
|
98
|
+
const indexes = new Map(lettersA.map((l, i) => [l, i]));
|
|
63
99
|
return {
|
|
64
100
|
encode: (digits) => {
|
|
65
|
-
|
|
66
|
-
throw new Error("alphabet.encode input should be an array of numbers");
|
|
101
|
+
aArr(digits);
|
|
67
102
|
return digits.map((i) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return alphabet2[i];
|
|
103
|
+
if (!Number.isSafeInteger(i) || i < 0 || i >= len)
|
|
104
|
+
throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
|
|
105
|
+
return lettersA[i];
|
|
72
106
|
});
|
|
73
107
|
},
|
|
74
108
|
decode: (input) => {
|
|
75
|
-
|
|
76
|
-
throw new Error("alphabet.decode input should be array of strings");
|
|
109
|
+
aArr(input);
|
|
77
110
|
return input.map((letter) => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return index;
|
|
111
|
+
astr("alphabet.decode", letter);
|
|
112
|
+
const i = indexes.get(letter);
|
|
113
|
+
if (i === void 0)
|
|
114
|
+
throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
|
|
115
|
+
return i;
|
|
84
116
|
});
|
|
85
117
|
}
|
|
86
118
|
};
|
|
87
119
|
}
|
|
88
120
|
// @__NO_SIDE_EFFECTS__
|
|
89
121
|
function join(separator = "") {
|
|
90
|
-
|
|
91
|
-
throw new Error("join separator should be string");
|
|
122
|
+
astr("join", separator);
|
|
92
123
|
return {
|
|
93
124
|
encode: (from) => {
|
|
94
|
-
|
|
95
|
-
throw new Error("join.encode input should be array of strings");
|
|
96
|
-
for (let i of from)
|
|
97
|
-
if (typeof i !== "string")
|
|
98
|
-
throw new Error(`join.encode: non-string input=${i}`);
|
|
125
|
+
astrArr("join.decode", from);
|
|
99
126
|
return from.join(separator);
|
|
100
127
|
},
|
|
101
128
|
decode: (to) => {
|
|
102
|
-
|
|
103
|
-
throw new Error("join.decode input should be string");
|
|
129
|
+
astr("join.decode", to);
|
|
104
130
|
return to.split(separator);
|
|
105
131
|
}
|
|
106
132
|
};
|
|
107
133
|
}
|
|
108
|
-
var gcd =
|
|
109
|
-
var radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to -
|
|
110
|
-
|
|
134
|
+
var gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
|
|
135
|
+
var radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to - gcd(from, to));
|
|
136
|
+
var powers = /* @__PURE__ */ (() => {
|
|
137
|
+
let res = [];
|
|
138
|
+
for (let i = 0; i < 40; i++)
|
|
139
|
+
res.push(2 ** i);
|
|
140
|
+
return res;
|
|
141
|
+
})();
|
|
111
142
|
function convertRadix2(data, from, to, padding) {
|
|
112
|
-
|
|
113
|
-
throw new Error("convertRadix2: data should be array");
|
|
143
|
+
aArr(data);
|
|
114
144
|
if (from <= 0 || from > 32)
|
|
115
145
|
throw new Error(`convertRadix2: wrong from=${from}`);
|
|
116
146
|
if (to <= 0 || to > 32)
|
|
@@ -120,11 +150,12 @@ function convertRadix2(data, from, to, padding) {
|
|
|
120
150
|
}
|
|
121
151
|
let carry = 0;
|
|
122
152
|
let pos = 0;
|
|
123
|
-
const
|
|
153
|
+
const max = powers[from];
|
|
154
|
+
const mask = powers[to] - 1;
|
|
124
155
|
const res = [];
|
|
125
156
|
for (const n of data) {
|
|
126
|
-
|
|
127
|
-
if (n >=
|
|
157
|
+
anumber(n);
|
|
158
|
+
if (n >= max)
|
|
128
159
|
throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);
|
|
129
160
|
carry = carry << from | n;
|
|
130
161
|
if (pos + from > 32)
|
|
@@ -132,12 +163,15 @@ function convertRadix2(data, from, to, padding) {
|
|
|
132
163
|
pos += from;
|
|
133
164
|
for (; pos >= to; pos -= to)
|
|
134
165
|
res.push((carry >> pos - to & mask) >>> 0);
|
|
135
|
-
|
|
166
|
+
const pow = powers[pos];
|
|
167
|
+
if (pow === void 0)
|
|
168
|
+
throw new Error("invalid carry");
|
|
169
|
+
carry &= pow - 1;
|
|
136
170
|
}
|
|
137
171
|
carry = carry << to - pos & mask;
|
|
138
172
|
if (!padding && pos >= from)
|
|
139
173
|
throw new Error("Excess padding");
|
|
140
|
-
if (!padding && carry)
|
|
174
|
+
if (!padding && carry > 0)
|
|
141
175
|
throw new Error(`Non-zero padding: ${carry}`);
|
|
142
176
|
if (padding && pos > 0)
|
|
143
177
|
res.push(carry >>> 0);
|
|
@@ -145,7 +179,7 @@ function convertRadix2(data, from, to, padding) {
|
|
|
145
179
|
}
|
|
146
180
|
// @__NO_SIDE_EFFECTS__
|
|
147
181
|
function radix2(bits, revPadding = false) {
|
|
148
|
-
|
|
182
|
+
anumber(bits);
|
|
149
183
|
if (bits <= 0 || bits > 32)
|
|
150
184
|
throw new Error("radix2: bits should be in (0..32]");
|
|
151
185
|
if (/* @__PURE__ */ radix2carry(8, bits) > 32 || /* @__PURE__ */ radix2carry(bits, 8) > 32)
|
|
@@ -154,19 +188,16 @@ function radix2(bits, revPadding = false) {
|
|
|
154
188
|
encode: (bytes) => {
|
|
155
189
|
if (!isBytes(bytes))
|
|
156
190
|
throw new Error("radix2.encode input should be Uint8Array");
|
|
157
|
-
return
|
|
191
|
+
return convertRadix2(Array.from(bytes), 8, bits, !revPadding);
|
|
158
192
|
},
|
|
159
193
|
decode: (digits) => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return Uint8Array.from(/* @__PURE__ */ convertRadix2(digits, bits, 8, revPadding));
|
|
194
|
+
anumArr("radix2.decode", digits);
|
|
195
|
+
return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));
|
|
163
196
|
}
|
|
164
197
|
};
|
|
165
198
|
}
|
|
166
|
-
// @__NO_SIDE_EFFECTS__
|
|
167
199
|
function unsafeWrapper(fn) {
|
|
168
|
-
|
|
169
|
-
throw new Error("unsafeWrapper fn should be function");
|
|
200
|
+
afn(fn);
|
|
170
201
|
return function(...args) {
|
|
171
202
|
try {
|
|
172
203
|
return fn.apply(null, args);
|
|
@@ -176,7 +207,6 @@ function unsafeWrapper(fn) {
|
|
|
176
207
|
}
|
|
177
208
|
var BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join(""));
|
|
178
209
|
var POLYMOD_GENERATORS = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
179
|
-
// @__NO_SIDE_EFFECTS__
|
|
180
210
|
function bech32Polymod(pre) {
|
|
181
211
|
const b = pre >> 25;
|
|
182
212
|
let chk = (pre & 33554431) << 5;
|
|
@@ -186,7 +216,6 @@ function bech32Polymod(pre) {
|
|
|
186
216
|
}
|
|
187
217
|
return chk;
|
|
188
218
|
}
|
|
189
|
-
// @__NO_SIDE_EFFECTS__
|
|
190
219
|
function bechChecksum(prefix, words, encodingConst = 1) {
|
|
191
220
|
const len = prefix.length;
|
|
192
221
|
let chk = 1;
|
|
@@ -194,17 +223,17 @@ function bechChecksum(prefix, words, encodingConst = 1) {
|
|
|
194
223
|
const c = prefix.charCodeAt(i);
|
|
195
224
|
if (c < 33 || c > 126)
|
|
196
225
|
throw new Error(`Invalid prefix (${prefix})`);
|
|
197
|
-
chk =
|
|
226
|
+
chk = bech32Polymod(chk) ^ c >> 5;
|
|
198
227
|
}
|
|
199
|
-
chk =
|
|
228
|
+
chk = bech32Polymod(chk);
|
|
200
229
|
for (let i = 0; i < len; i++)
|
|
201
|
-
chk =
|
|
230
|
+
chk = bech32Polymod(chk) ^ prefix.charCodeAt(i) & 31;
|
|
202
231
|
for (let v of words)
|
|
203
|
-
chk =
|
|
232
|
+
chk = bech32Polymod(chk) ^ v;
|
|
204
233
|
for (let i = 0; i < 6; i++)
|
|
205
|
-
chk =
|
|
234
|
+
chk = bech32Polymod(chk);
|
|
206
235
|
chk ^= encodingConst;
|
|
207
|
-
return BECH_ALPHABET.encode(
|
|
236
|
+
return BECH_ALPHABET.encode(convertRadix2([chk % powers[30]], 30, 5, false));
|
|
208
237
|
}
|
|
209
238
|
// @__NO_SIDE_EFFECTS__
|
|
210
239
|
function genBech32(encoding) {
|
|
@@ -212,28 +241,27 @@ function genBech32(encoding) {
|
|
|
212
241
|
const _words = /* @__PURE__ */ radix2(5);
|
|
213
242
|
const fromWords = _words.decode;
|
|
214
243
|
const toWords = _words.encode;
|
|
215
|
-
const fromWordsUnsafe =
|
|
244
|
+
const fromWordsUnsafe = unsafeWrapper(fromWords);
|
|
216
245
|
function encode(prefix, words, limit = 90) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (words instanceof Uint8Array)
|
|
246
|
+
astr("bech32.encode prefix", prefix);
|
|
247
|
+
if (isBytes(words))
|
|
220
248
|
words = Array.from(words);
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (
|
|
224
|
-
throw new TypeError(`Invalid prefix length ${
|
|
225
|
-
const actualLength =
|
|
249
|
+
anumArr("bech32.encode", words);
|
|
250
|
+
const plen = prefix.length;
|
|
251
|
+
if (plen === 0)
|
|
252
|
+
throw new TypeError(`Invalid prefix length ${plen}`);
|
|
253
|
+
const actualLength = plen + 7 + words.length;
|
|
226
254
|
if (limit !== false && actualLength > limit)
|
|
227
255
|
throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`);
|
|
228
256
|
const lowered = prefix.toLowerCase();
|
|
229
|
-
const sum =
|
|
257
|
+
const sum = bechChecksum(lowered, words, ENCODING_CONST);
|
|
230
258
|
return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}`;
|
|
231
259
|
}
|
|
232
260
|
function decode(str, limit = 90) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (
|
|
236
|
-
throw new TypeError(`
|
|
261
|
+
astr("bech32.decode input", str);
|
|
262
|
+
const slen = str.length;
|
|
263
|
+
if (slen < 8 || limit !== false && slen > limit)
|
|
264
|
+
throw new TypeError(`invalid string length: ${slen} (${str}). Expected (8..${limit})`);
|
|
237
265
|
const lowered = str.toLowerCase();
|
|
238
266
|
if (str !== lowered && str !== str.toUpperCase())
|
|
239
267
|
throw new Error(`String must be lowercase or uppercase`);
|
|
@@ -245,12 +273,12 @@ function genBech32(encoding) {
|
|
|
245
273
|
if (data.length < 6)
|
|
246
274
|
throw new Error("Data must be at least 6 characters long");
|
|
247
275
|
const words = BECH_ALPHABET.decode(data).slice(0, -6);
|
|
248
|
-
const sum =
|
|
276
|
+
const sum = bechChecksum(prefix, words, ENCODING_CONST);
|
|
249
277
|
if (!data.endsWith(sum))
|
|
250
278
|
throw new Error(`Invalid checksum in ${str}: expected "${sum}"`);
|
|
251
279
|
return { prefix, words };
|
|
252
280
|
}
|
|
253
|
-
const decodeUnsafe =
|
|
281
|
+
const decodeUnsafe = unsafeWrapper(decode);
|
|
254
282
|
function decodeToBytes(str) {
|
|
255
283
|
const { prefix, words } = decode(str, false);
|
|
256
284
|
return { prefix, words, bytes: fromWords(words) };
|
|
@@ -817,6 +845,9 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
817
845
|
async signData(payload, address) {
|
|
818
846
|
if (address === void 0) {
|
|
819
847
|
address = (await this.getUsedAddresses())[0];
|
|
848
|
+
if (address === void 0) {
|
|
849
|
+
address = await this.getChangeAddress();
|
|
850
|
+
}
|
|
820
851
|
}
|
|
821
852
|
if (address.startsWith("drep1")) {
|
|
822
853
|
return this._walletInstance.cip95.signData(address, (0, import_common2.fromUTF8)(payload));
|
package/dist/index.js
CHANGED
|
@@ -6,13 +6,45 @@ import {
|
|
|
6
6
|
} from "@meshsdk/core-cst";
|
|
7
7
|
|
|
8
8
|
// ../../node_modules/@scure/base/lib/esm/index.js
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
function isBytes(a) {
|
|
10
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
11
|
+
}
|
|
12
|
+
function isArrayOf(isString, arr) {
|
|
13
|
+
if (!Array.isArray(arr))
|
|
14
|
+
return false;
|
|
15
|
+
if (arr.length === 0)
|
|
16
|
+
return true;
|
|
17
|
+
if (isString) {
|
|
18
|
+
return arr.every((item) => typeof item === "string");
|
|
19
|
+
} else {
|
|
20
|
+
return arr.every((item) => Number.isSafeInteger(item));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function afn(input) {
|
|
24
|
+
if (typeof input !== "function")
|
|
25
|
+
throw new Error("function expected");
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
function astr(label, input) {
|
|
29
|
+
if (typeof input !== "string")
|
|
30
|
+
throw new Error(`${label}: string expected`);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
function anumber(n) {
|
|
11
34
|
if (!Number.isSafeInteger(n))
|
|
12
|
-
throw new Error(`
|
|
35
|
+
throw new Error(`invalid integer: ${n}`);
|
|
13
36
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
37
|
+
function aArr(input) {
|
|
38
|
+
if (!Array.isArray(input))
|
|
39
|
+
throw new Error("array expected");
|
|
40
|
+
}
|
|
41
|
+
function astrArr(label, input) {
|
|
42
|
+
if (!isArrayOf(true, input))
|
|
43
|
+
throw new Error(`${label}: array of strings expected`);
|
|
44
|
+
}
|
|
45
|
+
function anumArr(label, input) {
|
|
46
|
+
if (!isArrayOf(false, input))
|
|
47
|
+
throw new Error(`${label}: array of numbers expected`);
|
|
16
48
|
}
|
|
17
49
|
// @__NO_SIDE_EFFECTS__
|
|
18
50
|
function chain(...args) {
|
|
@@ -23,58 +55,56 @@ function chain(...args) {
|
|
|
23
55
|
return { encode, decode };
|
|
24
56
|
}
|
|
25
57
|
// @__NO_SIDE_EFFECTS__
|
|
26
|
-
function alphabet(
|
|
58
|
+
function alphabet(letters) {
|
|
59
|
+
const lettersA = typeof letters === "string" ? letters.split("") : letters;
|
|
60
|
+
const len = lettersA.length;
|
|
61
|
+
astrArr("alphabet", lettersA);
|
|
62
|
+
const indexes = new Map(lettersA.map((l, i) => [l, i]));
|
|
27
63
|
return {
|
|
28
64
|
encode: (digits) => {
|
|
29
|
-
|
|
30
|
-
throw new Error("alphabet.encode input should be an array of numbers");
|
|
65
|
+
aArr(digits);
|
|
31
66
|
return digits.map((i) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return alphabet2[i];
|
|
67
|
+
if (!Number.isSafeInteger(i) || i < 0 || i >= len)
|
|
68
|
+
throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
|
|
69
|
+
return lettersA[i];
|
|
36
70
|
});
|
|
37
71
|
},
|
|
38
72
|
decode: (input) => {
|
|
39
|
-
|
|
40
|
-
throw new Error("alphabet.decode input should be array of strings");
|
|
73
|
+
aArr(input);
|
|
41
74
|
return input.map((letter) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return index;
|
|
75
|
+
astr("alphabet.decode", letter);
|
|
76
|
+
const i = indexes.get(letter);
|
|
77
|
+
if (i === void 0)
|
|
78
|
+
throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
|
|
79
|
+
return i;
|
|
48
80
|
});
|
|
49
81
|
}
|
|
50
82
|
};
|
|
51
83
|
}
|
|
52
84
|
// @__NO_SIDE_EFFECTS__
|
|
53
85
|
function join(separator = "") {
|
|
54
|
-
|
|
55
|
-
throw new Error("join separator should be string");
|
|
86
|
+
astr("join", separator);
|
|
56
87
|
return {
|
|
57
88
|
encode: (from) => {
|
|
58
|
-
|
|
59
|
-
throw new Error("join.encode input should be array of strings");
|
|
60
|
-
for (let i of from)
|
|
61
|
-
if (typeof i !== "string")
|
|
62
|
-
throw new Error(`join.encode: non-string input=${i}`);
|
|
89
|
+
astrArr("join.decode", from);
|
|
63
90
|
return from.join(separator);
|
|
64
91
|
},
|
|
65
92
|
decode: (to) => {
|
|
66
|
-
|
|
67
|
-
throw new Error("join.decode input should be string");
|
|
93
|
+
astr("join.decode", to);
|
|
68
94
|
return to.split(separator);
|
|
69
95
|
}
|
|
70
96
|
};
|
|
71
97
|
}
|
|
72
|
-
var gcd =
|
|
73
|
-
var radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to -
|
|
74
|
-
|
|
98
|
+
var gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
|
|
99
|
+
var radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to - gcd(from, to));
|
|
100
|
+
var powers = /* @__PURE__ */ (() => {
|
|
101
|
+
let res = [];
|
|
102
|
+
for (let i = 0; i < 40; i++)
|
|
103
|
+
res.push(2 ** i);
|
|
104
|
+
return res;
|
|
105
|
+
})();
|
|
75
106
|
function convertRadix2(data, from, to, padding) {
|
|
76
|
-
|
|
77
|
-
throw new Error("convertRadix2: data should be array");
|
|
107
|
+
aArr(data);
|
|
78
108
|
if (from <= 0 || from > 32)
|
|
79
109
|
throw new Error(`convertRadix2: wrong from=${from}`);
|
|
80
110
|
if (to <= 0 || to > 32)
|
|
@@ -84,11 +114,12 @@ function convertRadix2(data, from, to, padding) {
|
|
|
84
114
|
}
|
|
85
115
|
let carry = 0;
|
|
86
116
|
let pos = 0;
|
|
87
|
-
const
|
|
117
|
+
const max = powers[from];
|
|
118
|
+
const mask = powers[to] - 1;
|
|
88
119
|
const res = [];
|
|
89
120
|
for (const n of data) {
|
|
90
|
-
|
|
91
|
-
if (n >=
|
|
121
|
+
anumber(n);
|
|
122
|
+
if (n >= max)
|
|
92
123
|
throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);
|
|
93
124
|
carry = carry << from | n;
|
|
94
125
|
if (pos + from > 32)
|
|
@@ -96,12 +127,15 @@ function convertRadix2(data, from, to, padding) {
|
|
|
96
127
|
pos += from;
|
|
97
128
|
for (; pos >= to; pos -= to)
|
|
98
129
|
res.push((carry >> pos - to & mask) >>> 0);
|
|
99
|
-
|
|
130
|
+
const pow = powers[pos];
|
|
131
|
+
if (pow === void 0)
|
|
132
|
+
throw new Error("invalid carry");
|
|
133
|
+
carry &= pow - 1;
|
|
100
134
|
}
|
|
101
135
|
carry = carry << to - pos & mask;
|
|
102
136
|
if (!padding && pos >= from)
|
|
103
137
|
throw new Error("Excess padding");
|
|
104
|
-
if (!padding && carry)
|
|
138
|
+
if (!padding && carry > 0)
|
|
105
139
|
throw new Error(`Non-zero padding: ${carry}`);
|
|
106
140
|
if (padding && pos > 0)
|
|
107
141
|
res.push(carry >>> 0);
|
|
@@ -109,7 +143,7 @@ function convertRadix2(data, from, to, padding) {
|
|
|
109
143
|
}
|
|
110
144
|
// @__NO_SIDE_EFFECTS__
|
|
111
145
|
function radix2(bits, revPadding = false) {
|
|
112
|
-
|
|
146
|
+
anumber(bits);
|
|
113
147
|
if (bits <= 0 || bits > 32)
|
|
114
148
|
throw new Error("radix2: bits should be in (0..32]");
|
|
115
149
|
if (/* @__PURE__ */ radix2carry(8, bits) > 32 || /* @__PURE__ */ radix2carry(bits, 8) > 32)
|
|
@@ -118,19 +152,16 @@ function radix2(bits, revPadding = false) {
|
|
|
118
152
|
encode: (bytes) => {
|
|
119
153
|
if (!isBytes(bytes))
|
|
120
154
|
throw new Error("radix2.encode input should be Uint8Array");
|
|
121
|
-
return
|
|
155
|
+
return convertRadix2(Array.from(bytes), 8, bits, !revPadding);
|
|
122
156
|
},
|
|
123
157
|
decode: (digits) => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return Uint8Array.from(/* @__PURE__ */ convertRadix2(digits, bits, 8, revPadding));
|
|
158
|
+
anumArr("radix2.decode", digits);
|
|
159
|
+
return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));
|
|
127
160
|
}
|
|
128
161
|
};
|
|
129
162
|
}
|
|
130
|
-
// @__NO_SIDE_EFFECTS__
|
|
131
163
|
function unsafeWrapper(fn) {
|
|
132
|
-
|
|
133
|
-
throw new Error("unsafeWrapper fn should be function");
|
|
164
|
+
afn(fn);
|
|
134
165
|
return function(...args) {
|
|
135
166
|
try {
|
|
136
167
|
return fn.apply(null, args);
|
|
@@ -140,7 +171,6 @@ function unsafeWrapper(fn) {
|
|
|
140
171
|
}
|
|
141
172
|
var BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join(""));
|
|
142
173
|
var POLYMOD_GENERATORS = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
143
|
-
// @__NO_SIDE_EFFECTS__
|
|
144
174
|
function bech32Polymod(pre) {
|
|
145
175
|
const b = pre >> 25;
|
|
146
176
|
let chk = (pre & 33554431) << 5;
|
|
@@ -150,7 +180,6 @@ function bech32Polymod(pre) {
|
|
|
150
180
|
}
|
|
151
181
|
return chk;
|
|
152
182
|
}
|
|
153
|
-
// @__NO_SIDE_EFFECTS__
|
|
154
183
|
function bechChecksum(prefix, words, encodingConst = 1) {
|
|
155
184
|
const len = prefix.length;
|
|
156
185
|
let chk = 1;
|
|
@@ -158,17 +187,17 @@ function bechChecksum(prefix, words, encodingConst = 1) {
|
|
|
158
187
|
const c = prefix.charCodeAt(i);
|
|
159
188
|
if (c < 33 || c > 126)
|
|
160
189
|
throw new Error(`Invalid prefix (${prefix})`);
|
|
161
|
-
chk =
|
|
190
|
+
chk = bech32Polymod(chk) ^ c >> 5;
|
|
162
191
|
}
|
|
163
|
-
chk =
|
|
192
|
+
chk = bech32Polymod(chk);
|
|
164
193
|
for (let i = 0; i < len; i++)
|
|
165
|
-
chk =
|
|
194
|
+
chk = bech32Polymod(chk) ^ prefix.charCodeAt(i) & 31;
|
|
166
195
|
for (let v of words)
|
|
167
|
-
chk =
|
|
196
|
+
chk = bech32Polymod(chk) ^ v;
|
|
168
197
|
for (let i = 0; i < 6; i++)
|
|
169
|
-
chk =
|
|
198
|
+
chk = bech32Polymod(chk);
|
|
170
199
|
chk ^= encodingConst;
|
|
171
|
-
return BECH_ALPHABET.encode(
|
|
200
|
+
return BECH_ALPHABET.encode(convertRadix2([chk % powers[30]], 30, 5, false));
|
|
172
201
|
}
|
|
173
202
|
// @__NO_SIDE_EFFECTS__
|
|
174
203
|
function genBech32(encoding) {
|
|
@@ -176,28 +205,27 @@ function genBech32(encoding) {
|
|
|
176
205
|
const _words = /* @__PURE__ */ radix2(5);
|
|
177
206
|
const fromWords = _words.decode;
|
|
178
207
|
const toWords = _words.encode;
|
|
179
|
-
const fromWordsUnsafe =
|
|
208
|
+
const fromWordsUnsafe = unsafeWrapper(fromWords);
|
|
180
209
|
function encode(prefix, words, limit = 90) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (words instanceof Uint8Array)
|
|
210
|
+
astr("bech32.encode prefix", prefix);
|
|
211
|
+
if (isBytes(words))
|
|
184
212
|
words = Array.from(words);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (
|
|
188
|
-
throw new TypeError(`Invalid prefix length ${
|
|
189
|
-
const actualLength =
|
|
213
|
+
anumArr("bech32.encode", words);
|
|
214
|
+
const plen = prefix.length;
|
|
215
|
+
if (plen === 0)
|
|
216
|
+
throw new TypeError(`Invalid prefix length ${plen}`);
|
|
217
|
+
const actualLength = plen + 7 + words.length;
|
|
190
218
|
if (limit !== false && actualLength > limit)
|
|
191
219
|
throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`);
|
|
192
220
|
const lowered = prefix.toLowerCase();
|
|
193
|
-
const sum =
|
|
221
|
+
const sum = bechChecksum(lowered, words, ENCODING_CONST);
|
|
194
222
|
return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}`;
|
|
195
223
|
}
|
|
196
224
|
function decode(str, limit = 90) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (
|
|
200
|
-
throw new TypeError(`
|
|
225
|
+
astr("bech32.decode input", str);
|
|
226
|
+
const slen = str.length;
|
|
227
|
+
if (slen < 8 || limit !== false && slen > limit)
|
|
228
|
+
throw new TypeError(`invalid string length: ${slen} (${str}). Expected (8..${limit})`);
|
|
201
229
|
const lowered = str.toLowerCase();
|
|
202
230
|
if (str !== lowered && str !== str.toUpperCase())
|
|
203
231
|
throw new Error(`String must be lowercase or uppercase`);
|
|
@@ -209,12 +237,12 @@ function genBech32(encoding) {
|
|
|
209
237
|
if (data.length < 6)
|
|
210
238
|
throw new Error("Data must be at least 6 characters long");
|
|
211
239
|
const words = BECH_ALPHABET.decode(data).slice(0, -6);
|
|
212
|
-
const sum =
|
|
240
|
+
const sum = bechChecksum(prefix, words, ENCODING_CONST);
|
|
213
241
|
if (!data.endsWith(sum))
|
|
214
242
|
throw new Error(`Invalid checksum in ${str}: expected "${sum}"`);
|
|
215
243
|
return { prefix, words };
|
|
216
244
|
}
|
|
217
|
-
const decodeUnsafe =
|
|
245
|
+
const decodeUnsafe = unsafeWrapper(decode);
|
|
218
246
|
function decodeToBytes(str) {
|
|
219
247
|
const { prefix, words } = decode(str, false);
|
|
220
248
|
return { prefix, words, bytes: fromWords(words) };
|
|
@@ -826,6 +854,9 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
826
854
|
async signData(payload, address) {
|
|
827
855
|
if (address === void 0) {
|
|
828
856
|
address = (await this.getUsedAddresses())[0];
|
|
857
|
+
if (address === void 0) {
|
|
858
|
+
address = await this.getChangeAddress();
|
|
859
|
+
}
|
|
829
860
|
}
|
|
830
861
|
if (address.startsWith("drep1")) {
|
|
831
862
|
return this._walletInstance.cip95.signData(address, fromUTF8(payload));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/wallet",
|
|
3
|
-
"version": "1.7.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.7.21",
|
|
4
|
+
"description": "Wallets - https://meshjs.dev/apis/wallets",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"browser": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"typescript": "^5.3.3"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@meshsdk/common": "1.7.
|
|
39
|
-
"@meshsdk/core-csl": "1.7.
|
|
40
|
-
"@meshsdk/core-cst": "1.7.
|
|
41
|
-
"@meshsdk/transaction": "1.7.
|
|
38
|
+
"@meshsdk/common": "1.7.21",
|
|
39
|
+
"@meshsdk/core-csl": "1.7.21",
|
|
40
|
+
"@meshsdk/core-cst": "1.7.21",
|
|
41
|
+
"@meshsdk/transaction": "1.7.21",
|
|
42
42
|
"@nufi/dapp-client-cardano": "0.3.5",
|
|
43
43
|
"@nufi/dapp-client-core": "0.3.5"
|
|
44
44
|
},
|