@solana/keys 2.0.0-experimental.eefafdf → 2.0.0-experimental.f07dced
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/README.md +51 -1
- package/dist/index.browser.cjs +114 -7
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +110 -4
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +355 -162
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +97 -4
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +101 -7
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +97 -4
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +12 -3
- package/dist/types/base58.d.ts +4 -0
- package/dist/types/guard.d.ts +5 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/key-pair.d.ts +2 -0
- package/dist/types/pubkey.d.ts +3 -0
- package/dist/types/signatures.d.ts +6 -0
- package/package.json +16 -13
|
@@ -2,188 +2,271 @@ this.globalThis = this.globalThis || {};
|
|
|
2
2
|
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
var __create = Object.create;
|
|
6
5
|
var __defProp = Object.defineProperty;
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var __esm = (fn, res) => function __init() {
|
|
12
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __publicField = (obj, key, value) => {
|
|
8
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9
|
+
return value;
|
|
13
10
|
};
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
|
|
12
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
|
|
13
|
+
var mergeBytes = (bytesArr) => {
|
|
14
|
+
const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
|
|
15
|
+
const result = new Uint8Array(totalLength);
|
|
16
|
+
let offset = 0;
|
|
17
|
+
bytesArr.forEach((arr) => {
|
|
18
|
+
result.set(arr, offset);
|
|
19
|
+
offset += arr.length;
|
|
20
|
+
});
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
var padBytes = (bytes, length) => {
|
|
24
|
+
if (bytes.length >= length)
|
|
25
|
+
return bytes;
|
|
26
|
+
const paddedBytes = new Uint8Array(length).fill(0);
|
|
27
|
+
paddedBytes.set(bytes);
|
|
28
|
+
return paddedBytes;
|
|
16
29
|
};
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
var fixBytes = (bytes, length) => padBytes(bytes.slice(0, length), length);
|
|
31
|
+
|
|
32
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
|
|
33
|
+
var DeserializingEmptyBufferError = class extends Error {
|
|
34
|
+
constructor(serializer) {
|
|
35
|
+
super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
|
|
36
|
+
__publicField(this, "name", "DeserializingEmptyBufferError");
|
|
22
37
|
}
|
|
23
|
-
return to;
|
|
24
38
|
};
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
-
mod
|
|
32
|
-
));
|
|
33
|
-
|
|
34
|
-
// ../build-scripts/env-shim.ts
|
|
35
|
-
var init_env_shim = __esm({
|
|
36
|
-
"../build-scripts/env-shim.ts"() {
|
|
39
|
+
var NotEnoughBytesError = class extends Error {
|
|
40
|
+
constructor(serializer, expected, actual) {
|
|
41
|
+
super(`Serializer [${serializer}] expected ${expected} bytes, got ${actual}.`);
|
|
42
|
+
__publicField(this, "name", "NotEnoughBytesError");
|
|
37
43
|
}
|
|
38
|
-
}
|
|
44
|
+
};
|
|
39
45
|
|
|
40
|
-
// ../../node_modules/.pnpm
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
|
|
47
|
+
function fixSerializer(serializer, fixedBytes, description) {
|
|
48
|
+
return {
|
|
49
|
+
description: description ?? `fixed(${fixedBytes}, ${serializer.description})`,
|
|
50
|
+
fixedSize: fixedBytes,
|
|
51
|
+
maxSize: fixedBytes,
|
|
52
|
+
serialize: (value) => fixBytes(serializer.serialize(value), fixedBytes),
|
|
53
|
+
deserialize: (buffer, offset = 0) => {
|
|
54
|
+
buffer = buffer.slice(offset, offset + fixedBytes);
|
|
55
|
+
if (buffer.length < fixedBytes) {
|
|
56
|
+
throw new NotEnoughBytesError("fixSerializer", fixedBytes, buffer.length);
|
|
47
57
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
BASE_MAP[j] = 255;
|
|
58
|
+
if (serializer.fixedSize !== null) {
|
|
59
|
+
buffer = fixBytes(buffer, serializer.fixedSize);
|
|
51
60
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
const [value] = serializer.deserialize(buffer, 0);
|
|
62
|
+
return [value, offset + fixedBytes];
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
|
|
68
|
+
var InvalidBaseStringError = class extends Error {
|
|
69
|
+
constructor(value, base, cause) {
|
|
70
|
+
const message = `Expected a string of base ${base}, got [${value}].`;
|
|
71
|
+
super(message);
|
|
72
|
+
__publicField(this, "name", "InvalidBaseStringError");
|
|
73
|
+
this.cause = cause;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
|
|
78
|
+
var baseX = (alphabet) => {
|
|
79
|
+
const base = alphabet.length;
|
|
80
|
+
const baseBigInt = BigInt(base);
|
|
81
|
+
return {
|
|
82
|
+
description: `base${base}`,
|
|
83
|
+
fixedSize: null,
|
|
84
|
+
maxSize: null,
|
|
85
|
+
serialize(value) {
|
|
86
|
+
if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
|
|
87
|
+
throw new InvalidBaseStringError(value, base);
|
|
59
88
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return "";
|
|
75
|
-
}
|
|
76
|
-
var zeroes = 0;
|
|
77
|
-
var length = 0;
|
|
78
|
-
var pbegin = 0;
|
|
79
|
-
var pend = source.length;
|
|
80
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
81
|
-
pbegin++;
|
|
82
|
-
zeroes++;
|
|
83
|
-
}
|
|
84
|
-
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
85
|
-
var b58 = new Uint8Array(size);
|
|
86
|
-
while (pbegin !== pend) {
|
|
87
|
-
var carry = source[pbegin];
|
|
88
|
-
var i2 = 0;
|
|
89
|
-
for (var it1 = size - 1; (carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) {
|
|
90
|
-
carry += 256 * b58[it1] >>> 0;
|
|
91
|
-
b58[it1] = carry % BASE >>> 0;
|
|
92
|
-
carry = carry / BASE >>> 0;
|
|
93
|
-
}
|
|
94
|
-
if (carry !== 0) {
|
|
95
|
-
throw new Error("Non-zero carry");
|
|
96
|
-
}
|
|
97
|
-
length = i2;
|
|
98
|
-
pbegin++;
|
|
99
|
-
}
|
|
100
|
-
var it2 = size - length;
|
|
101
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
102
|
-
it2++;
|
|
103
|
-
}
|
|
104
|
-
var str = LEADER.repeat(zeroes);
|
|
105
|
-
for (; it2 < size; ++it2) {
|
|
106
|
-
str += ALPHABET.charAt(b58[it2]);
|
|
107
|
-
}
|
|
108
|
-
return str;
|
|
89
|
+
if (value === "")
|
|
90
|
+
return new Uint8Array();
|
|
91
|
+
const chars = [...value];
|
|
92
|
+
let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
|
|
93
|
+
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
94
|
+
const leadingZeroes = Array(trailIndex).fill(0);
|
|
95
|
+
if (trailIndex === chars.length)
|
|
96
|
+
return Uint8Array.from(leadingZeroes);
|
|
97
|
+
const tailChars = chars.slice(trailIndex);
|
|
98
|
+
let base10Number = 0n;
|
|
99
|
+
let baseXPower = 1n;
|
|
100
|
+
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
101
|
+
base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
|
|
102
|
+
baseXPower *= baseBigInt;
|
|
109
103
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (source.length === 0) {
|
|
115
|
-
return new Uint8Array();
|
|
116
|
-
}
|
|
117
|
-
var psz = 0;
|
|
118
|
-
var zeroes = 0;
|
|
119
|
-
var length = 0;
|
|
120
|
-
while (source[psz] === LEADER) {
|
|
121
|
-
zeroes++;
|
|
122
|
-
psz++;
|
|
123
|
-
}
|
|
124
|
-
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
125
|
-
var b256 = new Uint8Array(size);
|
|
126
|
-
while (source[psz]) {
|
|
127
|
-
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
128
|
-
if (carry === 255) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
var i2 = 0;
|
|
132
|
-
for (var it3 = size - 1; (carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) {
|
|
133
|
-
carry += BASE * b256[it3] >>> 0;
|
|
134
|
-
b256[it3] = carry % 256 >>> 0;
|
|
135
|
-
carry = carry / 256 >>> 0;
|
|
136
|
-
}
|
|
137
|
-
if (carry !== 0) {
|
|
138
|
-
throw new Error("Non-zero carry");
|
|
139
|
-
}
|
|
140
|
-
length = i2;
|
|
141
|
-
psz++;
|
|
142
|
-
}
|
|
143
|
-
var it4 = size - length;
|
|
144
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
145
|
-
it4++;
|
|
146
|
-
}
|
|
147
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
148
|
-
var j2 = zeroes;
|
|
149
|
-
while (it4 !== size) {
|
|
150
|
-
vch[j2++] = b256[it4++];
|
|
151
|
-
}
|
|
152
|
-
return vch;
|
|
104
|
+
const tailBytes = [];
|
|
105
|
+
while (base10Number > 0n) {
|
|
106
|
+
tailBytes.unshift(Number(base10Number % 256n));
|
|
107
|
+
base10Number /= 256n;
|
|
153
108
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
109
|
+
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
110
|
+
},
|
|
111
|
+
deserialize(buffer, offset = 0) {
|
|
112
|
+
if (buffer.length === 0)
|
|
113
|
+
return ["", 0];
|
|
114
|
+
const bytes = buffer.slice(offset);
|
|
115
|
+
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
116
|
+
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
117
|
+
const leadingZeroes = alphabet[0].repeat(trailIndex);
|
|
118
|
+
if (trailIndex === bytes.length)
|
|
119
|
+
return [leadingZeroes, buffer.length];
|
|
120
|
+
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
121
|
+
const tailChars = [];
|
|
122
|
+
while (base10Number > 0n) {
|
|
123
|
+
tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
|
|
124
|
+
base10Number /= baseBigInt;
|
|
160
125
|
}
|
|
161
|
-
return
|
|
162
|
-
encode,
|
|
163
|
-
decodeUnsafe,
|
|
164
|
-
decode
|
|
165
|
-
};
|
|
126
|
+
return [leadingZeroes + tailChars.join(""), buffer.length];
|
|
166
127
|
}
|
|
167
|
-
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
|
|
132
|
+
var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
133
|
+
|
|
134
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
|
|
135
|
+
var removeNullCharacters = (value) => (
|
|
136
|
+
// eslint-disable-next-line no-control-regex
|
|
137
|
+
value.replace(/\u0000/g, "")
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
|
|
141
|
+
var utf8 = {
|
|
142
|
+
description: "utf8",
|
|
143
|
+
fixedSize: null,
|
|
144
|
+
maxSize: null,
|
|
145
|
+
serialize(value) {
|
|
146
|
+
return new TextEncoder().encode(value);
|
|
147
|
+
},
|
|
148
|
+
deserialize(buffer, offset = 0) {
|
|
149
|
+
const value = new TextDecoder().decode(buffer.slice(offset));
|
|
150
|
+
return [removeNullCharacters(value), buffer.length];
|
|
168
151
|
}
|
|
169
|
-
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
|
|
155
|
+
var Endian;
|
|
156
|
+
(function(Endian2) {
|
|
157
|
+
Endian2["Little"] = "le";
|
|
158
|
+
Endian2["Big"] = "be";
|
|
159
|
+
})(Endian || (Endian = {}));
|
|
160
|
+
|
|
161
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
|
|
162
|
+
var NumberOutOfRangeError = class extends RangeError {
|
|
163
|
+
constructor(serializer, min, max, actual) {
|
|
164
|
+
super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
|
|
165
|
+
__publicField(this, "name", "NumberOutOfRangeError");
|
|
166
|
+
}
|
|
167
|
+
};
|
|
170
168
|
|
|
171
|
-
// ../../node_modules/.pnpm
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
169
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
|
|
170
|
+
function numberFactory(input) {
|
|
171
|
+
let littleEndian;
|
|
172
|
+
let defaultDescription = input.name;
|
|
173
|
+
if (input.size > 1) {
|
|
174
|
+
littleEndian = !("endian" in input.options) || input.options.endian === Endian.Little;
|
|
175
|
+
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
description: input.options.description ?? defaultDescription,
|
|
179
|
+
fixedSize: input.size,
|
|
180
|
+
maxSize: input.size,
|
|
181
|
+
serialize(value) {
|
|
182
|
+
if (input.range) {
|
|
183
|
+
assertRange(input.name, input.range[0], input.range[1], value);
|
|
184
|
+
}
|
|
185
|
+
const buffer = new ArrayBuffer(input.size);
|
|
186
|
+
input.set(new DataView(buffer), value, littleEndian);
|
|
187
|
+
return new Uint8Array(buffer);
|
|
188
|
+
},
|
|
189
|
+
deserialize(bytes, offset = 0) {
|
|
190
|
+
const slice = bytes.slice(offset, offset + input.size);
|
|
191
|
+
assertEnoughBytes("i8", slice, input.size);
|
|
192
|
+
const view = toDataView(slice);
|
|
193
|
+
return [input.get(view, littleEndian), offset + input.size];
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
var toArrayBuffer = (array) => array.buffer.slice(array.byteOffset, array.byteLength + array.byteOffset);
|
|
198
|
+
var toDataView = (array) => new DataView(toArrayBuffer(array));
|
|
199
|
+
var assertRange = (serializer, min, max, value) => {
|
|
200
|
+
if (value < min || value > max) {
|
|
201
|
+
throw new NumberOutOfRangeError(serializer, min, max, value);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
var assertEnoughBytes = (serializer, bytes, expected) => {
|
|
205
|
+
if (bytes.length === 0) {
|
|
206
|
+
throw new DeserializingEmptyBufferError(serializer);
|
|
207
|
+
}
|
|
208
|
+
if (bytes.length < expected) {
|
|
209
|
+
throw new NotEnoughBytesError(serializer, expected, bytes.length);
|
|
178
210
|
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
|
|
214
|
+
var u32 = (options = {}) => numberFactory({
|
|
215
|
+
name: "u32",
|
|
216
|
+
size: 4,
|
|
217
|
+
range: [0, Number("0xffffffff")],
|
|
218
|
+
set: (view, value, le) => view.setUint32(0, Number(value), le),
|
|
219
|
+
get: (view, le) => view.getUint32(0, le),
|
|
220
|
+
options
|
|
179
221
|
});
|
|
180
222
|
|
|
181
|
-
//
|
|
182
|
-
|
|
223
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
|
|
224
|
+
function getSizeDescription(size) {
|
|
225
|
+
return typeof size === "object" ? size.description : `${size}`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
|
|
229
|
+
function string(options = {}) {
|
|
230
|
+
const size = options.size ?? u32();
|
|
231
|
+
const encoding = options.encoding ?? utf8;
|
|
232
|
+
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
233
|
+
if (size === "variable") {
|
|
234
|
+
return {
|
|
235
|
+
...encoding,
|
|
236
|
+
description
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if (typeof size === "number") {
|
|
240
|
+
return fixSerializer(encoding, size, description);
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
description,
|
|
244
|
+
fixedSize: null,
|
|
245
|
+
maxSize: null,
|
|
246
|
+
serialize: (value) => {
|
|
247
|
+
const contentBytes = encoding.serialize(value);
|
|
248
|
+
const lengthBytes = size.serialize(contentBytes.length);
|
|
249
|
+
return mergeBytes([lengthBytes, contentBytes]);
|
|
250
|
+
},
|
|
251
|
+
deserialize: (buffer, offset = 0) => {
|
|
252
|
+
if (buffer.slice(offset).length === 0) {
|
|
253
|
+
throw new DeserializingEmptyBufferError("string");
|
|
254
|
+
}
|
|
255
|
+
const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
|
|
256
|
+
const length = Number(lengthBigInt);
|
|
257
|
+
offset = lengthOffset;
|
|
258
|
+
const contentBuffer = buffer.slice(offset, offset + length);
|
|
259
|
+
if (contentBuffer.length < length) {
|
|
260
|
+
throw new NotEnoughBytesError("string", length, contentBuffer.length);
|
|
261
|
+
}
|
|
262
|
+
const [value, contentOffset] = encoding.deserialize(contentBuffer);
|
|
263
|
+
offset += contentOffset;
|
|
264
|
+
return [value, offset];
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}
|
|
183
268
|
|
|
184
269
|
// src/base58.ts
|
|
185
|
-
init_env_shim();
|
|
186
|
-
var import_bs58 = __toESM(require_bs58(), 1);
|
|
187
270
|
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
188
271
|
try {
|
|
189
272
|
if (
|
|
@@ -193,7 +276,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
193
276
|
) {
|
|
194
277
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
195
278
|
}
|
|
196
|
-
const bytes =
|
|
279
|
+
const bytes = base58.serialize(putativeBase58EncodedAddress);
|
|
197
280
|
const numBytes = bytes.byteLength;
|
|
198
281
|
if (numBytes !== 32) {
|
|
199
282
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
@@ -204,6 +287,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
204
287
|
});
|
|
205
288
|
}
|
|
206
289
|
}
|
|
290
|
+
function getBase58EncodedAddressCodec(config) {
|
|
291
|
+
return string({
|
|
292
|
+
description: config?.description ?? ("A 32-byte account address" ),
|
|
293
|
+
encoding: base58,
|
|
294
|
+
size: 32
|
|
295
|
+
});
|
|
296
|
+
}
|
|
207
297
|
function getBase58EncodedAddressComparator() {
|
|
208
298
|
return new Intl.Collator("en", {
|
|
209
299
|
caseFirst: "lower",
|
|
@@ -215,8 +305,111 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
215
305
|
}).compare;
|
|
216
306
|
}
|
|
217
307
|
|
|
308
|
+
// src/guard.ts
|
|
309
|
+
function assertIsSecureContext() {
|
|
310
|
+
if (!globalThis.isSecureContext) {
|
|
311
|
+
throw new Error(
|
|
312
|
+
"Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
var cachedEd25519Decision;
|
|
317
|
+
async function isEd25519CurveSupported(subtle) {
|
|
318
|
+
if (cachedEd25519Decision === void 0) {
|
|
319
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
320
|
+
subtle.generateKey(
|
|
321
|
+
"Ed25519",
|
|
322
|
+
/* extractable */
|
|
323
|
+
false,
|
|
324
|
+
["sign", "verify"]
|
|
325
|
+
).catch(() => {
|
|
326
|
+
resolve(cachedEd25519Decision = false);
|
|
327
|
+
}).then(() => {
|
|
328
|
+
resolve(cachedEd25519Decision = true);
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
333
|
+
return cachedEd25519Decision;
|
|
334
|
+
} else {
|
|
335
|
+
return await cachedEd25519Decision;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
async function assertKeyGenerationIsAvailable() {
|
|
339
|
+
assertIsSecureContext();
|
|
340
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
341
|
+
throw new Error("No key generation implementation could be found");
|
|
342
|
+
}
|
|
343
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
344
|
+
throw new Error(
|
|
345
|
+
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
async function assertKeyExporterIsAvailable() {
|
|
350
|
+
assertIsSecureContext();
|
|
351
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
|
|
352
|
+
throw new Error("No key export implementation could be found");
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
async function assertSigningCapabilityIsAvailable() {
|
|
356
|
+
assertIsSecureContext();
|
|
357
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
358
|
+
throw new Error("No signing implementation could be found");
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
async function assertVerificationCapabilityIsAvailable() {
|
|
362
|
+
assertIsSecureContext();
|
|
363
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
|
|
364
|
+
throw new Error("No signature verification implementation could be found");
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// src/key-pair.ts
|
|
369
|
+
async function generateKeyPair() {
|
|
370
|
+
await assertKeyGenerationIsAvailable();
|
|
371
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
372
|
+
/* algorithm */
|
|
373
|
+
"Ed25519",
|
|
374
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
375
|
+
/* extractable */
|
|
376
|
+
false,
|
|
377
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
378
|
+
/* allowed uses */
|
|
379
|
+
["sign", "verify"]
|
|
380
|
+
);
|
|
381
|
+
return keyPair;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// src/pubkey.ts
|
|
385
|
+
async function getBase58EncodedAddressFromPublicKey(publicKey) {
|
|
386
|
+
await assertKeyExporterIsAvailable();
|
|
387
|
+
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
|
|
388
|
+
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
|
|
389
|
+
}
|
|
390
|
+
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
|
|
391
|
+
const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
|
|
392
|
+
return base58EncodedAddress;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// src/signatures.ts
|
|
396
|
+
async function signBytes(key, data) {
|
|
397
|
+
await assertSigningCapabilityIsAvailable();
|
|
398
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
399
|
+
return new Uint8Array(signedData);
|
|
400
|
+
}
|
|
401
|
+
async function verifySignature(key, signature, data) {
|
|
402
|
+
await assertVerificationCapabilityIsAvailable();
|
|
403
|
+
return await crypto.subtle.verify("Ed25519", key, signature, data);
|
|
404
|
+
}
|
|
405
|
+
|
|
218
406
|
exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
|
|
407
|
+
exports.generateKeyPair = generateKeyPair;
|
|
408
|
+
exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
|
|
219
409
|
exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
|
|
410
|
+
exports.getBase58EncodedAddressFromPublicKey = getBase58EncodedAddressFromPublicKey;
|
|
411
|
+
exports.signBytes = signBytes;
|
|
412
|
+
exports.verifySignature = verifySignature;
|
|
220
413
|
|
|
221
414
|
return exports;
|
|
222
415
|
|