Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@solana/keys

Package Overview
Dependencies
Maintainers
13
Versions
1526
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/keys - npm Package Compare versions

Comparing version 2.0.0-experimental.4f36046 to 2.0.0-experimental.4f9ea6b

dist/types/guard.d.ts

100

dist/index.browser.js

@@ -43,4 +43,102 @@ import { base58, string } from '@metaplex-foundation/umi-serializers';

export { assertIsBase58EncodedAddress, getBase58EncodedAddressCodec, getBase58EncodedAddressComparator };
// src/guard.ts
function assertIsSecureContext() {
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 cachedEd25519Decision;
async function isEd25519CurveSupported(subtle) {
if (cachedEd25519Decision === void 0) {
cachedEd25519Decision = new Promise((resolve) => {
subtle.generateKey(
"Ed25519",
/* extractable */
false,
["sign", "verify"]
).catch(() => {
resolve(cachedEd25519Decision = false);
}).then(() => {
resolve(cachedEd25519Decision = true);
});
});
}
if (typeof cachedEd25519Decision === "boolean") {
return cachedEd25519Decision;
} else {
return await cachedEd25519Decision;
}
}
async function assertKeyGenerationIsAvailable() {
assertIsSecureContext();
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
throw new Error("No key generation implementation could be found");
}
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
throw new Error(
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
);
}
}
async function assertKeyExporterIsAvailable() {
assertIsSecureContext();
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
throw new Error("No key export implementation could be found");
}
}
async function assertSigningCapabilityIsAvailable() {
assertIsSecureContext();
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
throw new Error("No signing implementation could be found");
}
}
async function assertVerificationCapabilityIsAvailable() {
assertIsSecureContext();
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
throw new Error("No signature verification implementation could be found");
}
}
// src/key-pair.ts
async function generateKeyPair() {
await assertKeyGenerationIsAvailable();
const keyPair = await crypto.subtle.generateKey(
/* algorithm */
"Ed25519",
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
/* extractable */
false,
// Prevents the bytes of the private key from being visible to JS.
/* allowed uses */
["sign", "verify"]
);
return keyPair;
}
// src/pubkey.ts
async function getBase58EncodedAddressFromPublicKey(publicKey) {
await assertKeyExporterIsAvailable();
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
}
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
return base58EncodedAddress;
}
// src/signatures.ts
async function signBytes(key, data) {
await assertSigningCapabilityIsAvailable();
const signedData = await crypto.subtle.sign("Ed25519", key, data);
return new Uint8Array(signedData);
}
async function verifySignature(key, signature, data) {
await assertVerificationCapabilityIsAvailable();
return await crypto.subtle.verify("Ed25519", key, signature, data);
}
export { assertIsBase58EncodedAddress, generateKeyPair, getBase58EncodedAddressCodec, getBase58EncodedAddressComparator, getBase58EncodedAddressFromPublicKey, signBytes, verifySignature };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.browser.js.map

@@ -308,5 +308,107 @@ this.globalThis = this.globalThis || {};

// src/guard.ts
function assertIsSecureContext() {
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 cachedEd25519Decision;
async function isEd25519CurveSupported(subtle) {
if (cachedEd25519Decision === void 0) {
cachedEd25519Decision = new Promise((resolve) => {
subtle.generateKey(
"Ed25519",
/* extractable */
false,
["sign", "verify"]
).catch(() => {
resolve(cachedEd25519Decision = false);
}).then(() => {
resolve(cachedEd25519Decision = true);
});
});
}
if (typeof cachedEd25519Decision === "boolean") {
return cachedEd25519Decision;
} else {
return await cachedEd25519Decision;
}
}
async function assertKeyGenerationIsAvailable() {
assertIsSecureContext();
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
throw new Error("No key generation implementation could be found");
}
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
throw new Error(
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
);
}
}
async function assertKeyExporterIsAvailable() {
assertIsSecureContext();
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
throw new Error("No key export implementation could be found");
}
}
async function assertSigningCapabilityIsAvailable() {
assertIsSecureContext();
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
throw new Error("No signing implementation could be found");
}
}
async function assertVerificationCapabilityIsAvailable() {
assertIsSecureContext();
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
throw new Error("No signature verification implementation could be found");
}
}
// src/key-pair.ts
async function generateKeyPair() {
await assertKeyGenerationIsAvailable();
const keyPair = await crypto.subtle.generateKey(
/* algorithm */
"Ed25519",
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
/* extractable */
false,
// Prevents the bytes of the private key from being visible to JS.
/* allowed uses */
["sign", "verify"]
);
return keyPair;
}
// src/pubkey.ts
async function getBase58EncodedAddressFromPublicKey(publicKey) {
await assertKeyExporterIsAvailable();
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
}
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
return base58EncodedAddress;
}
// src/signatures.ts
async function signBytes(key, data) {
await assertSigningCapabilityIsAvailable();
const signedData = await crypto.subtle.sign("Ed25519", key, data);
return new Uint8Array(signedData);
}
async function verifySignature(key, signature, data) {
await assertVerificationCapabilityIsAvailable();
return await crypto.subtle.verify("Ed25519", key, signature, data);
}
exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
exports.generateKeyPair = generateKeyPair;
exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
exports.getBase58EncodedAddressFromPublicKey = getBase58EncodedAddressFromPublicKey;
exports.signBytes = signBytes;
exports.verifySignature = verifySignature;

