@solana/addresses 2.0.0-experimental.f4281a5 → 2.0.0-experimental.f45e92a

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.
@@ -1,12 +1,38 @@
1
- import { Base58EncodedAddress } from './base58';
2
- type PDAInput = Readonly<{
3
- programAddress: Base58EncodedAddress;
1
+ import { Address } from './address.js';
2
+ /**
3
+ * An address derived from a program address and a set of seeds.
4
+ * It includes the bump seed used to derive the address and
5
+ * ensure the address is not on the Ed25519 curve.
6
+ */
7
+ export type ProgramDerivedAddress<TAddress extends string = string> = Readonly<[
8
+ Address<TAddress>,
9
+ ProgramDerivedAddressBump
10
+ ]>;
11
+ /**
12
+ * A number between 0 and 255, inclusive.
13
+ */
14
+ export type ProgramDerivedAddressBump = number & {
15
+ readonly __brand: unique symbol;
16
+ };
17
+ /**
18
+ * Returns true if the input value is a program derived address.
19
+ */
20
+ export declare function isProgramDerivedAddress<TAddress extends string = string>(value: unknown): value is ProgramDerivedAddress<TAddress>;
21
+ /**
22
+ * Fails if the input value is not a program derived address.
23
+ */
24
+ export declare function assertIsProgramDerivedAddress<TAddress extends string = string>(value: unknown): asserts value is ProgramDerivedAddress<TAddress>;
25
+ type ProgramDerivedAddressInput = Readonly<{
26
+ programAddress: Address;
4
27
  seeds: Seed[];
5
28
  }>;
29
+ type SeedInput = Readonly<{
30
+ baseAddress: Address;
31
+ programAddress: Address;
32
+ seed: Seed;
33
+ }>;
6
34
  type Seed = string | Uint8Array;
7
- export declare function getProgramDerivedAddress({ programAddress, seeds }: PDAInput): Promise<Readonly<{
8
- bumpSeed: number;
9
- pda: Base58EncodedAddress;
10
- }>>;
35
+ export declare function getProgramDerivedAddress({ programAddress, seeds, }: ProgramDerivedAddressInput): Promise<ProgramDerivedAddress>;
36
+ export declare function createAddressWithSeed({ baseAddress, programAddress, seed }: SeedInput): Promise<Address>;
11
37
  export {};
12
38
  //# sourceMappingURL=program-derived-address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program-derived-address.d.ts","sourceRoot":"","sources":["../../src/program-derived-address.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAA+C,MAAM,WAAW,CAAC;AAGjF;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,QAAQ,CAC1E;IAAC,OAAO,CAAC,QAAQ,CAAC;IAAE,yBAAyB;CAAC,CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,MAAM,GAAG;IAC7C,QAAQ,CAAC,OAAO,EAAE,OAAO,MAAM,CAAC;CACnC,CAAC;AAEF;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,EACpE,KAAK,EAAE,OAAO,GACf,KAAK,IAAI,qBAAqB,CAAC,QAAQ,CAAC,CAU1C;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAC1E,KAAK,EAAE,OAAO,GACf,OAAO,CAAC,KAAK,IAAI,qBAAqB,CAAC,QAAQ,CAAC,CAclD;AAED,KAAK,0BAA0B,GAAG,QAAQ,CAAC;IACvC,cAAc,EAAE,OAAO,CAAC;IACxB,KAAK,EAAE,IAAI,EAAE,CAAC;CACjB,CAAC,CAAC;AAEH,KAAK,SAAS,GAAG,QAAQ,CAAC;IACtB,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,OAAO,CAAC;IACxB,IAAI,EAAE,IAAI,CAAC;CACd,CAAC,CAAC;AAEH,KAAK,IAAI,GAAG,MAAM,GAAG,UAAU,CAAC;AA0ChC,wBAAsB,wBAAwB,CAAC,EAC3C,cAAc,EACd,KAAK,GACR,EAAE,0BAA0B,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAmB7D;AAED,wBAAsB,qBAAqB,CAAC,EAAE,WAAW,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAyB9G"}
@@ -1,3 +1,3 @@
1
- import { Base58EncodedAddress } from './base58';
2
- export declare function getAddressFromPublicKey(publicKey: CryptoKey): Promise<Base58EncodedAddress>;
1
+ import { Address } from './address.js';
2
+ export declare function getAddressFromPublicKey(publicKey: CryptoKey): Promise<Address>;
3
3
  //# sourceMappingURL=public-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-key.d.ts","sourceRoot":"","sources":["../../src/public-key.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAqB,MAAM,WAAW,CAAC;AAEvD,wBAAsB,uBAAuB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAQpF"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ed25519.d.ts","sourceRoot":"","sources":["../../../../src/vendor/noble/ed25519.ts"],"names":[],"mappings":"AAgFA,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAanE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/addresses",
3
- "version": "2.0.0-experimental.f4281a5",
3
+ "version": "2.0.0-experimental.f45e92a",
4
4
  "description": "Helpers for generating account addresses",
5
5
  "exports": {
6
6
  "browser": {
@@ -49,30 +49,9 @@
49
49
  "node": ">=17.4"
50
50
  },
51
51
  "dependencies": {
52
- "@metaplex-foundation/umi-serializers": "^0.8.5",
53
- "@solana/assertions": "2.0.0-experimental.f4281a5"
54
- },
55
- "devDependencies": {
56
- "@solana/eslint-config-solana": "^1.0.2",
57
- "@swc/jest": "^0.2.28",
58
- "@types/jest": "^29.5.3",
59
- "@typescript-eslint/eslint-plugin": "^6.3.0",
60
- "@typescript-eslint/parser": "^6.3.0",
61
- "agadoo": "^3.0.0",
62
- "eslint": "^8.45.0",
63
- "eslint-plugin-jest": "^27.2.3",
64
- "eslint-plugin-sort-keys-fix": "^1.1.2",
65
- "jest": "^29.6.1",
66
- "jest-environment-jsdom": "^29.6.4",
67
- "jest-runner-eslint": "^2.1.0",
68
- "jest-runner-prettier": "^1.0.0",
69
- "prettier": "^2.8",
70
- "tsup": "7.2.0",
71
- "typescript": "^5.1.6",
72
- "version-from-git": "^1.1.1",
73
- "build-scripts": "0.0.0",
74
- "test-config": "0.0.0",
75
- "tsconfig": "0.0.0"
52
+ "@solana/assertions": "2.0.0-experimental.f45e92a",
53
+ "@solana/codecs-core": "2.0.0-experimental.f45e92a",
54
+ "@solana/codecs-strings": "2.0.0-experimental.f45e92a"
76
55
  },
77
56
  "bundlewatch": {
78
57
  "defaultCompression": "gzip",
@@ -83,17 +62,19 @@
83
62
  ]
84
63
  },
85
64
  "scripts": {
86
- "compile:js": "tsup --config build-scripts/tsup.config.library.ts",
87
- "compile:typedefs": "tsc -p ./tsconfig.declarations.json",
88
- "dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
89
- "publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
90
- "test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
91
- "test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
65
+ "compile:js": "tsup --config build-scripts/tsup.config.package.ts",
66
+ "compile:typedefs": "tsc -p ./tsconfig.declarations.json && node node_modules/@solana/build-scripts/add-js-extension-to-types.mjs",
67
+ "dev": "jest -c node_modules/@solana/test-config/jest-dev.config.ts --rootDir . --watch",
68
+ "publish-impl": "npm view $npm_package_name@$npm_package_version > /dev/null 2>&1 || pnpm publish --tag experimental --access public --no-git-checks",
69
+ "publish-packages": "pnpm prepublishOnly && pnpm publish-impl",
70
+ "style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
71
+ "test:lint": "jest -c node_modules/@solana/test-config/jest-lint.config.ts --rootDir . --silent",
72
+ "test:prettier": "jest -c node_modules/@solana/test-config/jest-prettier.config.ts --rootDir . --silent",
92
73
  "test:treeshakability:browser": "agadoo dist/index.browser.js",
93
- "test:treeshakability:native": "agadoo dist/index.node.js",
94
- "test:treeshakability:node": "agadoo dist/index.native.js",
74
+ "test:treeshakability:native": "agadoo dist/index.native.js",
75
+ "test:treeshakability:node": "agadoo dist/index.node.js",
95
76
  "test:typecheck": "tsc --noEmit",
96
- "test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent",
97
- "test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --rootDir . --silent"
77
+ "test:unit:browser": "jest -c node_modules/@solana/test-config/jest-unit.config.browser.ts --rootDir . --silent",
78
+ "test:unit:node": "jest -c node_modules/@solana/test-config/jest-unit.config.node.ts --rootDir . --silent"
98
79
  }
99
80
  }
