@solana/keys 2.0.0-experimental.457d032 → 2.0.0-experimental.45c014d

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.
@@ -2,13 +2,18 @@ this.globalThis = this.globalThis || {};
2
2
  this.globalThis.solanaWeb3 = (function (exports) {
3
3
  'use strict';
4
4
 
5
- var U=Object.defineProperty;var O=(e,r,t)=>r in e?U(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var u=(e,r,t)=>(O(e,typeof r!="symbol"?r+"":r,t),t);var w=e=>{let r=e.reduce((n,i)=>n+i.length,0),t=new Uint8Array(r),o=0;return e.forEach(n=>{t.set(n,o),o+=n.length;}),t},I=(e,r)=>{if(e.length>=r)return e;let t=new Uint8Array(r).fill(0);return t.set(e),t},y=(e,r)=>I(e.slice(0,r),r);var g=class extends Error{constructor(t){super(`Serializer [${t}] cannot deserialize empty buffers.`);u(this,"name","DeserializingEmptyBufferError");}},f=class extends Error{constructor(t,o,n){super(`Serializer [${t}] expected ${o} bytes, got ${n}.`);u(this,"name","NotEnoughBytesError");}};function S(e,r,t){return {description:t??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r,serialize:o=>y(e.serialize(o),r),deserialize:(o,n=0)=>{if(o=o.slice(n,n+r),o.length<r)throw new f("fixSerializer",r,o.length);e.fixedSize!==null&&(o=y(o,e.fixedSize));let[i]=e.deserialize(o,0);return [i,n+r]}}}var h=class extends Error{constructor(t,o,n){let i=`Expected a string of base ${o}, got [${t}].`;super(i);u(this,"name","InvalidBaseStringError");this.cause=n;}};var N=e=>{let r=e.length,t=BigInt(r);return {description:`base${r}`,fixedSize:null,maxSize:null,serialize(o){if(!o.match(new RegExp(`^[${e}]*$`)))throw new h(o,r);if(o==="")return new Uint8Array;let n=[...o],i=n.findIndex(d=>d!==e[0]);i=i===-1?n.length:i;let a=Array(i).fill(0);if(i===n.length)return Uint8Array.from(a);let m=n.slice(i),l=0n,c=1n;for(let d=m.length-1;d>=0;d-=1)l+=c*BigInt(e.indexOf(m[d])),c*=t;let p=[];for(;l>0n;)p.unshift(Number(l%256n)),l/=256n;return Uint8Array.from(a.concat(p))},deserialize(o,n=0){if(o.length===0)return ["",0];let i=o.slice(n),a=i.findIndex(p=>p!==0);a=a===-1?i.length:a;let m=e[0].repeat(a);if(a===i.length)return [m,o.length];let l=i.slice(a).reduce((p,d)=>p*256n+BigInt(d),0n),c=[];for(;l>0n;)c.unshift(e[Number(l%t)]),l/=t;return [m+c.join(""),o.length]}}};var E=N("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var C=e=>e.replace(/\u0000/g,"");var A={description:"utf8",fixedSize:null,maxSize:null,serialize(e){return new TextEncoder().encode(e)},deserialize(e,r=0){let t=new TextDecoder().decode(e.slice(r));return [C(t),e.length]}};var b;(function(e){e.Little="le",e.Big="be";})(b||(b={}));var z=class extends RangeError{constructor(t,o,n,i){super(`Serializer [${t}] expected number to be between ${o} and ${n}, got ${i}.`);u(this,"name","NumberOutOfRangeError");}};function $(e){let r,t=e.name;return e.size>1&&(r=!("endian"in e.options)||e.options.endian===b.Little,t+=r?"(le)":"(be)"),{description:e.options.description??t,fixedSize:e.size,maxSize:e.size,serialize(o){e.range&&L(e.name,e.range[0],e.range[1],o);let n=new ArrayBuffer(e.size);return e.set(new DataView(n),o,r),new Uint8Array(n)},deserialize(o,n=0){let i=o.slice(n,n+e.size);V("i8",i,e.size);let a=k(i);return [e.get(a,r),n+e.size]}}}var R=e=>e.buffer.slice(e.byteOffset,e.byteLength+e.byteOffset),k=e=>new DataView(R(e)),L=(e,r,t,o)=>{if(o<r||o>t)throw new z(e,r,t,o)},V=(e,r,t)=>{if(r.length===0)throw new g(e);if(r.length<t)throw new f(e,t,r.length)};var B=(e={})=>$({name:"u32",size:4,range:[0,+"0xffffffff"],set:(r,t,o)=>r.setUint32(0,Number(t),o),get:(r,t)=>r.getUint32(0,t),options:e});function D(e){return typeof e=="object"?e.description:`${e}`}function v(e={}){let r=e.size??B(),t=e.encoding??A,o=e.description??`string(${t.description}; ${D(r)})`;return r==="variable"?{...t,description:o}:typeof r=="number"?S(t,r,o):{description:o,fixedSize:null,maxSize:null,serialize:n=>{let i=t.serialize(n),a=r.serialize(i.length);return w([a,i])},deserialize:(n,i=0)=>{if(n.slice(i).length===0)throw new g("string");let[a,m]=r.deserialize(n,i),l=Number(a);i=m;let c=n.slice(i,i+l);if(c.length<l)throw new f("string",l,c.length);let[p,d]=t.deserialize(c);return i+=d,[p,i]}}}function tr(e){try{if(e.length<32||e.length>44)throw new Error("Expected input string to decode to a byte array of length 32.");let t=E.serialize(e).byteLength;if(t!==32)throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${t}`)}catch(r){throw new Error(`\`${e}\` is not a base-58 encoded address`,{cause:r})}}function T(e){return v({description:e?.description??"",encoding:E,size:32})}function or(){return new Intl.Collator("en",{caseFirst:"lower",ignorePunctuation:!1,localeMatcher:"best fit",numeric:!1,sensitivity:"variant",usage:"sort"}).compare}function K(){if(!globalThis.isSecureContext)throw new Error("Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts")}var x;async function F(e){return x===void 0&&(x=new Promise(r=>{e.generateKey("Ed25519",!1,["sign","verify"]).catch(()=>{r(x=!1);}).then(()=>{r(x=!0);});})),typeof x=="boolean"?x:await x}async function _(){if(K(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.generateKey!="function")throw new Error("No key generation implementation could be found");if(!await F(globalThis.crypto.subtle))throw new Error("This runtime does not support the generation of Ed25519 keypairs")}async function P(){if(K(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.exportKey!="function")throw new Error("No key export implementation could be found")}async function cr(){return await _(),await crypto.subtle.generateKey("Ed25519",!1,["sign","verify"])}async function gr(e){if(await P(),e.type!=="public"||e.algorithm.name!=="Ed25519")throw new Error("The `CryptoKey` must be an `Ed25519` public key");let r=await crypto.subtle.exportKey("raw",e),[t]=T().deserialize(new Uint8Array(r));return t}
5
+ function u(){if(!globalThis.isSecureContext)throw new Error("Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts")}var r;async function v(e){return r===void 0&&(r=new Promise(t=>{e.generateKey("Ed25519",!1,["sign","verify"]).catch(()=>{t(r=!1);}).then(()=>{t(r=!0);});})),typeof r=="boolean"?r:await r}async function b(){var e;if(u(),typeof globalThis.crypto>"u"||typeof((e=globalThis.crypto.subtle)==null?void 0:e.generateKey)!="function")throw new Error("No key generation implementation could be found");if(!await v(globalThis.crypto.subtle))throw new Error(`This runtime does not support the generation of Ed25519 key pairs.
6
6
 
7
- exports.assertIsBase58EncodedAddress = tr;
8
- exports.generateKeyPair = cr;
9
- exports.getBase58EncodedAddressCodec = T;
10
- exports.getBase58EncodedAddressComparator = or;
11
- exports.getBase58EncodedAddressFromPublicKey = gr;
7
+ Install and import \`@solana/webcrypto-ed25519-polyfill\` before generating keys in environments that do not support Ed25519.
8
+
9
+ For a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20`)}async function m(){var e;if(u(),typeof globalThis.crypto>"u"||typeof((e=globalThis.crypto.subtle)==null?void 0:e.sign)!="function")throw new Error("No signing implementation could be found")}async function x(){var e;if(u(),typeof globalThis.crypto>"u"||typeof((e=globalThis.crypto.subtle)==null?void 0:e.verify)!="function")throw new Error("No signature verification implementation could be found")}async function D(){return await b(),await crypto.subtle.generateKey("Ed25519",!1,["sign","verify"])}function E(e,t,n=t){if(!t.match(new RegExp(`^[${e}]*$`)))throw new Error(`Expected a string of base ${e.length}, got [${n}].`)}var S=e=>{let t=e.length,n=BigInt(t);return {description:`base${t}`,encode(d){if(E(e,d),d==="")return new Uint8Array;let a=[...d],o=a.findIndex(s=>s!==e[0]);o=o===-1?a.length:o;let f=Array(o).fill(0);if(o===a.length)return Uint8Array.from(f);let y=a.slice(o),c=0n,p=1n;for(let s=y.length-1;s>=0;s-=1)c+=p*BigInt(e.indexOf(y[s])),p*=n;let h=[];for(;c>0n;)h.unshift(Number(c%256n)),c/=256n;return Uint8Array.from(f.concat(h))},fixedSize:null,maxSize:null}};var w="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",g=()=>S(w);var i;function C(e){i||(i=g());try{if(e.length<64||e.length>88)throw new Error("Expected input string to decode to a byte array of length 64.");let n=i.encode(e).byteLength;if(n!==64)throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${n}`)}catch(t){throw new Error(`\`${e}\` is not a signature`,{cause:t})}}function X(e){return i||(i=g()),!(e.length<64||e.length>88||i.encode(e).byteLength!==64)}async function R(e,t){await m();let n=await crypto.subtle.sign("Ed25519",e,t);return new Uint8Array(n)}function V(e){return C(e),e}async function O(e,t,n){return await x(),await crypto.subtle.verify("Ed25519",e,t,n)}
10
+
11
+ exports.assertIsSignature = C;
12
+ exports.generateKeyPair = D;
13
+ exports.isSignature = X;
14
+ exports.signBytes = R;
15
+ exports.signature = V;
16
+ exports.verifySignature = O;
12
17
 
13
18
  return exports;
14
19
 
@@ -1,4 +1,3 @@
1
- export * from './base58';
2
1
  export * from './key-pair';
3
- export * from './pubkey';
2
+ export * from './signatures';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-pair.d.ts","sourceRoot":"","sources":["../../src/key-pair.ts"],"names":[],"mappings":"AAEA,wBAAsB,eAAe,IAAI,OAAO,CAAC,aAAa,CAAC,CAQ9D"}
@@ -0,0 +1,12 @@
1
+ export type Signature = string & {
2
+ readonly __brand: unique symbol;
3
+ };
4
+ export type SignatureBytes = Uint8Array & {
5
+ readonly __brand: unique symbol;
6
+ };
7
+ export declare function assertIsSignature(putativeSignature: string): asserts putativeSignature is Signature;
8
+ export declare function isSignature(putativeSignature: string): putativeSignature is Signature;
9
+ export declare function signBytes(key: CryptoKey, data: Uint8Array): Promise<SignatureBytes>;
10
+ export declare function signature(putativeSignature: string): Signature;
11
+ export declare function verifySignature(key: CryptoKey, signature: SignatureBytes, data: Uint8Array): Promise<boolean>;
12
+ //# sourceMappingURL=signatures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signatures.d.ts","sourceRoot":"","sources":["../../src/signatures.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,MAAM,CAAA;CAAE,CAAC;AACrE,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,MAAM,CAAA;CAAE,CAAC;AAI9E,wBAAgB,iBAAiB,CAAC,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,IAAI,SAAS,CAwBnG;AAED,wBAAgB,WAAW,CAAC,iBAAiB,EAAE,MAAM,GAAG,iBAAiB,IAAI,SAAS,CAmBrF;AAED,wBAAsB,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC,CAIzF;AAED,wBAAgB,SAAS,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAG9D;AAED,wBAAsB,eAAe,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAGnH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/keys",
3
- "version": "2.0.0-experimental.457d032",
3
+ "version": "2.0.0-experimental.45c014d",
4
4
  "description": "Helpers for generating and transforming key material",
5
5
  "exports": {
6
6
  "browser": {
@@ -49,29 +49,27 @@
49
49
  "node": ">=17.4"
50
50
  },
51
51
  "dependencies": {
52
- "@metaplex-foundation/umi-serializers": "^0.8.2"
52
+ "@solana/assertions": "2.0.0-experimental.45c014d",
53
+ "@solana/codecs-core": "2.0.0-experimental.45c014d",
54
+ "@solana/codecs-strings": "2.0.0-experimental.45c014d"
53
55
  },
54
56
  "devDependencies": {
55
57
  "@solana/eslint-config-solana": "^1.0.2",
56
- "@swc/core": "^1.3.18",
57
- "@swc/jest": "^0.2.26",
58
- "@types/jest": "^29.5.2",
59
- "@typescript-eslint/eslint-plugin": "^6.0.0",
60
- "@typescript-eslint/parser": "^6.0.0",
58
+ "@swc/jest": "^0.2.29",
59
+ "@types/jest": "^29.5.6",
60
+ "@typescript-eslint/eslint-plugin": "^6.7.0",
61
+ "@typescript-eslint/parser": "^6.3.0",
61
62
  "agadoo": "^3.0.0",
62
63
  "eslint": "^8.45.0",
63
- "eslint-plugin-jest": "^27.2.3",
64
- "eslint-plugin-react-hooks": "^4.6.0",
64
+ "eslint-plugin-jest": "^27.4.2",
65
65
  "eslint-plugin-sort-keys-fix": "^1.1.2",
66
- "jest": "^29.6.1",
67
- "jest-environment-jsdom": "^29.6.0",
68
- "jest-runner-eslint": "^2.1.0",
66
+ "jest": "^29.7.0",
67
+ "jest-environment-jsdom": "^29.7.0",
68
+ "jest-runner-eslint": "^2.1.2",
69
69
  "jest-runner-prettier": "^1.0.0",
70
- "postcss": "^8.4.12",
71
- "prettier": "^2.8.8",
72
- "ts-node": "^10.9.1",
73
- "tsup": "6.7.0",
74
- "typescript": "^5.1.6",
70
+ "prettier": "^2.8",
71
+ "tsup": "^8.0.1",
72
+ "typescript": "^5.2.2",
75
73
  "version-from-git": "^1.1.1",
76
74
  "build-scripts": "0.0.0",
77
75
  "test-config": "0.0.0",
@@ -90,11 +88,12 @@
90
88
  "compile:typedefs": "tsc -p ./tsconfig.declarations.json",
91
89
  "dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
92
90
  "publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
91
+ "style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
93
92
  "test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
94
93
  "test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
95
94
  "test:treeshakability:browser": "agadoo dist/index.browser.js",
96
- "test:treeshakability:native": "agadoo dist/index.node.js",
97
- "test:treeshakability:node": "agadoo dist/index.native.js",
95
+ "test:treeshakability:native": "agadoo dist/index.native.js",
96
+ "test:treeshakability:node": "agadoo dist/index.node.js",
98
97
  "test:typecheck": "tsc --noEmit",
99
98
  "test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent",
100
99
  "test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --rootDir . --silent"
@@ -1,10 +0,0 @@
1
- import { Serializer } from '@metaplex-foundation/umi-serializers';
2
- export type Base58EncodedAddress<TAddress extends string = string> = TAddress & {
3
- readonly __base58EncodedAddress: unique symbol;
4
- };
5
- export declare function assertIsBase58EncodedAddress(putativeBase58EncodedAddress: string): asserts putativeBase58EncodedAddress is Base58EncodedAddress<typeof putativeBase58EncodedAddress>;
6
- export declare function getBase58EncodedAddressCodec(config?: Readonly<{
7
- description: string;
8
- }>): Serializer<Base58EncodedAddress>;
9
- export declare function getBase58EncodedAddressComparator(): (x: string, y: string) => number;
10
- //# sourceMappingURL=base58.d.ts.map
@@ -1,5 +0,0 @@
1
- export declare function assertKeyGenerationIsAvailable(): Promise<void>;
2
- export declare function assertKeyExporterIsAvailable(): Promise<void>;
3
- export declare function assertSigningCapabilityIsAvailable(): Promise<void>;
4
- export declare function assertVerificationCapabilityIsAvailable(): Promise<void>;
5
- //# sourceMappingURL=guard.d.ts.map
@@ -1,3 +0,0 @@
1
- import { Base58EncodedAddress } from './base58';
2
- export declare function getBase58EncodedAddressFromPublicKey(publicKey: CryptoKey): Promise<Base58EncodedAddress>;
3
- //# sourceMappingURL=pubkey.d.ts.map