@@ -313,0 +415,0 @@ return exports;

@@ -42,5 +42,90 @@ import { base58, string } from '@metaplex-foundation/umi-serializers';

}
var cachedEd25519Decision;
async function isEd25519CurveSupported(subtle) {
if (cachedEd25519Decision === void 0) {
cachedEd25519Decision = new Promise((resolve) => {
subtle.generateKey(
"Ed25519",
/* extractable */
false,
["sign", "verify"]
).catch(() => {
resolve(cachedEd25519Decision = false);
}).then(() => {
resolve(cachedEd25519Decision = true);
});
});
}
if (typeof cachedEd25519Decision === "boolean") {
return cachedEd25519Decision;
} else {
return await cachedEd25519Decision;
}
}
async function assertKeyGenerationIsAvailable() {
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
throw new Error("No key generation implementation could be found");
}
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
throw new Error(
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
);
}
}
async function assertKeyExporterIsAvailable() {
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
throw new Error("No key export implementation could be found");
}
}
async function assertSigningCapabilityIsAvailable() {
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
throw new Error("No signing implementation could be found");
}
}
async function assertVerificationCapabilityIsAvailable() {
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
throw new Error("No signature verification implementation could be found");
}
}
export { assertIsBase58EncodedAddress, getBase58EncodedAddressCodec, getBase58EncodedAddressComparator };
// src/key-pair.ts
async function generateKeyPair() {
await assertKeyGenerationIsAvailable();
const keyPair = await crypto.subtle.generateKey(
/* algorithm */
"Ed25519",
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
/* extractable */
false,
// Prevents the bytes of the private key from being visible to JS.
/* allowed uses */
["sign", "verify"]
);
return keyPair;
}
// src/pubkey.ts
async function getBase58EncodedAddressFromPublicKey(publicKey) {
await assertKeyExporterIsAvailable();
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
}
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
return base58EncodedAddress;
}
// src/signatures.ts
async function signBytes(key, data) {
await assertSigningCapabilityIsAvailable();
const signedData = await crypto.subtle.sign("Ed25519", key, data);
return new Uint8Array(signedData);
}
async function verifySignature(key, signature, data) {
await assertVerificationCapabilityIsAvailable();
return await crypto.subtle.verify("Ed25519", key, signature, data);
}
export { assertIsBase58EncodedAddress, generateKeyPair, getBase58EncodedAddressCodec, getBase58EncodedAddressComparator, getBase58EncodedAddressFromPublicKey, signBytes, verifySignature };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.native.js.map

@@ -42,5 +42,90 @@ import { base58, string } from '@metaplex-foundation/umi-serializers';

}
var cachedEd25519Decision;
async function isEd25519CurveSupported(subtle) {
if (cachedEd25519Decision === void 0) {
cachedEd25519Decision = new Promise((resolve) => {
subtle.generateKey(
"Ed25519",
/* extractable */
false,
["sign", "verify"]
).catch(() => {
resolve(cachedEd25519Decision = false);
}).then(() => {
resolve(cachedEd25519Decision = true);
});
});
}
if (typeof cachedEd25519Decision === "boolean") {
return cachedEd25519Decision;
} else {
return await cachedEd25519Decision;
}
}
async function assertKeyGenerationIsAvailable() {
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
throw new Error("No key generation implementation could be found");
}
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
throw new Error(
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
);
}
}
async function assertKeyExporterIsAvailable() {
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
throw new Error("No key export implementation could be found");
}
}
async function assertSigningCapabilityIsAvailable() {
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
throw new Error("No signing implementation could be found");
}
}
async function assertVerificationCapabilityIsAvailable() {
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
throw new Error("No signature verification implementation could be found");
}
}
export { assertIsBase58EncodedAddress, getBase58EncodedAddressCodec, getBase58EncodedAddressComparator };
// src/key-pair.ts
async function generateKeyPair() {
await assertKeyGenerationIsAvailable();
const keyPair = await crypto.subtle.generateKey(
/* algorithm */
"Ed25519",
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
/* extractable */
false,
// Prevents the bytes of the private key from being visible to JS.
/* allowed uses */
["sign", "verify"]
);
return keyPair;
}
// src/pubkey.ts
async function getBase58EncodedAddressFromPublicKey(publicKey) {
await assertKeyExporterIsAvailable();
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
}
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
return base58EncodedAddress;
}
// src/signatures.ts
async function signBytes(key, data) {
await assertSigningCapabilityIsAvailable();
const signedData = await crypto.subtle.sign("Ed25519", key, data);
return new Uint8Array(signedData);
}
async function verifySignature(key, signature, data) {
await assertVerificationCapabilityIsAvailable();
return await crypto.subtle.verify("Ed25519", key, signature, data);
}
export { assertIsBase58EncodedAddress, generateKeyPair, getBase58EncodedAddressCodec, getBase58EncodedAddressComparator, getBase58EncodedAddressFromPublicKey, signBytes, verifySignature };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.node.js.map

