@solana/addresses 2.0.0-experimental.083193b

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2018 Solana Labs, Inc
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ [![npm][npm-image]][npm-url]
2
+ [![npm-downloads][npm-downloads-image]][npm-url]
3
+ [![semantic-release][semantic-release-image]][semantic-release-url]
4
+ <br />
5
+ [![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]
6
+
7
+ [code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
8
+ [code-style-prettier-url]: https://github.com/prettier/prettier
9
+ [npm-downloads-image]: https://img.shields.io/npm/dm/@solana/addresses/experimental.svg?style=flat
10
+ [npm-image]: https://img.shields.io/npm/v/@solana/addresses/experimental.svg?style=flat
11
+ [npm-url]: https://www.npmjs.com/package/@solana/addresses/v/experimental
12
+ [semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
13
+ [semantic-release-url]: https://github.com/semantic-release/semantic-release
14
+
15
+ # @solana/addresses
16
+
17
+ This package contains utilities for generating account addresses. It can be used standalone, but it is also exported as part of the Solana JavaScript SDK [`@solana/web3.js@experimental`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/library).
18
+
19
+ ## Types
20
+
21
+ ### `Base58EncodedAddress`
22
+
23
+ This type represents a string that validates as a Solana address. Functions that require well-formed addresses should specify their inputs in terms of this type.
24
+
25
+ Whenever you need to validate an arbitrary string as a base58-encoded address, use the `assertIsBase58EncodedAddress()` function in this package.
26
+
27
+ ## Functions
28
+
29
+ ### `assertIsBase58EncodedAddress()`
30
+
31
+ Client applications primarily deal with addresses and public keys in the form of base58-encoded strings. Addresses returned from the RPC API conform to the type `Base58EncodedAddress`. You can use a value of that type wherever a base58-encoded address is expected.
32
+
33
+ From time to time you might acquire a string, that you expect to validate as an address, from an untrusted network API or user input. To assert that such an arbitrary string is a base58-encoded address, use the `assertIsBase58EncodedAddress` function.
34
+
35
+ ```ts
36
+ import { assertIsBase58EncodedAddress } from '@solana/addresses';
37
+
38
+ // Imagine a function that fetches an account's balance when a user submits a form.
39
+ function handleSubmit() {
40
+ // We know only that what the user typed conforms to the `string` type.
41
+ const address: string = accountAddressInput.value;
42
+ try {
43
+ // If this type assertion function doesn't throw, then
44
+ // Typescript will upcast `address` to `Base58EncodedAddress`.
45
+ assertIsBase58EncodedAddress(address);
46
+ // At this point, `address` is a `Base58EncodedAddress` that can be used with the RPC.
47
+ const balanceInLamports = await rpc.getBalance(address).send();
48
+ } catch (e) {
49
+ // `address` turned out not to be a base58-encoded address
50
+ }
51
+ }
52
+ ```
53
+
54
+ ### `getBase58EncodedAddressFromPublicKey()`
55
+
56
+ Given a public `CryptoKey`, this method will return its associated `Base58EncodedAddress`.
57
+
58
+ ```ts
59
+ import { getBase58EncodedAddressFromPublicKey } from '@solana/addresses';
60
+
61
+ const address = await getBase58EncodedAddressFromPublicKey(publicKey);
62
+ ```
63
+
64
+ ### `getProgramDerivedAddress()`
65
+
66
+ Given a program's `Base58EncodedAddress` and up to 16 `Seeds`, this method will return the program derived address (PDA) associated with each.
67
+
68
+ ```ts
69
+ import { getBase58EncodedAddressCodec, getProgramDerivedAddress } from '@solana/addresses';
70
+
71
+ const { serialize } = getBase58EncodedAddressCodec();
72
+ const { bumpSeed, pda } = await getProgramDerivedAddress({
73
+ programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Base58EncodedAddress,
74
+ seeds: [
75
+ // Owner
76
+ serialize('9fYLFVoVqwH37C3dyPi6cpeobfbQ2jtLpN5HgAYDDdkm' as Base58EncodedAddress),
77
+ // Token program
78
+ serialize('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Base58EncodedAddress),
79
+ // Mint
80
+ serialize('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' as Base58EncodedAddress),
81
+ ],
82
+ });
83
+ ```
@@ -0,0 +1,228 @@
1
+ 'use strict';
2
+
3
+ var umiSerializers = require('@metaplex-foundation/umi-serializers');
4
+ var assertions = require('@solana/assertions');
5
+
6
+ // ../build-scripts/env-shim.ts
7
+ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
8
+ function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
9
+ try {
10
+ if (
11
+ // Lowest address (32 bytes of zeroes)
12
+ putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
13
+ putativeBase58EncodedAddress.length > 44
14
+ ) {
15
+ throw new Error("Expected input string to decode to a byte array of length 32.");
16
+ }
17
+ const bytes = umiSerializers.base58.serialize(putativeBase58EncodedAddress);
18
+ const numBytes = bytes.byteLength;
19
+ if (numBytes !== 32) {
20
+ throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
21
+ }
22
+ } catch (e) {
23
+ throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
24
+ cause: e
25
+ });
26
+ }
27
+ }
28
+ function getBase58EncodedAddressCodec(config) {
29
+ return umiSerializers.string({
30
+ description: config?.description ?? (__DEV__ ? "A 32-byte account address" : ""),
31
+ encoding: umiSerializers.base58,
32
+ size: 32
33
+ });
34
+ }
35
+ function getBase58EncodedAddressComparator() {
36
+ return new Intl.Collator("en", {
37
+ caseFirst: "lower",
38
+ ignorePunctuation: false,
39
+ localeMatcher: "best fit",
40
+ numeric: false,
41
+ sensitivity: "variant",
42
+ usage: "sort"
43
+ }).compare;
44
+ }
45
+
46
+ // src/vendor/noble/ed25519.ts
47
+ var D = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;
48
+ var P = 57896044618658097711785492504343953926634992332820282019728792003956564819949n;
49
+ var RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
50
+ function mod(a) {
51
+ const r = a % P;
52
+ return r >= 0n ? r : P + r;
53
+ }
54
+ function pow2(x, power) {
55
+ let r = x;
56
+ while (power-- > 0n) {
57
+ r *= r;
58
+ r %= P;
59
+ }
60
+ return r;
61
+ }
62
+ function pow_2_252_3(x) {
63
+ const x2 = x * x % P;
64
+ const b2 = x2 * x % P;
65
+ const b4 = pow2(b2, 2n) * b2 % P;
66
+ const b5 = pow2(b4, 1n) * x % P;
67
+ const b10 = pow2(b5, 5n) * b5 % P;
68
+ const b20 = pow2(b10, 10n) * b10 % P;
69
+ const b40 = pow2(b20, 20n) * b20 % P;
70
+ const b80 = pow2(b40, 40n) * b40 % P;
71
+ const b160 = pow2(b80, 80n) * b80 % P;
72
+ const b240 = pow2(b160, 80n) * b80 % P;
73
+ const b250 = pow2(b240, 10n) * b10 % P;
74
+ const pow_p_5_8 = pow2(b250, 2n) * x % P;
75
+ return pow_p_5_8;
76
+ }
77
+ function uvRatio(u, v) {
78
+ const v3 = mod(v * v * v);
79
+ const v7 = mod(v3 * v3 * v);
80
+ const pow = pow_2_252_3(u * v7);
81
+ let x = mod(u * v3 * pow);
82
+ const vx2 = mod(v * x * x);
83
+ const root1 = x;
84
+ const root2 = mod(x * RM1);
85
+ const useRoot1 = vx2 === u;
86
+ const useRoot2 = vx2 === mod(-u);
87
+ const noRoot = vx2 === mod(-u * RM1);
88
+ if (useRoot1)
89
+ x = root1;
90
+ if (useRoot2 || noRoot)
91
+ x = root2;
92
+ if ((mod(x) & 1n) === 1n)
93
+ x = mod(-x);
94
+ if (!useRoot1 && !useRoot2) {
95
+ return null;
96
+ }
97
+ return x;
98
+ }
99
+ function pointIsOnCurve(y, lastByte) {
100
+ const y2 = mod(y * y);
101
+ const u = mod(y2 - 1n);
102
+ const v = mod(D * y2 + 1n);
103
+ const x = uvRatio(u, v);
104
+ if (x === null) {
105
+ return false;
106
+ }
107
+ const isLastByteOdd = (lastByte & 128) !== 0;
108
+ if (x === 0n && isLastByteOdd) {
109
+ return false;
110
+ }
111
+ return true;
112
+ }
113
+
114
+ // src/curve.ts
115
+ function byteToHex(byte) {
116
+ const hexString = byte.toString(16);
117
+ if (hexString.length === 1) {
118
+ return `0${hexString}`;
119
+ } else {
120
+ return hexString;
121
+ }
122
+ }
123
+ function decompressPointBytes(bytes) {
124
+ const hexString = bytes.reduce((acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~128 : byte)}${acc}`, "");
125
+ const integerLiteralString = `0x${hexString}`;
126
+ return BigInt(integerLiteralString);
127
+ }
128
+ async function compressedPointBytesAreOnCurve(bytes) {
129
+ if (bytes.byteLength !== 32) {
130
+ return false;
131
+ }
132
+ const y = decompressPointBytes(bytes);
133
+ return pointIsOnCurve(y, bytes[31]);
134
+ }
135
+
136
+ // src/program-derived-address.ts
137
+ var MAX_SEED_LENGTH = 32;
138
+ var MAX_SEEDS = 16;
139
+ var PDA_MARKER_BYTES = [
140
+ // The string 'ProgramDerivedAddress'
141
+ 80,
142
+ 114,
143
+ 111,
144
+ 103,
145
+ 114,
146
+ 97,
147
+ 109,
148
+ 68,
149
+ 101,
150
+ 114,
151
+ 105,
152
+ 118,
153
+ 101,
154
+ 100,
155
+ 65,
156
+ 100,
157
+ 100,
158
+ 114,
159
+ 101,
160
+ 115,
161
+ 115
162
+ ];
163
+ var PointOnCurveError = class extends Error {
164
+ };
165
+ async function createProgramDerivedAddress({ programAddress, seeds }) {
166
+ await assertions.assertDigestCapabilityIsAvailable();
167
+ if (seeds.length > MAX_SEEDS) {
168
+ throw new Error(`A maximum of ${MAX_SEEDS} seeds may be supplied when creating an address`);
169
+ }
170
+ let textEncoder;
171
+ const seedBytes = seeds.reduce((acc, seed, ii) => {
172
+ const bytes = typeof seed === "string" ? (textEncoder || (textEncoder = new TextEncoder())).encode(seed) : seed;
173
+ if (bytes.byteLength > MAX_SEED_LENGTH) {
174
+ throw new Error(`The seed at index ${ii} exceeds the maximum length of 32 bytes`);
175
+ }
176
+ acc.push(...bytes);
177
+ return acc;
178
+ }, []);
179
+ const base58EncodedAddressCodec = getBase58EncodedAddressCodec();
180
+ const programAddressBytes = base58EncodedAddressCodec.serialize(programAddress);
181
+ const addressBytesBuffer = await crypto.subtle.digest(
182
+ "SHA-256",
183
+ new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
184
+ );
185
+ const addressBytes = new Uint8Array(addressBytesBuffer);
186
+ if (await compressedPointBytesAreOnCurve(addressBytes)) {
187
+ throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
188
+ }
189
+ return base58EncodedAddressCodec.deserialize(addressBytes)[0];
190
+ }
191
+ async function getProgramDerivedAddress({ programAddress, seeds }) {
192
+ let bumpSeed = 255;
193
+ while (bumpSeed > 0) {
194
+ try {
195
+ return {
196
+ bumpSeed,
197
+ pda: await createProgramDerivedAddress({
198
+ programAddress,
199
+ seeds: [...seeds, new Uint8Array([bumpSeed])]
200
+ })
201
+ };
202
+ } catch (e) {
203
+ if (e instanceof PointOnCurveError) {
204
+ bumpSeed--;
205
+ } else {
206
+ throw e;
207
+ }
208
+ }
209
+ }
210
+ throw new Error("Unable to find a viable program address bump seed");
211
+ }
212
+ async function getBase58EncodedAddressFromPublicKey(publicKey) {
213
+ await assertions.assertKeyExporterIsAvailable();
214
+ if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
215
+ throw new Error("The `CryptoKey` must be an `Ed25519` public key");
216
+ }
217
+ const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
218
+ const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
219
+ return base58EncodedAddress;
220
+ }
221
+
222
+ exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
223
+ exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
224
+ exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
225
+ exports.getBase58EncodedAddressFromPublicKey = getBase58EncodedAddressFromPublicKey;
226
+ exports.getProgramDerivedAddress = getProgramDerivedAddress;
227
+ //# sourceMappingURL=out.js.map
228
+ //# sourceMappingURL=index.browser.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../build-scripts/env-shim.ts","../src/base58.ts","../src/program-derived-address.ts","../src/vendor/noble/ed25519.ts","../src/curve.ts","../src/public-key.ts"],"names":[],"mappings":";AACO,IAAM,UAA2B,uBAAO,QAAgB,KAAU,EAAE,aAAa,eAAe;;;ACDvG,SAAS,QAAoB,cAAc;AAMpC,SAAS,6BACZ,8BACiG;AACjG,MAAI;AAEA;AAAA;AAAA,MAEI,6BAA6B,SAAS;AAAA,MAEtC,6BAA6B,SAAS;AAAA,MACxC;AACE,YAAM,IAAI,MAAM,+DAA+D;AAAA,IACnF;AAEA,UAAM,QAAQ,OAAO,UAAU,4BAA4B;AAC3D,UAAM,WAAW,MAAM;AACvB,QAAI,aAAa,IAAI;AACjB,YAAM,IAAI,MAAM,g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QAAM,sBAAsB,0BAA0B,UAAU,cAAc;AAC9E,QAAM,qBAAqB,MAAM,OAAO,OAAO;AAAA,IAC3C;AAAA,IACA,IAAI,WAAW,CAAC,GAAG,WAAW,GAAG,qBAAqB,GAAG,gBAAgB,CAAC;AAAA,EAC9E;AACA,QAAM,eAAe,IAAI,WAAW,kBAAkB;AACtD,MAAI,MAAM,+BAA+B,YAAY,GAAG;AAEpD,UAAM,IAAI,kBAAkB,sDAAsD;AAAA,EACtF;AACA,SAAO,0BAA0B,YAAY,YAAY,EAAE,CAAC;AAChE;AAEA,eAAsB,yBAAyB,EAAE,gBAAgB,MAAM,GAKrE;AACE,MAAI,WAAW;AACf,SAAO,WAAW,GAAG;AACjB,QAAI;AACA,aAAO;AAAA,QACH;AAAA,QACA,KAAK,MAAM,4BAA4B;AAAA,UACnC;AAAA,UACA,OAAO,CAAC,GAAG,OAAO,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC;AAAA,QAChD,CAAC;AAAA,MACL;AAAA,IACJ,SAAS,GAAP;AACE,UAAI,aAAa,mBAAmB;AAChC;AAAA,MACJ,OAAO;AACH,cAAM;AAAA,MACV;AAAA,IACJ;AAAA,EACJ;AAEA,QAAM,IAAI,MAAM,mDAAmD;AACvE;;;AG7EA,SAAS,oCAAoC;AAI7C,eAAsB,qCAAqC,WAAqD;AAC5G,QAAM,6BAA6B;AACnC,MAAI,UAAU,SAAS,YAAY,UAAU,UAAU,SAAS,WAAW;AAEvE,UAAM,IAAI,MAAM,iDAAiD;AAAA,EACrE;AACA,QAAM,iBAAiB,MAAM,OAAO,OAAO,UAAU,OAAO,SAAS;AACrE,QAAM,CAAC,oBAAoB,IAAI,6BAA6B,EAAE,YAAY,IAAI,WAAW,cAAc,CAAC;AACxG,SAAO;AACX","sourcesContent":["// Clever obfuscation to prevent the build system from inlining the value of `NODE_ENV`\nexport const __DEV__ = /* @__PURE__ */ (() => (process as any)['en' + 'v'].NODE_ENV === 'development')();\n","import { base58, Serializer, string } from '@metaplex-foundation/umi-serializers';\n\nexport type Base58EncodedAddress<TAddress extends string = string> = TAddress & {\n readonly __base58EncodedAddress: unique symbol;\n};\n\nexport function assertIsBase58EncodedAddress(\n putativeBase58EncodedAddress: string\n): asserts putativeBase58EncodedAddress is Base58EncodedAddress<typeof putativeBase58EncodedAddress> {\n try {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest address (32 bytes of zeroes)\n putativeBase58EncodedAddress.length < 32 ||\n // Highest address (32 bytes of 255)\n putativeBase58EncodedAddress.length > 44\n ) {\n throw new Error('Expected input string to decode to a byte array of length 32.');\n }\n // Slow-path; actually attempt to decode the input string.\n const bytes = base58.serialize(putativeBase58EncodedAddress);\n const numBytes = bytes.byteLength;\n if (numBytes !== 32) {\n throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);\n }\n } catch (e) {\n throw new Error(`\\`${putativeBase58EncodedAddress}\\` is not a base-58 encoded address`, {\n cause: e,\n });\n }\n}\n\nexport function getBase58EncodedAddressCodec(\n config?: Readonly<{\n description: string;\n }>\n): Serializer<Base58EncodedAddress> {\n return string({\n description: config?.description ?? (__DEV__ ? 'A 32-byte account address' : ''),\n encoding: base58,\n size: 32,\n }) as unknown as Serializer<Base58EncodedAddress>;\n}\n\nexport function getBase58EncodedAddressComparator(): (x: string, y: string) => number {\n return new Intl.Collator('en', {\n caseFirst: 'lower',\n ignorePunctuation: false,\n localeMatcher: 'best fit',\n numeric: false,\n sensitivity: 'variant',\n usage: 'sort',\n }).compare;\n}\n","import { assertDigestCapabilityIsAvailable } from '@solana/assertions';\n\nimport { Base58EncodedAddress, getBase58EncodedAddressCodec } from './base58';\nimport { compressedPointBytesAreOnCurve } from './curve';\n\ntype PDAInput = Readonly<{\n programAddress: Base58EncodedAddress;\n seeds: Seed[];\n}>;\ntype Seed = string | Uint8Array;\n\nconst MAX_SEED_LENGTH = 32;\nconst MAX_SEEDS = 16;\nconst PDA_MARKER_BYTES = [\n // The string 'ProgramDerivedAddress'\n 80, 114, 111, 103, 114, 97, 109, 68, 101, 114, 105, 118, 101, 100, 65, 100, 100, 114, 101, 115, 115,\n] as const;\n\n// TODO: Coded error.\nclass PointOnCurveError extends Error {}\n\nasync function createProgramDerivedAddress({ programAddress, seeds }: PDAInput): Promise<Base58EncodedAddress> {\n await assertDigestCapabilityIsAvailable();\n if (seeds.length > MAX_SEEDS) {\n // TODO: Coded error.\n throw new Error(`A maximum of ${MAX_SEEDS} seeds may be supplied when creating an address`);\n }\n let textEncoder: TextEncoder;\n const seedBytes = seeds.reduce((acc, seed, ii) => {\n const bytes = typeof seed === 'string' ? (textEncoder ||= new TextEncoder()).encode(seed) : seed;\n if (bytes.byteLength > MAX_SEED_LENGTH) {\n // TODO: Coded error.\n throw new Error(`The seed at index ${ii} exceeds the maximum length of 32 bytes`);\n }\n acc.push(...bytes);\n return acc;\n }, [] as number[]);\n const base58EncodedAddressCodec = getBase58EncodedAddressCodec();\n const programAddressBytes = base58EncodedAddressCodec.serialize(programAddress);\n const addressBytesBuffer = await crypto.subtle.digest(\n 'SHA-256',\n new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])\n );\n const addressBytes = new Uint8Array(addressBytesBuffer);\n if (await compressedPointBytesAreOnCurve(addressBytes)) {\n // TODO: Coded error.\n throw new PointOnCurveError('Invalid seeds; point must fall off the Ed25519 curve');\n }\n return base58EncodedAddressCodec.deserialize(addressBytes)[0];\n}\n\nexport async function getProgramDerivedAddress({ programAddress, seeds }: PDAInput): Promise<\n Readonly<{\n bumpSeed: number;\n pda: Base58EncodedAddress;\n }>\n> {\n let bumpSeed = 255;\n while (bumpSeed > 0) {\n try {\n return {\n bumpSeed,\n pda: await createProgramDerivedAddress({\n programAddress,\n seeds: [...seeds, new Uint8Array([bumpSeed])],\n }),\n };\n } catch (e) {\n if (e instanceof PointOnCurveError) {\n bumpSeed--;\n } else {\n throw e;\n }\n }\n }\n // TODO: Coded error.\n throw new Error('Unable to find a viable program address bump seed');\n}\n","/**!\n * noble-ed25519\n *\n * The MIT License (MIT)\n *\n * Copyright (c) 2019 Paul Miller (https://paulmillr.com)\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the “Software”), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\nconst D = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;\nconst P = 57896044618658097711785492504343953926634992332820282019728792003956564819949n; // 2n ** 255n - 19n; ed25519 is twisted edwards curve\nconst RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n; // √-1\n\n// mod division\nfunction mod(a: bigint): bigint {\n const r = a % P;\n return r >= 0n ? r : P + r;\n}\nfunction pow2(x: bigint, power: bigint): bigint {\n // pow2(x, 4) == x^(2^4)\n let r = x;\n while (power-- > 0n) {\n r *= r;\n r %= P;\n }\n return r;\n}\nfunction pow_2_252_3(x: bigint): bigint {\n // x^(2^252-3) unrolled util for square root\n const x2 = (x * x) % P; // x^2, bits 1\n const b2 = (x2 * x) % P; // x^3, bits 11\n const b4 = (pow2(b2, 2n) * b2) % P; // x^(2^4-1), bits 1111\n const b5 = (pow2(b4, 1n) * x) % P; // x^(2^5-1), bits 11111\n const b10 = (pow2(b5, 5n) * b5) % P; // x^(2^10)\n const b20 = (pow2(b10, 10n) * b10) % P; // x^(2^20)\n const b40 = (pow2(b20, 20n) * b20) % P; // x^(2^40)\n const b80 = (pow2(b40, 40n) * b40) % P; // x^(2^80)\n const b160 = (pow2(b80, 80n) * b80) % P; // x^(2^160)\n const b240 = (pow2(b160, 80n) * b80) % P; // x^(2^240)\n const b250 = (pow2(b240, 10n) * b10) % P; // x^(2^250)\n const pow_p_5_8 = (pow2(b250, 2n) * x) % P; // < To pow to (p+3)/8, multiply it by x.\n return pow_p_5_8;\n}\nfunction uvRatio(u: bigint, v: bigint): bigint | null {\n // for sqrt comp\n const v3 = mod(v * v * v); // v³\n const v7 = mod(v3 * v3 * v); // v⁷\n const pow = pow_2_252_3(u * v7); // (uv⁷)^(p-5)/8\n let x = mod(u * v3 * pow); // (uv³)(uv⁷)^(p-5)/8\n const vx2 = mod(v * x * x); // vx²\n const root1 = x; // First root candidate\n const root2 = mod(x * RM1); // Second root candidate; RM1 is √-1\n const useRoot1 = vx2 === u; // If vx² = u (mod p), x is a square root\n const useRoot2 = vx2 === mod(-u); // If vx² = -u, set x <-- x * 2^((p-1)/4)\n const noRoot = vx2 === mod(-u * RM1); // There is no valid root, vx² = -u√-1\n if (useRoot1) x = root1;\n if (useRoot2 || noRoot) x = root2; // We return root2 anyway, for const-time\n if ((mod(x) & 1n) === 1n) x = mod(-x); // edIsNegative\n if (!useRoot1 && !useRoot2) {\n return null;\n }\n return x;\n}\n// https://datatracker.ietf.org/doc/html/rfc8032#section-5.1.3\nexport function pointIsOnCurve(y: bigint, lastByte: number): boolean {\n const y2 = mod(y * y); // y²\n const u = mod(y2 - 1n); // u=y²-1\n const v = mod(D * y2 + 1n);\n const x = uvRatio(u, v); // (uv³)(uv⁷)^(p-5)/8; square root\n if (x === null) {\n return false;\n }\n const isLastByteOdd = (lastByte & 0x80) !== 0; // x_0, last bit\n if (x === 0n && isLastByteOdd) {\n return false;\n }\n return true;\n}\n","import { pointIsOnCurve } from './vendor/noble/ed25519';\n\nfunction byteToHex(byte: number): string {\n const hexString = byte.toString(16);\n if (hexString.length === 1) {\n return `0${hexString}`;\n } else {\n return hexString;\n }\n}\n\nfunction decompressPointBytes(bytes: Uint8Array): bigint {\n const hexString = bytes.reduce((acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~0x80 : byte)}${acc}`, '');\n const integerLiteralString = `0x${hexString}`;\n return BigInt(integerLiteralString);\n}\n\nexport async function compressedPointBytesAreOnCurve(bytes: Uint8Array): Promise<boolean> {\n if (bytes.byteLength !== 32) {\n return false;\n }\n const y = decompressPointBytes(bytes);\n return pointIsOnCurve(y, bytes[31]);\n}\n","import { assertKeyExporterIsAvailable } from '@solana/assertions';\n\nimport { Base58EncodedAddress, getBase58EncodedAddressCodec } from './base58';\n\nexport async function getBase58EncodedAddressFromPublicKey(publicKey: CryptoKey): Promise<Base58EncodedAddress> {\n await assertKeyExporterIsAvailable();\n if (publicKey.type !== 'public' || publicKey.algorithm.name !== 'Ed25519') {\n // TODO: Coded error.\n throw new Error('The `CryptoKey` must be an `Ed25519` public key');\n }\n const publicKeyBytes = await crypto.subtle.exportKey('raw', publicKey);\n const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));\n return base58EncodedAddress;\n}\n"]}
@@ -0,0 +1,222 @@
1
+ import { base58, string } from '@metaplex-foundation/umi-serializers';
2
+ import { assertKeyExporterIsAvailable, assertDigestCapabilityIsAvailable } from '@solana/assertions';
3
+
4
+ // ../build-scripts/env-shim.ts
5
+ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
6
+ function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
7
+ try {
8
+ if (
9
+ // Lowest address (32 bytes of zeroes)
10
+ putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
11
+ putativeBase58EncodedAddress.length > 44
12
+ ) {
13
+ throw new Error("Expected input string to decode to a byte array of length 32.");
14
+ }
15
+ const bytes = base58.serialize(putativeBase58EncodedAddress);
16
+ const numBytes = bytes.byteLength;
17
+ if (numBytes !== 32) {
18
+ throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
19
+ }
20
+ } catch (e) {
21
+ throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
22
+ cause: e
23
+ });
24
+ }
25
+ }
26
+ function getBase58EncodedAddressCodec(config) {
27
+ return string({
28
+ description: config?.description ?? (__DEV__ ? "A 32-byte account address" : ""),
29
+ encoding: base58,
30
+ size: 32
31
+ });
32
+ }
33
+ function getBase58EncodedAddressComparator() {
34
+ return new Intl.Collator("en", {
35
+ caseFirst: "lower",
36
+ ignorePunctuation: false,
37
+ localeMatcher: "best fit",
38
+ numeric: false,
39
+ sensitivity: "variant",
40
+ usage: "sort"
41
+ }).compare;
42
+ }
43
+
44
+ // src/vendor/noble/ed25519.ts
45
+ var D = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;
46
+ var P = 57896044618658097711785492504343953926634992332820282019728792003956564819949n;
47
+ var RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
48
+ function mod(a) {
49
+ const r = a % P;
50
+ return r >= 0n ? r : P + r;
51
+ }
52
+ function pow2(x, power) {
53
+ let r = x;
54
+ while (power-- > 0n) {
55
+ r *= r;
56
+ r %= P;
57
+ }
58
+ return r;
59
+ }
60
+ function pow_2_252_3(x) {
61
+ const x2 = x * x % P;
62
+ const b2 = x2 * x % P;
63
+ const b4 = pow2(b2, 2n) * b2 % P;
64
+ const b5 = pow2(b4, 1n) * x % P;
65
+ const b10 = pow2(b5, 5n) * b5 % P;
66
+ const b20 = pow2(b10, 10n) * b10 % P;
67
+ const b40 = pow2(b20, 20n) * b20 % P;
68
+ const b80 = pow2(b40, 40n) * b40 % P;
69
+ const b160 = pow2(b80, 80n) * b80 % P;
70
+ const b240 = pow2(b160, 80n) * b80 % P;
71
+ const b250 = pow2(b240, 10n) * b10 % P;
72
+ const pow_p_5_8 = pow2(b250, 2n) * x % P;
73
+ return pow_p_5_8;
74
+ }
75
+ function uvRatio(u, v) {
76
+ const v3 = mod(v * v * v);
77
+ const v7 = mod(v3 * v3 * v);
78
+ const pow = pow_2_252_3(u * v7);
79
+ let x = mod(u * v3 * pow);
80
+ const vx2 = mod(v * x * x);
81
+ const root1 = x;
82
+ const root2 = mod(x * RM1);
83
+ const useRoot1 = vx2 === u;
84
+ const useRoot2 = vx2 === mod(-u);
85
+ const noRoot = vx2 === mod(-u * RM1);
86
+ if (useRoot1)
87
+ x = root1;
88
+ if (useRoot2 || noRoot)
89
+ x = root2;
90
+ if ((mod(x) & 1n) === 1n)
91
+ x = mod(-x);
92
+ if (!useRoot1 && !useRoot2) {
93
+ return null;
94
+ }
95
+ return x;
96
+ }
97
+ function pointIsOnCurve(y, lastByte) {
98
+ const y2 = mod(y * y);
99
+ const u = mod(y2 - 1n);
100
+ const v = mod(D * y2 + 1n);
101
+ const x = uvRatio(u, v);
102
+ if (x === null) {
103
+ return false;
104
+ }
105
+ const isLastByteOdd = (lastByte & 128) !== 0;
106
+ if (x === 0n && isLastByteOdd) {
107
+ return false;
108
+ }
109
+ return true;
110
+ }
111
+
112
+ // src/curve.ts
113
+ function byteToHex(byte) {
114
+ const hexString = byte.toString(16);
115
+ if (hexString.length === 1) {
116
+ return `0${hexString}`;
117
+ } else {
118
+ return hexString;
119
+ }
120
+ }
121
+ function decompressPointBytes(bytes) {
122
+ const hexString = bytes.reduce((acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~128 : byte)}${acc}`, "");
123
+ const integerLiteralString = `0x${hexString}`;
124
+ return BigInt(integerLiteralString);
125
+ }
126
+ async function compressedPointBytesAreOnCurve(bytes) {
127
+ if (bytes.byteLength !== 32) {
128
+ return false;
129
+ }
130
+ const y = decompressPointBytes(bytes);
131
+ return pointIsOnCurve(y, bytes[31]);
132
+ }
133
+
134
+ // src/program-derived-address.ts
135
+ var MAX_SEED_LENGTH = 32;
136
+ var MAX_SEEDS = 16;
137
+ var PDA_MARKER_BYTES = [
138
+ // The string 'ProgramDerivedAddress'
139
+ 80,
140
+ 114,
141
+ 111,
142
+ 103,
143
+ 114,
144
+ 97,
145
+ 109,
146
+ 68,
147
+ 101,
148
+ 114,
149
+ 105,
150
+ 118,
151
+ 101,
152
+ 100,
153
+ 65,
154
+ 100,
155
+ 100,
156
+ 114,
157
+ 101,
158
+ 115,
159
+ 115
160
+ ];
161
+ var PointOnCurveError = class extends Error {
162
+ };
163
+ async function createProgramDerivedAddress({ programAddress, seeds }) {
164
+ await assertDigestCapabilityIsAvailable();
165
+ if (seeds.length > MAX_SEEDS) {
166
+ throw new Error(`A maximum of ${MAX_SEEDS} seeds may be supplied when creating an address`);
167
+ }
168
+ let textEncoder;
169
+ const seedBytes = seeds.reduce((acc, seed, ii) => {
170
+ const bytes = typeof seed === "string" ? (textEncoder || (textEncoder = new TextEncoder())).encode(seed) : seed;
171
+ if (bytes.byteLength > MAX_SEED_LENGTH) {
172
+ throw new Error(`The seed at index ${ii} exceeds the maximum length of 32 bytes`);
173
+ }
174
+ acc.push(...bytes);
175
+ return acc;
176
+ }, []);
177
+ const base58EncodedAddressCodec = getBase58EncodedAddressCodec();
178
+ const programAddressBytes = base58EncodedAddressCodec.serialize(programAddress);
179
+ const addressBytesBuffer = await crypto.subtle.digest(
180
+ "SHA-256",
181
+ new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
182
+ );
183
+ const addressBytes = new Uint8Array(addressBytesBuffer);
184
+ if (await compressedPointBytesAreOnCurve(addressBytes)) {
185
+ throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
186
+ }
187
+ return base58EncodedAddressCodec.deserialize(addressBytes)[0];
188
+ }
189
+ async function getProgramDerivedAddress({ programAddress, seeds }) {
190
+ let bumpSeed = 255;
191
+ while (bumpSeed > 0) {
192
+ try {
193
+ return {
194
+ bumpSeed,
195
+ pda: await createProgramDerivedAddress({
196
+ programAddress,
197
+ seeds: [...seeds, new Uint8Array([bumpSeed])]
198
+ })
199
+ };
200
+ } catch (e) {
201
+ if (e instanceof PointOnCurveError) {
202
+ bumpSeed--;
203
+ } else {
204
+ throw e;
205
+ }
206
+ }
207
+ }
208
+ throw new Error("Unable to find a viable program address bump seed");
209
+ }
210
+ async function getBase58EncodedAddressFromPublicKey(publicKey) {
211
+ await assertKeyExporterIsAvailable();
212
+ if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
213
+ throw new Error("The `CryptoKey` must be an `Ed25519` public key");
214
+ }
215
+ const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
216
+ const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
217
+ return base58EncodedAddress;
218
+ }
219
+
220
+ export { assertIsBase58EncodedAddress, getBase58EncodedAddressCodec, getBase58EncodedAddressComparator, getBase58EncodedAddressFromPublicKey, getProgramDerivedAddress };
221
+ //# sourceMappingURL=out.js.map
222
+ //# sourceMappingURL=index.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../build-scripts/env-shim.ts","../src/base58.ts","../src/program-derived-address.ts","../src/vendor/noble/ed25519.ts","../src/curve.ts","../src/public-key.ts"],"names":[],"mappings":";AACO,IAAM,UAA2B,uBAAO,QAAgB,KAAU,EAAE,aAAa,eAAe;;;ACDvG,SAAS,QAAoB,cAAc;AAMpC,SAAS,6BACZ,8BACiG;AACjG,MAAI;AAEA;AAAA;AAAA,MAEI,6BAA6B,SAAS;AAAA,MAEtC,6BAA6B,SAAS;AAAA,MACxC;AACE,YAAM,IAAI,MAAM,+DAA+D;AAAA,IACnF;AAEA,UAAM,QAAQ,OAAO,UAAU,4BAA4B;AAC3D,UAAM,WAAW,MAAM;AACvB,QAAI,aAAa,IAAI;AACjB,YAAM,IAAI,MAAM,gFAAgF,UAAU;AAAA,IAC9G;AAAA,EACJ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C9E,QAAM,qBAAqB,MAAM,OAAO,OAAO;AAAA,IAC3C;AAAA,IACA,IAAI,WAAW,CAAC,GAAG,WAAW,GAAG,qBAAqB,GAAG,gBAAgB,CAAC;AAAA,EAC9E;AACA,QAAM,eAAe,IAAI,WAAW,kBAAkB;AACtD,MAAI,MAAM,+BAA+B,YAAY,GAAG;AAEpD,UAAM,IAAI,kBAAkB,sDAAsD;AAAA,EACtF;AACA,SAAO,0BAA0B,YAAY,YAAY,EAAE,CAAC;AAChE;AAEA,eAAsB,yBAAyB,EAAE,gBAAgB,MAAM,GAKrE;AACE,MAAI,WAAW;AACf,SAAO,WAAW,GAAG;AACjB,QAAI;AACA,aAAO;AAAA,QACH;AAAA,QACA,KAAK,MAAM,4BAA4B;AAAA,UACnC;AAAA,UACA,OAAO,CAAC,GAAG,OAAO,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC;AAAA,QAChD,CAAC;AAAA,MACL;AAAA,IACJ,SAAS,GAAP;AACE,UAAI,aAAa,mBAAmB;AAChC;AAAA,MACJ,OAAO;AACH,cAAM;AAAA,MACV;AAAA,IACJ;AAAA,EACJ;AAEA,QAAM,IAAI,MAAM,mDAAmD;AACvE;;;AG7EA,SAAS,oCAAoC;AAI7C,eAAsB,qCAAqC,WAAqD;AAC5G,QAAM,6BAA6B;AACnC,MAAI,UAAU,SAAS,YAAY,UAAU,UAAU,SAAS,WAAW;AAEvE,UAAM,IAAI,MAAM,iDAAiD;AAAA,EACrE;AACA,QAAM,iBAAiB,MAAM,OAAO,OAAO,UAAU,OAAO,SAAS;AACrE,QAAM,CAAC,oBAAoB,IAAI,6BAA6B,EAAE,YAAY,IAAI,WAAW,cAAc,CAAC;AACxG,SAAO;AACX","sourcesContent":["// Clever obfuscation to prevent the build system from inlining the value of `NODE_ENV`\nexport const __DEV__ = /* @__PURE__ */ (() => (process as any)['en' + 'v'].NODE_ENV === 'development')();\n","import { base58, Serializer, string } from '@metaplex-foundation/umi-serializers';\n\nexport type Base58EncodedAddress<TAddress extends string = string> = TAddress & {\n readonly __base58EncodedAddress: unique symbol;\n};\n\nexport function assertIsBase58EncodedAddress(\n putativeBase58EncodedAddress: string\n): asserts putativeBase58EncodedAddress is Base58EncodedAddress<typeof putativeBase58EncodedAddress> {\n try {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest address (32 bytes of zeroes)\n putativeBase58EncodedAddress.length < 32 ||\n // Highest address (32 bytes of 255)\n putativeBase58EncodedAddress.length > 44\n ) {\n throw new Error('Expected input string to decode to a byte array of length 32.');\n }\n // Slow-path; actually attempt to decode the input string.\n const bytes = base58.serialize(putativeBase58EncodedAddress);\n const numBytes = bytes.byteLength;\n if (numBytes !== 32) {\n throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);\n }\n } catch (e) {\n throw new Error(`\\`${putativeBase58EncodedAddress}\\` is not a base-58 encoded address`, {\n cause: e,\n });\n }\n}\n\nexport function getBase58EncodedAddressCodec(\n config?: Readonly<{\n description: string;\n }>\n): Serializer<Base58EncodedAddress> {\n return string({\n description: config?.description ?? (__DEV__ ? 'A 32-byte account address' : ''),\n encoding: base58,\n size: 32,\n }) as unknown as Serializer<Base58EncodedAddress>;\n}\n\nexport function getBase58EncodedAddressComparator(): (x: string, y: string) => number {\n return new Intl.Collator('en', {\n caseFirst: 'lower',\n ignorePunctuation: false,\n localeMatcher: 'best fit',\n numeric: false,\n sensitivity: 'variant',\n usage: 'sort',\n }).compare;\n}\n","import { assertDigestCapabilityIsAvailable } from '@solana/assertions';\n\nimport { Base58EncodedAddress, getBase58EncodedAddressCodec } from './base58';\nimport { compressedPointBytesAreOnCurve } from './curve';\n\ntype PDAInput = Readonly<{\n programAddress: Base58EncodedAddress;\n seeds: Seed[];\n}>;\ntype Seed = string | Uint8Array;\n\nconst MAX_SEED_LENGTH = 32;\nconst MAX_SEEDS = 16;\nconst PDA_MARKER_BYTES = [\n // The string 'ProgramDerivedAddress'\n 80, 114, 111, 103, 114, 97, 109, 68, 101, 114, 105, 118, 101, 100, 65, 100, 100, 114, 101, 115, 115,\n] as const;\n\n// TODO: Coded error.\nclass PointOnCurveError extends Error {}\n\nasync function createProgramDerivedAddress({ programAddress, seeds }: PDAInput): Promise<Base58EncodedAddress> {\n await assertDigestCapabilityIsAvailable();\n if (seeds.length > MAX_SEEDS) {\n // TODO: Coded error.\n throw new Error(`A maximum of ${MAX_SEEDS} seeds may be supplied when creating an address`);\n }\n let textEncoder: TextEncoder;\n const seedBytes = seeds.reduce((acc, seed, ii) => {\n const bytes = typeof seed === 'string' ? (textEncoder ||= new TextEncoder()).encode(seed) : seed;\n if (bytes.byteLength > MAX_SEED_LENGTH) {\n // TODO: Coded error.\n throw new Error(`The seed at index ${ii} exceeds the maximum length of 32 bytes`);\n }\n acc.push(...bytes);\n return acc;\n }, [] as number[]);\n const base58EncodedAddressCodec = getBase58EncodedAddressCodec();\n const programAddressBytes = base58EncodedAddressCodec.serialize(programAddress);\n const addressBytesBuffer = await crypto.subtle.digest(\n 'SHA-256',\n new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])\n );\n const addressBytes = new Uint8Array(addressBytesBuffer);\n if (await compressedPointBytesAreOnCurve(addressBytes)) {\n // TODO: Coded error.\n throw new PointOnCurveError('Invalid seeds; point must fall off the Ed25519 curve');\n }\n return base58EncodedAddressCodec.deserialize(addressBytes)[0];\n}\n\nexport async function getProgramDerivedAddress({ programAddress, seeds }: PDAInput): Promise<\n Readonly<{\n bumpSeed: number;\n pda: Base58EncodedAddress;\n }>\n> {\n let bumpSeed = 255;\n while (bumpSeed > 0) {\n try {\n return {\n bumpSeed,\n pda: await createProgramDerivedAddress({\n programAddress,\n seeds: [...seeds, new Uint8Array([bumpSeed])],\n }),\n };\n } catch (e) {\n if (e instanceof PointOnCurveError) {\n bumpSeed--;\n } else {\n throw e;\n }\n }\n }\n // TODO: Coded error.\n throw new Error('Unable to find a viable program address bump seed');\n}\n","/**!\n * noble-ed25519\n *\n * The MIT License (MIT)\n *\n * Copyright (c) 2019 Paul Miller (https://paulmillr.com)\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the “Software”), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\nconst D = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;\nconst P = 57896044618658097711785492504343953926634992332820282019728792003956564819949n; // 2n ** 255n - 19n; ed25519 is twisted edwards curve\nconst RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n; // √-1\n\n// mod division\nfunction mod(a: bigint): bigint {\n const r = a % P;\n return r >= 0n ? r : P + r;\n}\nfunction pow2(x: bigint, power: bigint): bigint {\n // pow2(x, 4) == x^(2^4)\n let r = x;\n while (power-- > 0n) {\n r *= r;\n r %= P;\n }\n return r;\n}\nfunction pow_2_252_3(x: bigint): bigint {\n // x^(2^252-3) unrolled util for square root\n const x2 = (x * x) % P; // x^2, bits 1\n const b2 = (x2 * x) % P; // x^3, bits 11\n const b4 = (pow2(b2, 2n) * b2) % P; // x^(2^4-1), bits 1111\n const b5 = (pow2(b4, 1n) * x) % P; // x^(2^5-1), bits 11111\n const b10 = (pow2(b5, 5n) * b5) % P; // x^(2^10)\n const b20 = (pow2(b10, 10n) * b10) % P; // x^(2^20)\n const b40 = (pow2(b20, 20n) * b20) % P; // x^(2^40)\n const b80 = (pow2(b40, 40n) * b40) % P; // x^(2^80)\n const b160 = (pow2(b80, 80n) * b80) % P; // x^(2^160)\n const b240 = (pow2(b160, 80n) * b80) % P; // x^(2^240)\n const b250 = (pow2(b240, 10n) * b10) % P; // x^(2^250)\n const pow_p_5_8 = (pow2(b250, 2n) * x) % P; // < To pow to (p+3)/8, multiply it by x.\n return pow_p_5_8;\n}\nfunction uvRatio(u: bigint, v: bigint): bigint | null {\n // for sqrt comp\n const v3 = mod(v * v * v); // v³\n const v7 = mod(v3 * v3 * v); // v⁷\n const pow = pow_2_252_3(u * v7); // (uv⁷)^(p-5)/8\n let x = mod(u * v3 * pow); // (uv³)(uv⁷)^(p-5)/8\n const vx2 = mod(v * x * x); // vx²\n const root1 = x; // First root candidate\n const root2 = mod(x * RM1); // Second root candidate; RM1 is √-1\n const useRoot1 = vx2 === u; // If vx² = u (mod p), x is a square root\n const useRoot2 = vx2 === mod(-u); // If vx² = -u, set x <-- x * 2^((p-1)/4)\n const noRoot = vx2 === mod(-u * RM1); // There is no valid root, vx² = -u√-1\n if (useRoot1) x = root1;\n if (useRoot2 || noRoot) x = root2; // We return root2 anyway, for const-time\n if ((mod(x) & 1n) === 1n) x = mod(-x); // edIsNegative\n if (!useRoot1 && !useRoot2) {\n return null;\n }\n return x;\n}\n// https://datatracker.ietf.org/doc/html/rfc8032#section-5.1.3\nexport function pointIsOnCurve(y: bigint, lastByte: number): boolean {\n const y2 = mod(y * y); // y²\n const u = mod(y2 - 1n); // u=y²-1\n const v = mod(D * y2 + 1n);\n const x = uvRatio(u, v); // (uv³)(uv⁷)^(p-5)/8; square root\n if (x === null) {\n return false;\n }\n const isLastByteOdd = (lastByte & 0x80) !== 0; // x_0, last bit\n if (x === 0n && isLastByteOdd) {\n return false;\n }\n return true;\n}\n","import { pointIsOnCurve } from './vendor/noble/ed25519';\n\nfunction byteToHex(byte: number): string {\n const hexString = byte.toString(16);\n if (hexString.length === 1) {\n return `0${hexString}`;\n } else {\n return hexString;\n }\n}\n\nfunction decompressPointBytes(bytes: Uint8Array): bigint {\n const hexString = bytes.reduce((acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~0x80 : byte)}${acc}`, '');\n const integerLiteralString = `0x${hexString}`;\n return BigInt(integerLiteralString);\n}\n\nexport async function compressedPointBytesAreOnCurve(bytes: Uint8Array): Promise<boolean> {\n if (bytes.byteLength !== 32) {\n return false;\n }\n const y = decompressPointBytes(bytes);\n return pointIsOnCurve(y, bytes[31]);\n}\n","import { assertKeyExporterIsAvailable } from '@solana/assertions';\n\nimport { Base58EncodedAddress, getBase58EncodedAddressCodec } from './base58';\n\nexport async function getBase58EncodedAddressFromPublicKey(publicKey: CryptoKey): Promise<Base58EncodedAddress> {\n await assertKeyExporterIsAvailable();\n if (publicKey.type !== 'public' || publicKey.algorithm.name !== 'Ed25519') {\n // TODO: Coded error.\n throw new Error('The `CryptoKey` must be an `Ed25519` public key');\n }\n const publicKeyBytes = await crypto.subtle.exportKey('raw', publicKey);\n const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));\n return base58EncodedAddress;\n}\n"]}