@@ -1,517 +0,0 @@
1
- this.globalThis = this.globalThis || {};
2
- this.globalThis.solanaWeb3 = (function (exports) {
3
- 'use strict';
4
-
5
- var __defProp = Object.defineProperty;
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;
10
- };
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;
29
- };
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");
37
- }
38
- };
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");
43
- }
44
- };
45
-
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);
57
- }
58
- if (serializer.fixedSize !== null) {
59
- buffer = fixBytes(buffer, serializer.fixedSize);
60
- }
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);
88
- }
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;
103
- }
104
- const tailBytes = [];
105
- while (base10Number > 0n) {
106
- tailBytes.unshift(Number(base10Number % 256n));
107
- base10Number /= 256n;
108
- }
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;
125
- }
126
- return [leadingZeroes + tailChars.join(""), buffer.length];
127
- }
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];
151
- }
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
- };
168
-
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);
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
221
- });
222
-
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
- }
268
-
269
- // src/base58.ts
270
- function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
271
- try {
272
- if (
273
- // Lowest address (32 bytes of zeroes)
274
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
275
- putativeBase58EncodedAddress.length > 44
276
- ) {
277
- throw new Error("Expected input string to decode to a byte array of length 32.");
278
- }
279
- const bytes = base58.serialize(putativeBase58EncodedAddress);
280
- const numBytes = bytes.byteLength;
281
- if (numBytes !== 32) {
282
- throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
283
- }
284
- } catch (e) {
285
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
286
- cause: e
287
- });
288
- }
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
- }
297
- function getBase58EncodedAddressComparator() {
298
- return new Intl.Collator("en", {
299
- caseFirst: "lower",
300
- ignorePunctuation: false,
301
- localeMatcher: "best fit",
302
- numeric: false,
303
- sensitivity: "variant",
304
- usage: "sort"
305
- }).compare;
306
- }
307
-
308
- // ../assertions/dist/index.browser.js
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
- async function assertDigestCapabilityIsAvailable() {
317
- assertIsSecureContext();
318
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
319
- throw new Error("No digest implementation could be found");
320
- }
321
- }
322
- async function assertKeyExporterIsAvailable() {
323
- assertIsSecureContext();
324
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
325
- throw new Error("No key export implementation could be found");
326
- }
327
- }
328
-
329
- // src/vendor/noble/ed25519.ts
330
- var D = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;
331
- var P = 57896044618658097711785492504343953926634992332820282019728792003956564819949n;
332
- var RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
333
- function mod(a) {
334
- const r = a % P;
335
- return r >= 0n ? r : P + r;
336
- }
337
- function pow2(x, power) {
338
- let r = x;
339
- while (power-- > 0n) {
340
- r *= r;
341
- r %= P;
342
- }
343
- return r;
344
- }
345
- function pow_2_252_3(x) {
346
- const x2 = x * x % P;
347
- const b2 = x2 * x % P;
348
- const b4 = pow2(b2, 2n) * b2 % P;
349
- const b5 = pow2(b4, 1n) * x % P;
350
- const b10 = pow2(b5, 5n) * b5 % P;
351
- const b20 = pow2(b10, 10n) * b10 % P;
352
- const b40 = pow2(b20, 20n) * b20 % P;
353
- const b80 = pow2(b40, 40n) * b40 % P;
354
- const b160 = pow2(b80, 80n) * b80 % P;
355
- const b240 = pow2(b160, 80n) * b80 % P;
356
- const b250 = pow2(b240, 10n) * b10 % P;
357
- const pow_p_5_8 = pow2(b250, 2n) * x % P;
358
- return pow_p_5_8;
359
- }
360
- function uvRatio(u, v) {
361
- const v3 = mod(v * v * v);
362
- const v7 = mod(v3 * v3 * v);
363
- const pow = pow_2_252_3(u * v7);
364
- let x = mod(u * v3 * pow);
365
- const vx2 = mod(v * x * x);
366
- const root1 = x;
367
- const root2 = mod(x * RM1);
368
- const useRoot1 = vx2 === u;
369
- const useRoot2 = vx2 === mod(-u);
370
- const noRoot = vx2 === mod(-u * RM1);
371
- if (useRoot1)
372
- x = root1;
373
- if (useRoot2 || noRoot)
374
- x = root2;
375
- if ((mod(x) & 1n) === 1n)
376
- x = mod(-x);
377
- if (!useRoot1 && !useRoot2) {
378
- return null;
379
- }
380
- return x;
381
- }
382
- function pointIsOnCurve(y, lastByte) {
383
- const y2 = mod(y * y);
384
- const u = mod(y2 - 1n);
385
- const v = mod(D * y2 + 1n);
386
- const x = uvRatio(u, v);
387
- if (x === null) {
388
- return false;
389
- }
390
- const isLastByteOdd = (lastByte & 128) !== 0;
391
- if (x === 0n && isLastByteOdd) {
392
- return false;
393
- }
394
- return true;
395
- }
396
-
397
- // src/curve.ts
398
- function byteToHex(byte) {
399
- const hexString = byte.toString(16);
400
- if (hexString.length === 1) {
401
- return `0${hexString}`;
402
- } else {
403
- return hexString;
404
- }
405
- }
406
- function decompressPointBytes(bytes) {
407
- const hexString = bytes.reduce((acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~128 : byte)}${acc}`, "");
408
- const integerLiteralString = `0x${hexString}`;
409
- return BigInt(integerLiteralString);
410
- }
411
- async function compressedPointBytesAreOnCurve(bytes) {
412
- if (bytes.byteLength !== 32) {
413
- return false;
414
- }
415
- const y = decompressPointBytes(bytes);
416
- return pointIsOnCurve(y, bytes[31]);
417
- }
418
-
419
- // src/program-derived-address.ts
420
- var MAX_SEED_LENGTH = 32;
421
- var MAX_SEEDS = 16;
422
- var PDA_MARKER_BYTES = [
423
- // The string 'ProgramDerivedAddress'
424
- 80,
425
- 114,
426
- 111,
427
- 103,
428
- 114,
429
- 97,
430
- 109,
431
- 68,
432
- 101,
433
- 114,
434
- 105,
435
- 118,
436
- 101,
437
- 100,
438
- 65,
439
- 100,
440
- 100,
441
- 114,
442
- 101,
443
- 115,
444
- 115
445
- ];
446
- var PointOnCurveError = class extends Error {
447
- };
448
- async function createProgramDerivedAddress({ programAddress, seeds }) {
449
- await assertDigestCapabilityIsAvailable();
450
- if (seeds.length > MAX_SEEDS) {
451
- throw new Error(`A maximum of ${MAX_SEEDS} seeds may be supplied when creating an address`);
452
- }
453
- let textEncoder;
454
- const seedBytes = seeds.reduce((acc, seed, ii) => {
455
- const bytes = typeof seed === "string" ? (textEncoder || (textEncoder = new TextEncoder())).encode(seed) : seed;
456
- if (bytes.byteLength > MAX_SEED_LENGTH) {
457
- throw new Error(`The seed at index ${ii} exceeds the maximum length of 32 bytes`);
458
- }
459
- acc.push(...bytes);
460
- return acc;
461
- }, []);
462
- const base58EncodedAddressCodec = getBase58EncodedAddressCodec();
463
- const programAddressBytes = base58EncodedAddressCodec.serialize(programAddress);
464
- const addressBytesBuffer = await crypto.subtle.digest(
465
- "SHA-256",
466
- new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
467
- );
468
- const addressBytes = new Uint8Array(addressBytesBuffer);
469
- if (await compressedPointBytesAreOnCurve(addressBytes)) {
470
- throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
471
- }
472
- return base58EncodedAddressCodec.deserialize(addressBytes)[0];
473
- }
474
- async function getProgramDerivedAddress({ programAddress, seeds }) {
475
- let bumpSeed = 255;
476
- while (bumpSeed > 0) {
477
- try {
478
- return {
479
- bumpSeed,
480
- pda: await createProgramDerivedAddress({
481
- programAddress,
482
- seeds: [...seeds, new Uint8Array([bumpSeed])]
483
- })
484
- };
485
- } catch (e) {
486
- if (e instanceof PointOnCurveError) {
487
- bumpSeed--;
488
- } else {
489
- throw e;
490
- }
491
- }
492
- }
493
- throw new Error("Unable to find a viable program address bump seed");
494
- }
495
-
496
- // src/public-key.ts
497
- async function getAddressFromPublicKey(publicKey) {
498
- await assertKeyExporterIsAvailable();
499
- if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
500
- throw new Error("The `CryptoKey` must be an `Ed25519` public key");
501
- }
502
- const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
503
- const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
504
- return base58EncodedAddress;
505
- }
506
-
507
- exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
508
- exports.getAddressFromPublicKey = getAddressFromPublicKey;
509
- exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
510
- exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
511
- exports.getProgramDerivedAddress = getProgramDerivedAddress;
512
-
513
- return exports;
514
-
515
- })({});
516
- //# sourceMappingURL=out.js.map
517
- //# sourceMappingURL=index.development.js.map