16

dist/index.production.min.js

@@ -5,10 +5,18 @@ this.globalThis = this.globalThis || {};

var O=Object.defineProperty;var U=(e,r,t)=>r in e?O(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var u=(e,r,t)=>(U(e,typeof r!="symbol"?r+"":r,t),t);var S=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},N=(e,r)=>{if(e.length>=r)return e;let t=new Uint8Array(r).fill(0);return t.set(e),t},g=(e,r)=>N(e.slice(0,r),r);var x=class extends Error{constructor(t){super(`Serializer [${t}] cannot deserialize empty buffers.`);u(this,"name","DeserializingEmptyBufferError");}},d=class extends Error{constructor(t,o,n){super(`Serializer [${t}] expected ${o} bytes, got ${n}.`);u(this,"name","NotEnoughBytesError");}};function w(e,r,t){return {description:t??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r,serialize:o=>g(e.serialize(o),r),deserialize:(o,n=0)=>{if(o=o.slice(n,n+r),o.length<r)throw new d("fixSerializer",r,o.length);e.fixedSize!==null&&(o=g(o,e.fixedSize));let[i]=e.deserialize(o,0);return [i,n+r]}}}var z=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 $=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 z(o,r);if(o==="")return new Uint8Array;let n=[...o],i=n.findIndex(m=>m!==e[0]);i=i===-1?n.length:i;let a=Array(i).fill(0);if(i===n.length)return Uint8Array.from(a);let p=n.slice(i),l=0n,c=1n;for(let m=p.length-1;m>=0;m-=1)l+=c*BigInt(e.indexOf(p[m])),c*=t;let f=[];for(;l>0n;)f.unshift(Number(l%256n)),l/=256n;return Uint8Array.from(a.concat(f))},deserialize(o,n=0){if(o.length===0)return ["",0];let i=o.slice(n),a=i.findIndex(f=>f!==0);a=a===-1?i.length:a;let p=e[0].repeat(a);if(a===i.length)return [p,o.length];let l=i.slice(a).reduce((f,m)=>f*256n+BigInt(m),0n),c=[];for(;l>0n;)c.unshift(e[Number(l%t)]),l/=t;return [p+c.join(""),o.length]}}};var h=$("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var I=e=>e.replace(/\u0000/g,"");var b={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 [I(t),e.length]}};var E;(function(e){e.Little="le",e.Big="be";})(E||(E={}));var y=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 v(e){let r,t=e.name;return e.size>1&&(r=!("endian"in e.options)||e.options.endian===E.Little,t+=r?"(le)":"(be)"),{description:e.options.description??t,fixedSize:e.size,maxSize:e.size,serialize(o){e.range&&_(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);L("i8",i,e.size);let a=R(i);return [e.get(a,r),n+e.size]}}}var C=e=>e.buffer.slice(e.byteOffset,e.byteLength+e.byteOffset),R=e=>new DataView(C(e)),_=(e,r,t,o)=>{if(o<r||o>t)throw new y(e,r,t,o)},L=(e,r,t)=>{if(r.length===0)throw new x(e);if(r.length<t)throw new d(e,t,r.length)};var B=(e={})=>v({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 A(e={}){let r=e.size??B(),t=e.encoding??b,o=e.description??`string(${t.description}; ${D(r)})`;return r==="variable"?{...t,description:o}:typeof r=="number"?w(t,r,o):{description:o,fixedSize:null,maxSize:null,serialize:n=>{let i=t.serialize(n),a=r.serialize(i.length);return S([a,i])},deserialize:(n,i=0)=>{if(n.slice(i).length===0)throw new x("string");let[a,p]=r.deserialize(n,i),l=Number(a);i=p;let c=n.slice(i,i+l);if(c.length<l)throw new d("string",l,c.length);let[f,m]=t.deserialize(c);return i+=m,[f,i]}}}function Je(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=h.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 Qe(e){return A({description:e?.description??"",encoding:h,size:32})}function We(){return new Intl.Collator("en",{caseFirst:"lower",ignorePunctuation:!1,localeMatcher:"best fit",numeric:!1,sensitivity:"variant",usage:"sort"}).compare}
var O=Object.defineProperty;var R=(e,r,t)=>r in e?O(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var m=(e,r,t)=>(R(e,typeof r!="symbol"?r+"":r,t),t);var S=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},x=(e,r)=>I(e.slice(0,r),r);var g=class extends Error{constructor(t){super(`Serializer [${t}] cannot deserialize empty buffers.`);m(this,"name","DeserializingEmptyBufferError");}},p=class extends Error{constructor(t,o,n){super(`Serializer [${t}] expected ${o} bytes, got ${n}.`);m(this,"name","NotEnoughBytesError");}};function A(e,r,t){return {description:t??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r,serialize:o=>x(e.serialize(o),r),deserialize:(o,n=0)=>{if(o=o.slice(n,n+r),o.length<r)throw new p("fixSerializer",r,o.length);e.fixedSize!==null&&(o=x(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);m(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 u=n.slice(i),l=0n,c=1n;for(let d=u.length-1;d>=0;d-=1)l+=c*BigInt(e.indexOf(u[d])),c*=t;let f=[];for(;l>0n;)f.unshift(Number(l%256n)),l/=256n;return Uint8Array.from(a.concat(f))},deserialize(o,n=0){if(o.length===0)return ["",0];let i=o.slice(n),a=i.findIndex(f=>f!==0);a=a===-1?i.length:a;let u=e[0].repeat(a);if(a===i.length)return [u,o.length];let l=i.slice(a).reduce((f,d)=>f*256n+BigInt(d),0n),c=[];for(;l>0n;)c.unshift(e[Number(l%t)]),l/=t;return [u+c.join(""),o.length]}}};var E=N("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var $=e=>e.replace(/\u0000/g,"");var B={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 [$(t),e.length]}};var b;(function(e){e.Little="le",e.Big="be";})(b||(b={}));var w=class extends RangeError{constructor(t,o,n,i){super(`Serializer [${t}] expected number to be between ${o} and ${n}, got ${i}.`);m(this,"name","NumberOutOfRangeError");}};function U(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&&F(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);j("i8",i,e.size);let a=V(i);return [e.get(a,r),n+e.size]}}}var L=e=>e.buffer.slice(e.byteOffset,e.byteLength+e.byteOffset),V=e=>new DataView(L(e)),F=(e,r,t,o)=>{if(o<r||o>t)throw new w(e,r,t,o)},j=(e,r,t)=>{if(r.length===0)throw new g(e);if(r.length<t)throw new p(e,t,r.length)};var v=(e={})=>U({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 C(e={}){let r=e.size??v(),t=e.encoding??B,o=e.description??`string(${t.description}; ${D(r)})`;return r==="variable"?{...t,description:o}:typeof r=="number"?A(t,r,o):{description:o,fixedSize:null,maxSize:null,serialize:n=>{let i=t.serialize(n),a=r.serialize(i.length);return S([a,i])},deserialize:(n,i=0)=>{if(n.slice(i).length===0)throw new g("string");let[a,u]=r.deserialize(n,i),l=Number(a);i=u;let c=n.slice(i,i+l);if(c.length<l)throw new p("string",l,c.length);let[f,d]=t.deserialize(c);return i+=d,[f,i]}}}function nr(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 K(e){return C({description:e?.description??"",encoding:E,size:32})}function ir(){return new Intl.Collator("en",{caseFirst:"lower",ignorePunctuation:!1,localeMatcher:"best fit",numeric:!1,sensitivity:"variant",usage:"sort"}).compare}function z(){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 y;async function X(e){return y===void 0&&(y=new Promise(r=>{e.generateKey("Ed25519",!1,["sign","verify"]).catch(()=>{r(y=!1);}).then(()=>{r(y=!0);});})),typeof y=="boolean"?y:await y}async function _(){if(z(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.generateKey!="function")throw new Error("No key generation implementation could be found");if(!await X(globalThis.crypto.subtle))throw new Error(`This runtime does not support the generation of Ed25519 key pairs.
exports.assertIsBase58EncodedAddress = Je;
exports.getBase58EncodedAddressCodec = Qe;
exports.getBase58EncodedAddressComparator = We;
Install and import \`@solana/webcrypto-ed25519-polyfill\` before generating keys in environments that do not support Ed25519.
For a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20`)}async function P(){if(z(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.exportKey!="function")throw new Error("No key export implementation could be found")}async function T(){if(z(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.sign!="function")throw new Error("No signing implementation could be found")}async function k(){if(z(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.verify!="function")throw new Error("No signature verification implementation could be found")}async function pr(){return await _(),await crypto.subtle.generateKey("Ed25519",!1,["sign","verify"])}async function xr(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]=K().deserialize(new Uint8Array(r));return t}async function wr(e,r){await T();let t=await crypto.subtle.sign("Ed25519",e,r);return new Uint8Array(t)}async function zr(e,r,t){return await k(),await crypto.subtle.verify("Ed25519",e,r,t)}
exports.assertIsBase58EncodedAddress = nr;
exports.generateKeyPair = pr;
exports.getBase58EncodedAddressCodec = K;
exports.getBase58EncodedAddressComparator = ir;
exports.getBase58EncodedAddressFromPublicKey = xr;
exports.signBytes = wr;
exports.verifySignature = zr;
return exports;
})({});
export * from './base58';
export * from './key-pair';
export * from './pubkey';
export * from './signatures';
//# sourceMappingURL=index.d.ts.map
{
"name": "@solana/keys",
"version": "2.0.0-experimental.4f36046",
"version": "2.0.0-experimental.4f9ea6b",
"description": "Helpers for generating and transforming key material",

@@ -55,11 +55,11 @@ "exports": {

"devDependencies": {
"@solana/eslint-config-solana": "^1.0.1",
"@solana/eslint-config-solana": "^1.0.2",
"@swc/core": "^1.3.18",
"@swc/jest": "^0.2.26",
"@types/jest": "^29.5.2",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"agadoo": "^3.0.0",
"eslint": "^8.37.0",
"eslint-plugin-jest": "^27.1.5",
"eslint": "^8.45.0",
"eslint-plugin-jest": "^27.2.3",
"eslint-plugin-react-hooks": "^4.6.0",

@@ -75,3 +75,3 @@ "eslint-plugin-sort-keys-fix": "^1.1.2",

"tsup": "6.7.0",
"typescript": "^5.0.4",
"typescript": "^5.1.6",
"version-from-git": "^1.1.1",

@@ -78,0 +78,0 @@ "build-scripts": "0.0.0",

@@ -27,2 +27,8 @@ [![npm][npm-image]][npm-url]

### `Ed25519Signature`
This type represents a 64-byte Ed25519 signature of some data with a private key.
Whenever you need to verify that a particular signature is, in fact, the one that would have been produced by signing some known bytes using the private key associated with some known public key, use the `verifySignature()` function in this package.
## Functions

@@ -37,3 +43,3 @@

```ts
import { assertIsBase58EncodedAddress } from '@solana/web3.js`;
import { assertIsBase58EncodedAddress } from '@solana/keys';

@@ -55,1 +61,45 @@ // Imagine a function that fetches an account's balance when a user submits a form.

```
### `generateKeyPair()`
Generates an Ed25519 public/private key pair for use with other methods in this package that accept `CryptoKey` objects.
```ts
import { generateKeyPair } from '@solana/keys';
const { privateKey, publicKey } = await generateKeyPair();
```
### `getBase58EncodedAddressFromPublicKey()`
Given a public `CryptoKey`, this method will return its associated `Base58EncodedAddress`.
```ts
import { getBase58EncodedAddressFromPublicKey } from '@solana/keys';
const address = await getBase58EncodedAddressFromPublicKey(publicKey);
```
### `signBytes()`
Given a private `CryptoKey` and a `Uint8Array` of bytes, this method will return the 64-byte Ed25519 signature of that data as a `Uint8Array`.
```ts
import { signBytes } from '@solana/keys';
const data = new Uint8Array([1, 2, 3]);
const signature = await signBytes(privateKey, data);
```
### `verifySignature()`
Given a public `CryptoKey`, an `Ed25519Signature`, and a `Uint8Array` of bytes, this method will return `true` if the signature was produced by signing the bytes using the private key associated with the public key, and `false` otherwise.
```ts
import { verifySignature } from '@solana/keys';
const data = new Uint8Array([1, 2, 3]);
if (!(await verifySignature(publicKey, signature, data))) {
throw new Error('The data were *not* signed by the private key associated with `publicKey`');
}
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc