@solana/keys
Advanced tools
Comparing version 2.0.0-experimental.0b7dd02 to 2.0.0-experimental.0b7eadc
@@ -1,27 +0,30 @@ | ||
import bs58 from 'bs58'; | ||
import { assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions'; | ||
// src/base58.ts | ||
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) { | ||
try { | ||
if ( | ||
// Lowest address (32 bytes of zeroes) | ||
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255) | ||
putativeBase58EncodedAddress.length > 44 | ||
) { | ||
throw new Error("Expected input string to decode to a byte array of length 32."); | ||
} | ||
const bytes = bs58.decode(putativeBase58EncodedAddress); | ||
const numBytes = bytes.byteLength; | ||
if (numBytes !== 32) { | ||
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`); | ||
} | ||
} catch (e) { | ||
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, { | ||
cause: e | ||
}); | ||
} | ||
// 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; | ||
} | ||
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 }; | ||
export { generateKeyPair, signBytes, verifySignature }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.browser.js.map |
@@ -5,206 +5,86 @@ this.globalThis = this.globalThis || {}; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __esm = (fn, res) => function __init() { | ||
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; | ||
}; | ||
var __commonJS = (cb, mod) => function __require() { | ||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
// ../assertions/dist/index.browser.js | ||
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" | ||
); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
// ../build-scripts/env-shim.ts | ||
var init_env_shim = __esm({ | ||
"../build-scripts/env-shim.ts"() { | ||
} | ||
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); | ||
}); | ||
}); | ||
} | ||
}); | ||
// ../../node_modules/.pnpm/base-x@4.0.0/node_modules/base-x/src/index.js | ||
var require_src = __commonJS({ | ||
"../../node_modules/.pnpm/base-x@4.0.0/node_modules/base-x/src/index.js"(exports, module) { | ||
init_env_shim(); | ||
function base(ALPHABET) { | ||
if (ALPHABET.length >= 255) { | ||
throw new TypeError("Alphabet too long"); | ||
} | ||
var BASE_MAP = new Uint8Array(256); | ||
for (var j = 0; j < BASE_MAP.length; j++) { | ||
BASE_MAP[j] = 255; | ||
} | ||
for (var i = 0; i < ALPHABET.length; i++) { | ||
var x = ALPHABET.charAt(i); | ||
var xc = x.charCodeAt(0); | ||
if (BASE_MAP[xc] !== 255) { | ||
throw new TypeError(x + " is ambiguous"); | ||
} | ||
BASE_MAP[xc] = i; | ||
} | ||
var BASE = ALPHABET.length; | ||
var LEADER = ALPHABET.charAt(0); | ||
var FACTOR = Math.log(BASE) / Math.log(256); | ||
var iFACTOR = Math.log(256) / Math.log(BASE); | ||
function encode(source) { | ||
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) { | ||
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength); | ||
} else if (Array.isArray(source)) { | ||
source = Uint8Array.from(source); | ||
} | ||
if (!(source instanceof Uint8Array)) { | ||
throw new TypeError("Expected Uint8Array"); | ||
} | ||
if (source.length === 0) { | ||
return ""; | ||
} | ||
var zeroes = 0; | ||
var length = 0; | ||
var pbegin = 0; | ||
var pend = source.length; | ||
while (pbegin !== pend && source[pbegin] === 0) { | ||
pbegin++; | ||
zeroes++; | ||
} | ||
var size = (pend - pbegin) * iFACTOR + 1 >>> 0; | ||
var b58 = new Uint8Array(size); | ||
while (pbegin !== pend) { | ||
var carry = source[pbegin]; | ||
var i2 = 0; | ||
for (var it1 = size - 1; (carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) { | ||
carry += 256 * b58[it1] >>> 0; | ||
b58[it1] = carry % BASE >>> 0; | ||
carry = carry / BASE >>> 0; | ||
} | ||
if (carry !== 0) { | ||
throw new Error("Non-zero carry"); | ||
} | ||
length = i2; | ||
pbegin++; | ||
} | ||
var it2 = size - length; | ||
while (it2 !== size && b58[it2] === 0) { | ||
it2++; | ||
} | ||
var str = LEADER.repeat(zeroes); | ||
for (; it2 < size; ++it2) { | ||
str += ALPHABET.charAt(b58[it2]); | ||
} | ||
return str; | ||
} | ||
function decodeUnsafe(source) { | ||
if (typeof source !== "string") { | ||
throw new TypeError("Expected String"); | ||
} | ||
if (source.length === 0) { | ||
return new Uint8Array(); | ||
} | ||
var psz = 0; | ||
var zeroes = 0; | ||
var length = 0; | ||
while (source[psz] === LEADER) { | ||
zeroes++; | ||
psz++; | ||
} | ||
var size = (source.length - psz) * FACTOR + 1 >>> 0; | ||
var b256 = new Uint8Array(size); | ||
while (source[psz]) { | ||
var carry = BASE_MAP[source.charCodeAt(psz)]; | ||
if (carry === 255) { | ||
return; | ||
} | ||
var i2 = 0; | ||
for (var it3 = size - 1; (carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) { | ||
carry += BASE * b256[it3] >>> 0; | ||
b256[it3] = carry % 256 >>> 0; | ||
carry = carry / 256 >>> 0; | ||
} | ||
if (carry !== 0) { | ||
throw new Error("Non-zero carry"); | ||
} | ||
length = i2; | ||
psz++; | ||
} | ||
var it4 = size - length; | ||
while (it4 !== size && b256[it4] === 0) { | ||
it4++; | ||
} | ||
var vch = new Uint8Array(zeroes + (size - it4)); | ||
var j2 = zeroes; | ||
while (it4 !== size) { | ||
vch[j2++] = b256[it4++]; | ||
} | ||
return vch; | ||
} | ||
function decode(string) { | ||
var buffer = decodeUnsafe(string); | ||
if (buffer) { | ||
return buffer; | ||
} | ||
throw new Error("Non-base" + BASE + " character"); | ||
} | ||
return { | ||
encode, | ||
decodeUnsafe, | ||
decode | ||
}; | ||
} | ||
module.exports = base; | ||
if (typeof cachedEd25519Decision === "boolean") { | ||
return cachedEd25519Decision; | ||
} else { | ||
return await cachedEd25519Decision; | ||
} | ||
}); | ||
// ../../node_modules/.pnpm/bs58@5.0.0/node_modules/bs58/index.js | ||
var require_bs58 = __commonJS({ | ||
"../../node_modules/.pnpm/bs58@5.0.0/node_modules/bs58/index.js"(exports, module) { | ||
init_env_shim(); | ||
var basex = require_src(); | ||
var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; | ||
module.exports = basex(ALPHABET); | ||
} | ||
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 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/index.ts | ||
init_env_shim(); | ||
// 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/base58.ts | ||
init_env_shim(); | ||
var import_bs58 = __toESM(require_bs58(), 1); | ||
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) { | ||
try { | ||
if ( | ||
// Lowest address (32 bytes of zeroes) | ||
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255) | ||
putativeBase58EncodedAddress.length > 44 | ||
) { | ||
throw new Error("Expected input string to decode to a byte array of length 32."); | ||
} | ||
const bytes = import_bs58.default.decode(putativeBase58EncodedAddress); | ||
const numBytes = bytes.byteLength; | ||
if (numBytes !== 32) { | ||
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`); | ||
} | ||
} catch (e) { | ||
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, { | ||
cause: e | ||
}); | ||
} | ||
// 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.signBytes = signBytes; | ||
exports.verifySignature = verifySignature; | ||
@@ -211,0 +91,0 @@ return exports; |
@@ -1,27 +0,30 @@ | ||
import bs58 from 'bs58'; | ||
import { assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions'; | ||
// src/base58.ts | ||
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) { | ||
try { | ||
if ( | ||
// Lowest address (32 bytes of zeroes) | ||
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255) | ||
putativeBase58EncodedAddress.length > 44 | ||
) { | ||
throw new Error("Expected input string to decode to a byte array of length 32."); | ||
} | ||
const bytes = bs58.decode(putativeBase58EncodedAddress); | ||
const numBytes = bytes.byteLength; | ||
if (numBytes !== 32) { | ||
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`); | ||
} | ||
} catch (e) { | ||
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, { | ||
cause: e | ||
}); | ||
} | ||
// 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; | ||
} | ||
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 }; | ||
export { generateKeyPair, signBytes, verifySignature }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.native.js.map |
@@ -1,27 +0,30 @@ | ||
import bs58 from 'bs58'; | ||
import { assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable } from '@solana/assertions'; | ||
// src/base58.ts | ||
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) { | ||
try { | ||
if ( | ||
// Lowest address (32 bytes of zeroes) | ||
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255) | ||
putativeBase58EncodedAddress.length > 44 | ||
) { | ||
throw new Error("Expected input string to decode to a byte array of length 32."); | ||
} | ||
const bytes = bs58.decode(putativeBase58EncodedAddress); | ||
const numBytes = bytes.byteLength; | ||
if (numBytes !== 32) { | ||
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`); | ||
} | ||
} catch (e) { | ||
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, { | ||
cause: e | ||
}); | ||
} | ||
// 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; | ||
} | ||
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 }; | ||
export { generateKeyPair, signBytes, verifySignature }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.node.js.map |
@@ -5,8 +5,14 @@ this.globalThis = this.globalThis || {}; | ||
var S=Object.create;var m=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var $=(e,r)=>()=>(e&&(r=e(e=0)),r);var u=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var k=(e,r,n,p)=>{if(r&&typeof r=="object"||typeof r=="function")for(let l of q(r))!F.call(e,l)&&l!==n&&m(e,l,{get:()=>r[l],enumerable:!(p=V(r,l))||p.enumerable});return e};var G=(e,r,n)=>(n=e!=null?S(B(e)):{},k(r||!e||!e.__esModule?m(n,"default",{value:e,enumerable:!0}):n,e));var w=$(()=>{});var _=u((X,z)=>{w();function I(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var p=0;p<e.length;p++){var l=e.charAt(p),c=l.charCodeAt(0);if(r[c]!==255)throw new TypeError(l+" is ambiguous");r[c]=p;}var A=e.length,U=e.charAt(0),T=Math.log(A)/Math.log(256),D=Math.log(256)/Math.log(A);function O(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(t.length===0)return "";for(var a=0,y=0,i=0,h=t.length;i!==h&&t[i]===0;)i++,a++;for(var d=(h-i)*D+1>>>0,o=new Uint8Array(d);i!==h;){for(var f=t[i],g=0,s=d-1;(f!==0||g<y)&&s!==-1;s--,g++)f+=256*o[s]>>>0,o[s]=f%A>>>0,f=f/A>>>0;if(f!==0)throw new Error("Non-zero carry");y=g,i++;}for(var v=d-y;v!==d&&o[v]===0;)v++;for(var b=U.repeat(a);v<d;++v)b+=e.charAt(o[v]);return b}function x(t){if(typeof t!="string")throw new TypeError("Expected String");if(t.length===0)return new Uint8Array;for(var a=0,y=0,i=0;t[a]===U;)y++,a++;for(var h=(t.length-a)*T+1>>>0,d=new Uint8Array(h);t[a];){var o=r[t.charCodeAt(a)];if(o===255)return;for(var f=0,g=h-1;(o!==0||f<i)&&g!==-1;g--,f++)o+=A*d[g]>>>0,d[g]=o%256>>>0,o=o/256>>>0;if(o!==0)throw new Error("Non-zero carry");i=f,a++;}for(var s=h-i;s!==h&&d[s]===0;)s++;for(var v=new Uint8Array(y+(h-s)),b=y;s!==h;)v[b++]=d[s++];return v}function R(t){var a=x(t);if(a)return a;throw new Error("Non-base"+A+" character")}return {encode:O,decodeUnsafe:x,decode:R}}z.exports=I;});var N=u((Z,M)=>{w();var J=_(),K="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";M.exports=J(K);});w();w();var C=G(N(),1);function L(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 n=C.default.decode(e).byteLength;if(n!==32)throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${n}`)}catch(r){throw new Error(`\`${e}\` is not a base-58 encoded address`,{cause:r})}} | ||
function n(){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 e;async function y(t){return e===void 0&&(e=new Promise(o=>{t.generateKey("Ed25519",!1,["sign","verify"]).catch(()=>{o(e=!1);}).then(()=>{o(e=!0);});})),typeof e=="boolean"?e:await e}async function a(){if(n(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.generateKey!="function")throw new Error("No key generation implementation could be found");if(!await y(globalThis.crypto.subtle))throw new Error(`This runtime does not support the generation of Ed25519 key pairs. | ||
exports.assertIsBase58EncodedAddress = L; | ||
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 s(){if(n(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.sign!="function")throw new Error("No signing implementation could be found")}async function l(){if(n(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.verify!="function")throw new Error("No signature verification implementation could be found")}async function d(){return await a(),await crypto.subtle.generateKey("Ed25519",!1,["sign","verify"])}async function m(t,o){await s();let r=await crypto.subtle.sign("Ed25519",t,o);return new Uint8Array(r)}async function w(t,o,r){return await l(),await crypto.subtle.verify("Ed25519",t,o,r)} | ||
exports.generateKeyPair = d; | ||
exports.signBytes = m; | ||
exports.verifySignature = w; | ||
return exports; | ||
})({}); |
@@ -1,2 +0,3 @@ | ||
export * from './base58'; | ||
export * from './key-pair'; | ||
export * from './signatures'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@solana/keys", | ||
"version": "2.0.0-experimental.0b7dd02", | ||
"version": "2.0.0-experimental.0b7eadc", | ||
"description": "Helpers for generating and transforming key material", | ||
@@ -48,27 +48,29 @@ "exports": { | ||
], | ||
"engine": { | ||
"node": ">=17.4" | ||
}, | ||
"dependencies": { | ||
"@solana/assertions": "2.0.0-experimental.0b7eadc" | ||
}, | ||
"devDependencies": { | ||
"@solana/eslint-config-solana": "^1.0.1", | ||
"@swc/core": "^1.3.18", | ||
"@swc/jest": "^0.2.23", | ||
"@types/jest": "^29.5.1", | ||
"@typescript-eslint/eslint-plugin": "^5.57.1", | ||
"@typescript-eslint/parser": "^5.57.1", | ||
"@solana/eslint-config-solana": "^1.0.2", | ||
"@swc/jest": "^0.2.27", | ||
"@types/jest": "^29.5.3", | ||
"@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-plugin-react-hooks": "^4.6.0", | ||
"eslint": "^8.45.0", | ||
"eslint-plugin-jest": "^27.2.3", | ||
"eslint-plugin-sort-keys-fix": "^1.1.2", | ||
"jest": "^29.5.0", | ||
"jest-environment-jsdom": "^29.5.0", | ||
"jest-runner-eslint": "^2.0.0", | ||
"jest": "^29.6.1", | ||
"jest-environment-jsdom": "^29.6.2", | ||
"jest-runner-eslint": "^2.1.0", | ||
"jest-runner-prettier": "^1.0.0", | ||
"postcss": "^8.4.12", | ||
"prettier": "^2.8.8", | ||
"ts-node": "^10.9.1", | ||
"tsup": "6.7.0", | ||
"typescript": "^5.0.3", | ||
"prettier": "^3.0.1", | ||
"tsup": "7.2.0", | ||
"typescript": "^5.1.6", | ||
"version-from-git": "^1.1.1", | ||
"build-scripts": "0.0.0", | ||
"test-config": "0.0.0", | ||
"tsconfig": "0.0.0" | ||
"tsconfig": "0.0.0", | ||
"build-scripts": "0.0.0" | ||
}, | ||
@@ -83,5 +85,2 @@ "bundlewatch": { | ||
}, | ||
"dependencies": { | ||
"bs58": "^5.0.0" | ||
}, | ||
"scripts": { | ||
@@ -88,0 +87,0 @@ "compile:js": "tsup --config build-scripts/tsup.config.library.ts", |
@@ -21,33 +21,42 @@ [![npm][npm-image]][npm-url] | ||
### `Base58EncodedAddress` | ||
### `Ed25519Signature` | ||
This type represents a string that validates as a Solana address or public key. Functions that require well-formed addresses should specify their inputs in terms of this type. | ||
This type represents a 64-byte Ed25519 signature of some data with a private key. | ||
Whenever you need to validate an arbitrary string as a base58-encoded address, use the `assertIsBase58EncodedAddress()` function in this package. | ||
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 | ||
### `assertIsBase58EncodedAddress()` | ||
### `generateKeyPair()` | ||
Client applications primarily deal with addresses and public keys in the form of base58-encoded strings. Addresses and public keys returned from the RPC API conform to the type `Base58EncodedAddress`. You can use a value of that type wherever a base58-encoded address or key is expected. | ||
Generates an Ed25519 public/private key pair for use with other methods in this package that accept `CryptoKey` objects. | ||
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. | ||
```ts | ||
import { generateKeyPair } from '@solana/keys'; | ||
const { privateKey, publicKey } = await generateKeyPair(); | ||
``` | ||
### `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 { assertIsBase58EncodedAddress } from '@solana/web3.js`; | ||
import { signBytes } from '@solana/keys'; | ||
// Imagine a function that fetches an account's balance when a user submits a form. | ||
function handleSubmit() { | ||
// We know only that what the user typed conforms to the `string` type. | ||
const address: string = accountAddressInput.value; | ||
try { | ||
// If this type assertion function doesn't throw, then | ||
// Typescript will upcast `address` to `Base58EncodedAddress`. | ||
assertIsBase58EncodedAddress(address); | ||
// At this point, `address` is a `Base58EncodedAddress` that can be used with the RPC. | ||
const balanceInLamports = await rpc.getBalance(address).send(); | ||
} catch (e) { | ||
// `address` turned out not to be a base58-encoded address | ||
} | ||
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20
23
62
35519
282
1
+ Added@solana/assertions@2.0.0-experimental.0b7eadc(transitive)
- Removedbs58@^5.0.0
- Removedbase-x@4.0.0(transitive)
- Removedbs58@5.0.0(transitive)