@solana/addresses 2.0.0-20241006045741

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.
@@ -0,0 +1,294 @@
1
+ import { transformEncoder, fixEncoderSize, fixDecoderSize, combineCodec } from '@solana/codecs-core';
2
+ import { getBase58Encoder, getBase58Decoder } from '@solana/codecs-strings';
3
+ import { SolanaError, SOLANA_ERROR__ADDRESSES__STRING_LENGTH_OUT_OF_RANGE, SOLANA_ERROR__ADDRESSES__INVALID_BYTE_LENGTH, SOLANA_ERROR__ADDRESSES__MALFORMED_PDA, SOLANA_ERROR__ADDRESSES__PDA_BUMP_SEED_OUT_OF_RANGE, isSolanaError, SOLANA_ERROR__ADDRESSES__INVALID_SEEDS_POINT_ON_CURVE, SOLANA_ERROR__ADDRESSES__FAILED_TO_FIND_VIABLE_PDA_BUMP_SEED, SOLANA_ERROR__ADDRESSES__MAX_PDA_SEED_LENGTH_EXCEEDED, SOLANA_ERROR__ADDRESSES__PDA_ENDS_WITH_PDA_MARKER, SOLANA_ERROR__ADDRESSES__INVALID_ED25519_PUBLIC_KEY, SOLANA_ERROR__ADDRESSES__MAX_NUMBER_OF_PDA_SEEDS_EXCEEDED } from '@solana/errors';
4
+ import { assertKeyExporterIsAvailable, assertDigestCapabilityIsAvailable } from '@solana/assertions';
5
+
6
+ // src/address.ts
7
+ var memoizedBase58Encoder;
8
+ var memoizedBase58Decoder;
9
+ function getMemoizedBase58Encoder() {
10
+ if (!memoizedBase58Encoder) memoizedBase58Encoder = getBase58Encoder();
11
+ return memoizedBase58Encoder;
12
+ }
13
+ function getMemoizedBase58Decoder() {
14
+ if (!memoizedBase58Decoder) memoizedBase58Decoder = getBase58Decoder();
15
+ return memoizedBase58Decoder;
16
+ }
17
+ function isAddress(putativeAddress) {
18
+ if (
19
+ // Lowest address (32 bytes of zeroes)
20
+ putativeAddress.length < 32 || // Highest address (32 bytes of 255)
21
+ putativeAddress.length > 44
22
+ ) {
23
+ return false;
24
+ }
25
+ const base58Encoder = getMemoizedBase58Encoder();
26
+ try {
27
+ return base58Encoder.encode(putativeAddress).byteLength === 32;
28
+ } catch {
29
+ return false;
30
+ }
31
+ }
32
+ function assertIsAddress(putativeAddress) {
33
+ if (
34
+ // Lowest address (32 bytes of zeroes)
35
+ putativeAddress.length < 32 || // Highest address (32 bytes of 255)
36
+ putativeAddress.length > 44
37
+ ) {
38
+ throw new SolanaError(SOLANA_ERROR__ADDRESSES__STRING_LENGTH_OUT_OF_RANGE, {
39
+ actualLength: putativeAddress.length
40
+ });
41
+ }
42
+ const base58Encoder = getMemoizedBase58Encoder();
43
+ const bytes = base58Encoder.encode(putativeAddress);
44
+ const numBytes = bytes.byteLength;
45
+ if (numBytes !== 32) {
46
+ throw new SolanaError(SOLANA_ERROR__ADDRESSES__INVALID_BYTE_LENGTH, {
47
+ actualLength: numBytes
48
+ });
49
+ }
50
+ }
51
+ function address(putativeAddress) {
52
+ assertIsAddress(putativeAddress);
53
+ return putativeAddress;
54
+ }
55
+ function getAddressEncoder() {
56
+ return transformEncoder(
57
+ fixEncoderSize(getMemoizedBase58Encoder(), 32),
58
+ (putativeAddress) => address(putativeAddress)
59
+ );
60
+ }
61
+ function getAddressDecoder() {
62
+ return fixDecoderSize(getMemoizedBase58Decoder(), 32);
63
+ }
64
+ function getAddressCodec() {
65
+ return combineCodec(getAddressEncoder(), getAddressDecoder());
66
+ }
67
+ function getAddressComparator() {
68
+ return new Intl.Collator("en", {
69
+ caseFirst: "lower",
70
+ ignorePunctuation: false,
71
+ localeMatcher: "best fit",
72
+ numeric: false,
73
+ sensitivity: "variant",
74
+ usage: "sort"
75
+ }).compare;
76
+ }
77
+
78
+ // src/vendor/noble/ed25519.ts
79
+ var D = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;
80
+ var P = 57896044618658097711785492504343953926634992332820282019728792003956564819949n;
81
+ var RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
82
+ function mod(a) {
83
+ const r = a % P;
84
+ return r >= 0n ? r : P + r;
85
+ }
86
+ function pow2(x, power) {
87
+ let r = x;
88
+ while (power-- > 0n) {
89
+ r *= r;
90
+ r %= P;
91
+ }
92
+ return r;
93
+ }
94
+ function pow_2_252_3(x) {
95
+ const x2 = x * x % P;
96
+ const b2 = x2 * x % P;
97
+ const b4 = pow2(b2, 2n) * b2 % P;
98
+ const b5 = pow2(b4, 1n) * x % P;
99
+ const b10 = pow2(b5, 5n) * b5 % P;
100
+ const b20 = pow2(b10, 10n) * b10 % P;
101
+ const b40 = pow2(b20, 20n) * b20 % P;
102
+ const b80 = pow2(b40, 40n) * b40 % P;
103
+ const b160 = pow2(b80, 80n) * b80 % P;
104
+ const b240 = pow2(b160, 80n) * b80 % P;
105
+ const b250 = pow2(b240, 10n) * b10 % P;
106
+ const pow_p_5_8 = pow2(b250, 2n) * x % P;
107
+ return pow_p_5_8;
108
+ }
109
+ function uvRatio(u, v) {
110
+ const v3 = mod(v * v * v);
111
+ const v7 = mod(v3 * v3 * v);
112
+ const pow = pow_2_252_3(u * v7);
113
+ let x = mod(u * v3 * pow);
114
+ const vx2 = mod(v * x * x);
115
+ const root1 = x;
116
+ const root2 = mod(x * RM1);
117
+ const useRoot1 = vx2 === u;
118
+ const useRoot2 = vx2 === mod(-u);
119
+ const noRoot = vx2 === mod(-u * RM1);
120
+ if (useRoot1) x = root1;
121
+ if (useRoot2 || noRoot) x = root2;
122
+ if ((mod(x) & 1n) === 1n) x = mod(-x);
123
+ if (!useRoot1 && !useRoot2) {
124
+ return null;
125
+ }
126
+ return x;
127
+ }
128
+ function pointIsOnCurve(y, lastByte) {
129
+ const y2 = mod(y * y);
130
+ const u = mod(y2 - 1n);
131
+ const v = mod(D * y2 + 1n);
132
+ const x = uvRatio(u, v);
133
+ if (x === null) {
134
+ return false;
135
+ }
136
+ const isLastByteOdd = (lastByte & 128) !== 0;
137
+ if (x === 0n && isLastByteOdd) {
138
+ return false;
139
+ }
140
+ return true;
141
+ }
142
+
143
+ // src/curve.ts
144
+ function byteToHex(byte) {
145
+ const hexString = byte.toString(16);
146
+ if (hexString.length === 1) {
147
+ return `0${hexString}`;
148
+ } else {
149
+ return hexString;
150
+ }
151
+ }
152
+ function decompressPointBytes(bytes) {
153
+ const hexString = bytes.reduce((acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~128 : byte)}${acc}`, "");
154
+ const integerLiteralString = `0x${hexString}`;
155
+ return BigInt(integerLiteralString);
156
+ }
157
+ function compressedPointBytesAreOnCurve(bytes) {
158
+ if (bytes.byteLength !== 32) {
159
+ return false;
160
+ }
161
+ const y = decompressPointBytes(bytes);
162
+ return pointIsOnCurve(y, bytes[31]);
163
+ }
164
+
165
+ // src/program-derived-address.ts
166
+ function isProgramDerivedAddress(value) {
167
+ return Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number" && value[1] >= 0 && value[1] <= 255 && isAddress(value[0]);
168
+ }
169
+ function assertIsProgramDerivedAddress(value) {
170
+ const validFormat = Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number";
171
+ if (!validFormat) {
172
+ throw new SolanaError(SOLANA_ERROR__ADDRESSES__MALFORMED_PDA);
173
+ }
174
+ if (value[1] < 0 || value[1] > 255) {
175
+ throw new SolanaError(SOLANA_ERROR__ADDRESSES__PDA_BUMP_SEED_OUT_OF_RANGE, {
176
+ bump: value[1]
177
+ });
178
+ }
179
+ assertIsAddress(value[0]);
180
+ }
181
+ var MAX_SEED_LENGTH = 32;
182
+ var MAX_SEEDS = 16;
183
+ var PDA_MARKER_BYTES = [
184
+ // The string 'ProgramDerivedAddress'
185
+ 80,
186
+ 114,
187
+ 111,
188
+ 103,
189
+ 114,
190
+ 97,
191
+ 109,
192
+ 68,
193
+ 101,
194
+ 114,
195
+ 105,
196
+ 118,
197
+ 101,
198
+ 100,
199
+ 65,
200
+ 100,
201
+ 100,
202
+ 114,
203
+ 101,
204
+ 115,
205
+ 115
206
+ ];
207
+ async function createProgramDerivedAddress({ programAddress, seeds }) {
208
+ assertDigestCapabilityIsAvailable();
209
+ if (seeds.length > MAX_SEEDS) {
210
+ throw new SolanaError(SOLANA_ERROR__ADDRESSES__MAX_NUMBER_OF_PDA_SEEDS_EXCEEDED, {
211
+ actual: seeds.length,
212
+ maxSeeds: MAX_SEEDS
213
+ });
214
+ }
215
+ let textEncoder;
216
+ const seedBytes = seeds.reduce((acc, seed, ii) => {
217
+ const bytes = typeof seed === "string" ? (textEncoder ||= new TextEncoder()).encode(seed) : seed;
218
+ if (bytes.byteLength > MAX_SEED_LENGTH) {
219
+ throw new SolanaError(SOLANA_ERROR__ADDRESSES__MAX_PDA_SEED_LENGTH_EXCEEDED, {
220
+ actual: bytes.byteLength,
221
+ index: ii,
222
+ maxSeedLength: MAX_SEED_LENGTH
223
+ });
224
+ }
225
+ acc.push(...bytes);
226
+ return acc;
227
+ }, []);
228
+ const base58EncodedAddressCodec = getAddressCodec();
229
+ const programAddressBytes = base58EncodedAddressCodec.encode(programAddress);
230
+ const addressBytesBuffer = await crypto.subtle.digest(
231
+ "SHA-256",
232
+ new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
233
+ );
234
+ const addressBytes = new Uint8Array(addressBytesBuffer);
235
+ if (compressedPointBytesAreOnCurve(addressBytes)) {
236
+ throw new SolanaError(SOLANA_ERROR__ADDRESSES__INVALID_SEEDS_POINT_ON_CURVE);
237
+ }
238
+ return base58EncodedAddressCodec.decode(addressBytes);
239
+ }
240
+ async function getProgramDerivedAddress({
241
+ programAddress,
242
+ seeds
243
+ }) {
244
+ let bumpSeed = 255;
245
+ while (bumpSeed > 0) {
246
+ try {
247
+ const address2 = await createProgramDerivedAddress({
248
+ programAddress,
249
+ seeds: [...seeds, new Uint8Array([bumpSeed])]
250
+ });
251
+ return [address2, bumpSeed];
252
+ } catch (e) {
253
+ if (isSolanaError(e, SOLANA_ERROR__ADDRESSES__INVALID_SEEDS_POINT_ON_CURVE)) {
254
+ bumpSeed--;
255
+ } else {
256
+ throw e;
257
+ }
258
+ }
259
+ }
260
+ throw new SolanaError(SOLANA_ERROR__ADDRESSES__FAILED_TO_FIND_VIABLE_PDA_BUMP_SEED);
261
+ }
262
+ async function createAddressWithSeed({ baseAddress, programAddress, seed }) {
263
+ const { encode, decode } = getAddressCodec();
264
+ const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
265
+ if (seedBytes.byteLength > MAX_SEED_LENGTH) {
266
+ throw new SolanaError(SOLANA_ERROR__ADDRESSES__MAX_PDA_SEED_LENGTH_EXCEEDED, {
267
+ actual: seedBytes.byteLength,
268
+ index: 0,
269
+ maxSeedLength: MAX_SEED_LENGTH
270
+ });
271
+ }
272
+ const programAddressBytes = encode(programAddress);
273
+ if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
274
+ throw new SolanaError(SOLANA_ERROR__ADDRESSES__PDA_ENDS_WITH_PDA_MARKER);
275
+ }
276
+ const addressBytesBuffer = await crypto.subtle.digest(
277
+ "SHA-256",
278
+ new Uint8Array([...encode(baseAddress), ...seedBytes, ...programAddressBytes])
279
+ );
280
+ const addressBytes = new Uint8Array(addressBytesBuffer);
281
+ return decode(addressBytes);
282
+ }
283
+ async function getAddressFromPublicKey(publicKey) {
284
+ assertKeyExporterIsAvailable();
285
+ if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
286
+ throw new SolanaError(SOLANA_ERROR__ADDRESSES__INVALID_ED25519_PUBLIC_KEY);
287
+ }
288
+ const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
289
+ return getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
290
+ }
291
+
292
+ export { address, assertIsAddress, assertIsProgramDerivedAddress, createAddressWithSeed, getAddressCodec, getAddressComparator, getAddressDecoder, getAddressEncoder, getAddressFromPublicKey, getProgramDerivedAddress, isAddress, isProgramDerivedAddress };
293
+ //# sourceMappingURL=index.node.mjs.map
294
+ //# sourceMappingURL=index.node.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/address.ts","../src/vendor/noble/ed25519.ts","../src/curve.ts","../src/program-derived-address.ts","../src/public-key.ts"],"names":["SolanaError","address"],"mappings":";;;;;;AAsBA,IAAI,qBAAA,CAAA;AACJ,IAAI,qBAAA,CAAA;AAEJ,SAAS,wBAA4C,GAAA;AACjD,EAAI,IAAA,CAAC,qBAAuB,EAAA,qBAAA,GAAwB,gBAAiB,EAAA,CAAA;AACrE,EAAO,OAAA,qBAAA,CAAA;AACX,CAAA;AAEA,SAAS,wBAA4C,GAAA;AACjD,EAAI,IAAA,CAAC,qBAAuB,EAAA,qBAAA,GAAwB,gBAAiB,EAAA,CAAA;AACrE,EAAO,OAAA,qBAAA,CAAA;AACX,CAAA;AAEO,SAAS,UAAU,eAA6E,EAAA;AAEnG,EAAA;AAAA;AAAA,IAEI,gBAAgB,MAAS,GAAA,EAAA;AAAA,IAEzB,gBAAgB,MAAS,GAAA,EAAA;AAAA,IAC3B;AACE,IAAO,OAAA,KAAA,CAAA;AAAA,GACX;AAEA,EAAA,MAAM,gBAAgB,wBAAyB,EAAA,CAAA;AAC/C,EAAI,IAAA;AACA,IAAA,OAAO,aAAc,CAAA,MAAA,CAAO,eAAe,CAAA,CAAE,UAAe,KAAA,EAAA,CAAA;AAAA,GACxD,CAAA,MAAA;AACJ,IAAO,OAAA,KAAA,CAAA;AAAA,GACX;AACJ,CAAA;AAEO,SAAS,gBAAgB,eAAqF,EAAA;AAEjH,EAAA;AAAA;AAAA,IAEI,gBAAgB,MAAS,GAAA,EAAA;AAAA,IAEzB,gBAAgB,MAAS,GAAA,EAAA;AAAA,IAC3B;AACE,IAAM,MAAA,IAAI,YAAY,mDAAqD,EAAA;AAAA,MACvE,cAAc,eAAgB,CAAA,MAAA;AAAA,KACjC,CAAA,CAAA;AAAA,GACL;AAEA,EAAA,MAAM,gBAAgB,wBAAyB,EA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AAIA,YAAY,iDAAiD,CAAA,CAAA;AAAA,GAC3E;AAEA,EAAM,MAAA,kBAAA,GAAqB,MAAM,MAAA,CAAO,MAAO,CAAA,MAAA;AAAA,IAC3C,SAAA;AAAA,IACA,IAAI,UAAW,CAAA,CAAC,GAAG,MAAA,CAAO,WAAW,CAAA,EAAG,GAAG,SAAA,EAAW,GAAG,mBAAmB,CAAC,CAAA;AAAA,GACjF,CAAA;AACA,EAAM,MAAA,YAAA,GAAe,IAAI,UAAA,CAAW,kBAAkB,CAAA,CAAA;AAEtD,EAAA,OAAO,OAAO,YAAY,CAAA,CAAA;AAC9B,CAAA;ACxKA,eAAsB,wBAAwB,SAAwC,EAAA;AAClF,EAA6B,4BAAA,EAAA,CAAA;AAC7B,EAAA,IAAI,UAAU,IAAS,KAAA,QAAA,IAAY,SAAU,CAAA,SAAA,CAAU,SAAS,SAAW,EAAA;AACvE,IAAM,MAAA,IAAIA,YAAY,mDAAmD,CAAA,CAAA;AAAA,GAC7E;AACA,EAAA,MAAM,iBAAiB,MAAM,MAAA,CAAO,MAAO,CAAA,SAAA,CAAU,OAAO,SAAS,CAAA,CAAA;AACrE,EAAA,OAAO,mBAAoB,CAAA,MAAA,CAAO,IAAI,UAAA,CAAW,cAAc,CAAC,CAAA,CAAA;AACpE","file":"index.node.mjs","sourcesContent":["import {\n combineCodec,\n Decoder,\n Encoder,\n fixDecoderSize,\n FixedSizeCodec,\n FixedSizeDecoder,\n FixedSizeEncoder,\n fixEncoderSize,\n transformEncoder,\n} from '@solana/codecs-core';\nimport { getBase58Decoder, getBase58Encoder } from '@solana/codecs-strings';\nimport {\n SOLANA_ERROR__ADDRESSES__INVALID_BYTE_LENGTH,\n SOLANA_ERROR__ADDRESSES__STRING_LENGTH_OUT_OF_RANGE,\n SolanaError,\n} from '@solana/errors';\n\nexport type Address<TAddress extends string = string> = TAddress & {\n readonly __brand: unique symbol;\n};\n\nlet memoizedBase58Encoder: Encoder<string> | undefined;\nlet memoizedBase58Decoder: Decoder<string> | undefined;\n\nfunction getMemoizedBase58Encoder(): Encoder<string> {\n if (!memoizedBase58Encoder) memoizedBase58Encoder = getBase58Encoder();\n return memoizedBase58Encoder;\n}\n\nfunction getMemoizedBase58Decoder(): Decoder<string> {\n if (!memoizedBase58Decoder) memoizedBase58Decoder = getBase58Decoder();\n return memoizedBase58Decoder;\n}\n\nexport function isAddress(putativeAddress: string): putativeAddress is Address<typeof putativeAddress> {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest address (32 bytes of zeroes)\n putativeAddress.length < 32 ||\n // Highest address (32 bytes of 255)\n putativeAddress.length > 44\n ) {\n return false;\n }\n // Slow-path; actually attempt to decode the input string.\n const base58Encoder = getMemoizedBase58Encoder();\n try {\n return base58Encoder.encode(putativeAddress).byteLength === 32;\n } catch {\n return false;\n }\n}\n\nexport function assertIsAddress(putativeAddress: string): asserts putativeAddress is Address<typeof putativeAddress> {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest address (32 bytes of zeroes)\n putativeAddress.length < 32 ||\n // Highest address (32 bytes of 255)\n putativeAddress.length > 44\n ) {\n throw new SolanaError(SOLANA_ERROR__ADDRESSES__STRING_LENGTH_OUT_OF_RANGE, {\n actualLength: putativeAddress.length,\n });\n }\n // Slow-path; actually attempt to decode the input string.\n const base58Encoder = getMemoizedBase58Encoder();\n const bytes = base58Encoder.encode(putativeAddress);\n const numBytes = bytes.byteLength;\n if (numBytes !== 32) {\n throw new SolanaError(SOLANA_ERROR__ADDRESSES__INVALID_BYTE_LENGTH, {\n actualLength: numBytes,\n });\n }\n}\n\nexport function address<TAddress extends string = string>(putativeAddress: TAddress): Address<TAddress> {\n assertIsAddress(putativeAddress);\n return putativeAddress as Address<TAddress>;\n}\n\nexport function getAddressEncoder(): FixedSizeEncoder<Address, 32> {\n return transformEncoder(fixEncoderSize(getMemoizedBase58Encoder(), 32), putativeAddress =>\n address(putativeAddress),\n );\n}\n\nexport function getAddressDecoder(): FixedSizeDecoder<Address, 32> {\n return fixDecoderSize(getMemoizedBase58Decoder(), 32) as FixedSizeDecoder<Address, 32>;\n}\n\nexport function getAddressCodec(): FixedSizeCodec<Address, Address, 32> {\n return combineCodec(getAddressEncoder(), getAddressDecoder());\n}\n\nexport function getAddressComparator(): (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","/**!\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 function compressedPointBytesAreOnCurve(bytes: Uint8Array): boolean {\n if (bytes.byteLength !== 32) {\n return false;\n }\n const y = decompressPointBytes(bytes);\n return pointIsOnCurve(y, bytes[31]);\n}\n","import { assertDigestCapabilityIsAvailable } from '@solana/assertions';\nimport type { ReadonlyUint8Array } from '@solana/codecs-core';\nimport {\n isSolanaError,\n SOLANA_ERROR__ADDRESSES__FAILED_TO_FIND_VIABLE_PDA_BUMP_SEED,\n SOLANA_ERROR__ADDRESSES__INVALID_SEEDS_POINT_ON_CURVE,\n SOLANA_ERROR__ADDRESSES__MALFORMED_PDA,\n SOLANA_ERROR__ADDRESSES__MAX_NUMBER_OF_PDA_SEEDS_EXCEEDED,\n SOLANA_ERROR__ADDRESSES__MAX_PDA_SEED_LENGTH_EXCEEDED,\n SOLANA_ERROR__ADDRESSES__PDA_BUMP_SEED_OUT_OF_RANGE,\n SOLANA_ERROR__ADDRESSES__PDA_ENDS_WITH_PDA_MARKER,\n SolanaError,\n} from '@solana/errors';\n\nimport { Address, assertIsAddress, getAddressCodec, isAddress } from './address';\nimport { compressedPointBytesAreOnCurve } from './curve';\n\n/**\n * An address derived from a program address and a set of seeds.\n * It includes the bump seed used to derive the address and\n * ensure the address is not on the Ed25519 curve.\n */\nexport type ProgramDerivedAddress<TAddress extends string = string> = Readonly<\n [Address<TAddress>, ProgramDerivedAddressBump]\n>;\n\n/**\n * A number between 0 and 255, inclusive.\n */\nexport type ProgramDerivedAddressBump = number & {\n readonly __brand: unique symbol;\n};\n\n/**\n * Returns true if the input value is a program derived address.\n */\nexport function isProgramDerivedAddress<TAddress extends string = string>(\n value: unknown,\n): value is ProgramDerivedAddress<TAddress> {\n return (\n Array.isArray(value) &&\n value.length === 2 &&\n typeof value[0] === 'string' &&\n typeof value[1] === 'number' &&\n value[1] >= 0 &&\n value[1] <= 255 &&\n isAddress(value[0])\n );\n}\n\n/**\n * Fails if the input value is not a program derived address.\n */\nexport function assertIsProgramDerivedAddress<TAddress extends string = string>(\n value: unknown,\n): asserts value is ProgramDerivedAddress<TAddress> {\n const validFormat =\n Array.isArray(value) && value.length === 2 && typeof value[0] === 'string' && typeof value[1] === 'number';\n if (!validFormat) {\n throw new SolanaError(SOLANA_ERROR__ADDRESSES__MALFORMED_PDA);\n }\n if (value[1] < 0 || value[1] > 255) {\n throw new SolanaError(SOLANA_ERROR__ADDRESSES__PDA_BUMP_SEED_OUT_OF_RANGE, {\n bump: value[1],\n });\n }\n assertIsAddress(value[0]);\n}\n\ntype ProgramDerivedAddressInput = Readonly<{\n programAddress: Address;\n seeds: Seed[];\n}>;\n\ntype SeedInput = Readonly<{\n baseAddress: Address;\n programAddress: Address;\n seed: Seed;\n}>;\n\ntype Seed = ReadonlyUint8Array | string;\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\nasync function createProgramDerivedAddress({ programAddress, seeds }: ProgramDerivedAddressInput): Promise<Address> {\n assertDigestCapabilityIsAvailable();\n if (seeds.length > MAX_SEEDS) {\n throw new SolanaError(SOLANA_ERROR__ADDRESSES__MAX_NUMBER_OF_PDA_SEEDS_EXCEEDED, {\n actual: seeds.length,\n maxSeeds: MAX_SEEDS,\n });\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 throw new SolanaError(SOLANA_ERROR__ADDRESSES__MAX_PDA_SEED_LENGTH_EXCEEDED, {\n actual: bytes.byteLength,\n index: ii,\n maxSeedLength: MAX_SEED_LENGTH,\n });\n }\n acc.push(...bytes);\n return acc;\n }, [] as number[]);\n const base58EncodedAddressCodec = getAddressCodec();\n const programAddressBytes = base58EncodedAddressCodec.encode(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 (compressedPointBytesAreOnCurve(addressBytes)) {\n throw new SolanaError(SOLANA_ERROR__ADDRESSES__INVALID_SEEDS_POINT_ON_CURVE);\n }\n return base58EncodedAddressCodec.decode(addressBytes);\n}\n\nexport async function getProgramDerivedAddress({\n programAddress,\n seeds,\n}: ProgramDerivedAddressInput): Promise<ProgramDerivedAddress> {\n let bumpSeed = 255;\n while (bumpSeed > 0) {\n try {\n const address = await createProgramDerivedAddress({\n programAddress,\n seeds: [...seeds, new Uint8Array([bumpSeed])],\n });\n return [address, bumpSeed as ProgramDerivedAddressBump];\n } catch (e) {\n if (isSolanaError(e, SOLANA_ERROR__ADDRESSES__INVALID_SEEDS_POINT_ON_CURVE)) {\n bumpSeed--;\n } else {\n throw e;\n }\n }\n }\n throw new SolanaError(SOLANA_ERROR__ADDRESSES__FAILED_TO_FIND_VIABLE_PDA_BUMP_SEED);\n}\n\nexport async function createAddressWithSeed({ baseAddress, programAddress, seed }: SeedInput): Promise<Address> {\n const { encode, decode } = getAddressCodec();\n\n const seedBytes = typeof seed === 'string' ? new TextEncoder().encode(seed) : seed;\n if (seedBytes.byteLength > MAX_SEED_LENGTH) {\n throw new SolanaError(SOLANA_ERROR__ADDRESSES__MAX_PDA_SEED_LENGTH_EXCEEDED, {\n actual: seedBytes.byteLength,\n index: 0,\n maxSeedLength: MAX_SEED_LENGTH,\n });\n }\n\n const programAddressBytes = encode(programAddress);\n if (\n programAddressBytes.length >= PDA_MARKER_BYTES.length &&\n programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])\n ) {\n throw new SolanaError(SOLANA_ERROR__ADDRESSES__PDA_ENDS_WITH_PDA_MARKER);\n }\n\n const addressBytesBuffer = await crypto.subtle.digest(\n 'SHA-256',\n new Uint8Array([...encode(baseAddress), ...seedBytes, ...programAddressBytes]),\n );\n const addressBytes = new Uint8Array(addressBytesBuffer);\n\n return decode(addressBytes);\n}\n","import { assertKeyExporterIsAvailable } from '@solana/assertions';\nimport { SOLANA_ERROR__ADDRESSES__INVALID_ED25519_PUBLIC_KEY, SolanaError } from '@solana/errors';\n\nimport { Address, getAddressDecoder } from './address';\n\nexport async function getAddressFromPublicKey(publicKey: CryptoKey): Promise<Address> {\n assertKeyExporterIsAvailable();\n if (publicKey.type !== 'public' || publicKey.algorithm.name !== 'Ed25519') {\n throw new SolanaError(SOLANA_ERROR__ADDRESSES__INVALID_ED25519_PUBLIC_KEY);\n }\n const publicKeyBytes = await crypto.subtle.exportKey('raw', publicKey);\n return getAddressDecoder().decode(new Uint8Array(publicKeyBytes));\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
2
+ export type Address<TAddress extends string = string> = TAddress & {
3
+ readonly __brand: unique symbol;
4
+ };
5
+ export declare function isAddress(putativeAddress: string): putativeAddress is Address<typeof putativeAddress>;
6
+ export declare function assertIsAddress(putativeAddress: string): asserts putativeAddress is Address<typeof putativeAddress>;
7
+ export declare function address<TAddress extends string = string>(putativeAddress: TAddress): Address<TAddress>;
8
+ export declare function getAddressEncoder(): FixedSizeEncoder<Address, 32>;
9
+ export declare function getAddressDecoder(): FixedSizeDecoder<Address, 32>;
10
+ export declare function getAddressCodec(): FixedSizeCodec<Address, Address, 32>;
11
+ export declare function getAddressComparator(): (x: string, y: string) => number;
12
+ //# sourceMappingURL=address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAGnB,MAAM,qBAAqB,CAAC;AAQ7B,MAAM,MAAM,OAAO,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,QAAQ,GAAG;IAC/D,QAAQ,CAAC,OAAO,EAAE,OAAO,MAAM,CAAC;CACnC,CAAC;AAeF,wBAAgB,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,eAAe,IAAI,OAAO,CAAC,OAAO,eAAe,CAAC,CAiBrG;AAED,wBAAgB,eAAe,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,IAAI,OAAO,CAAC,OAAO,eAAe,CAAC,CAqBnH;AAED,wBAAgB,OAAO,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAAE,eAAe,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAGtG;AAED,wBAAgB,iBAAiB,IAAI,gBAAgB,CAAC,OAAO,EAAE,EAAE,CAAC,CAIjE;AAED,wBAAgB,iBAAiB,IAAI,gBAAgB,CAAC,OAAO,EAAE,EAAE,CAAC,CAEjE;AAED,wBAAgB,eAAe,IAAI,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,CAEtE;AAED,wBAAgB,oBAAoB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CASvE"}
@@ -0,0 +1,2 @@
1
+ export declare function compressedPointBytesAreOnCurve(bytes: Uint8Array): boolean;
2
+ //# sourceMappingURL=curve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"curve.d.ts","sourceRoot":"","sources":["../../src/curve.ts"],"names":[],"mappings":"AAiBA,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAMzE"}
@@ -0,0 +1,4 @@
1
+ export * from './address';
2
+ export * from './program-derived-address';
3
+ export * from './public-key';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,cAAc,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { ReadonlyUint8Array } from '@solana/codecs-core';
2
+ import { Address } from './address';
3
+ /**
4
+ * An address derived from a program address and a set of seeds.
5
+ * It includes the bump seed used to derive the address and
6
+ * ensure the address is not on the Ed25519 curve.
7
+ */
8
+ export type ProgramDerivedAddress<TAddress extends string = string> = Readonly<[
9
+ Address<TAddress>,
10
+ ProgramDerivedAddressBump
11
+ ]>;
12
+ /**
13
+ * A number between 0 and 255, inclusive.
14
+ */
15
+ export type ProgramDerivedAddressBump = number & {
16
+ readonly __brand: unique symbol;
17
+ };
18
+ /**
19
+ * Returns true if the input value is a program derived address.
20
+ */
21
+ export declare function isProgramDerivedAddress<TAddress extends string = string>(value: unknown): value is ProgramDerivedAddress<TAddress>;
22
+ /**
23
+ * Fails if the input value is not a program derived address.
24
+ */
25
+ export declare function assertIsProgramDerivedAddress<TAddress extends string = string>(value: unknown): asserts value is ProgramDerivedAddress<TAddress>;
26
+ type ProgramDerivedAddressInput = Readonly<{
27
+ programAddress: Address;
28
+ seeds: Seed[];
29
+ }>;
30
+ type SeedInput = Readonly<{
31
+ baseAddress: Address;
32
+ programAddress: Address;
33
+ seed: Seed;
34
+ }>;
35
+ type Seed = ReadonlyUint8Array | string;
36
+ export declare function getProgramDerivedAddress({ programAddress, seeds, }: ProgramDerivedAddressInput): Promise<ProgramDerivedAddress>;
37
+ export declare function createAddressWithSeed({ baseAddress, programAddress, seed }: SeedInput): Promise<Address>;
38
+ export {};
39
+ //# 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":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAa9D,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,CAYlD;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,kBAAkB,GAAG,MAAM,CAAC;AA2CxC,wBAAsB,wBAAwB,CAAC,EAC3C,cAAc,EACd,KAAK,GACR,EAAE,0BAA0B,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAkB7D;AAED,wBAAsB,qBAAqB,CAAC,EAAE,WAAW,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CA2B9G"}
@@ -0,0 +1,3 @@
1
+ import { Address } from './address';
2
+ export declare function getAddressFromPublicKey(publicKey: CryptoKey): Promise<Address>;
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":"AAGA,OAAO,EAAE,OAAO,EAAqB,MAAM,WAAW,CAAC;AAEvD,wBAAsB,uBAAuB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAOpF"}
@@ -0,0 +1,2 @@
1
+ export declare function pointIsOnCurve(y: bigint, lastByte: number): boolean;
2
+ //# sourceMappingURL=ed25519.d.ts.map
@@ -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 ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "@solana/addresses",
3
+ "version": "2.0.0-20241006045741",
4
+ "description": "Helpers for generating account addresses",
5
+ "exports": {
6
+ "edge-light": {
7
+ "import": "./dist/index.node.mjs",
8
+ "require": "./dist/index.node.cjs"
9
+ },
10
+ "workerd": {
11
+ "import": "./dist/index.node.mjs",
12
+ "require": "./dist/index.node.cjs"
13
+ },
14
+ "browser": {
15
+ "import": "./dist/index.browser.mjs",
16
+ "require": "./dist/index.browser.cjs"
17
+ },
18
+ "node": {
19
+ "import": "./dist/index.node.mjs",
20
+ "require": "./dist/index.node.cjs"
21
+ },
22
+ "react-native": "./dist/index.native.mjs",
23
+ "types": "./dist/types/index.d.ts"
24
+ },
25
+ "browser": {
26
+ "./dist/index.node.cjs": "./dist/index.browser.cjs",
27
+ "./dist/index.node.mjs": "./dist/index.browser.mjs"
28
+ },
29
+ "main": "./dist/index.node.cjs",
30
+ "module": "./dist/index.node.mjs",
31
+ "react-native": "./dist/index.native.mjs",
32
+ "types": "./dist/types/index.d.ts",
33
+ "type": "commonjs",
34
+ "files": [
35
+ "./dist/"
36
+ ],
37
+ "sideEffects": false,
38
+ "keywords": [
39
+ "blockchain",
40
+ "solana",
41
+ "web3"
42
+ ],
43
+ "author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
44
+ "license": "MIT",
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "https://github.com/solana-labs/solana-web3.js"
48
+ },
49
+ "bugs": {
50
+ "url": "http://github.com/solana-labs/solana-web3.js/issues"
51
+ },
52
+ "browserslist": [
53
+ "supports bigint and not dead",
54
+ "maintained node versions"
55
+ ],
56
+ "engine": {
57
+ "node": ">=17.4"
58
+ },
59
+ "dependencies": {
60
+ "@solana/assertions": "2.0.0-20241006045741",
61
+ "@solana/codecs-core": "2.0.0-20241006045741",
62
+ "@solana/codecs-strings": "2.0.0-20241006045741",
63
+ "@solana/errors": "2.0.0-20241006045741"
64
+ },
65
+ "peerDependencies": {
66
+ "typescript": ">=5"
67
+ },
68
+ "bundlewatch": {
69
+ "defaultCompression": "gzip",
70
+ "files": [
71
+ {
72
+ "path": "./dist/index*.js"
73
+ }
74
+ ]
75
+ },
76
+ "scripts": {
77
+ "compile:js": "tsup --config build-scripts/tsup.config.package.ts",
78
+ "compile:typedefs": "tsc -p ./tsconfig.declarations.json",
79
+ "dev": "jest -c ../../node_modules/@solana/test-config/jest-dev.config.ts --rootDir . --watch",
80
+ "publish-impl": "npm view $npm_package_name@$npm_package_version > /dev/null 2>&1 || pnpm publish --tag ${PUBLISH_TAG:-canary} --access public --no-git-checks",
81
+ "publish-packages": "pnpm prepublishOnly && pnpm publish-impl",
82
+ "style:fix": "pnpm eslint --fix src && pnpm prettier --log-level warn --ignore-unknown --write ./*",
83
+ "test:lint": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-lint.config.ts --rootDir . --silent",
84
+ "test:prettier": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-prettier.config.ts --rootDir . --silent",
85
+ "test:treeshakability:browser": "agadoo dist/index.browser.mjs",
86
+ "test:treeshakability:native": "agadoo dist/index.native.mjs",
87
+ "test:treeshakability:node": "agadoo dist/index.node.mjs",
88
+ "test:typecheck": "tsc --noEmit",
89
+ "test:unit:browser": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-unit.config.browser.ts --rootDir . --silent",
90
+ "test:unit:node": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-unit.config.node.ts --rootDir . --silent"
91
+ }
92
+ }