{"_id":"@axvn-vn/keys","_rev":"3-ad49ff9d4c8b344a67382069277cd990","name":"@axvn-vn/keys","dist-tags":{"latest":"0.0.0"},"versions":{"0.0.0":{"name":"@axvn-vn/keys","version":"0.0.0","keywords":["blockchain","solana","web3"],"author":{"name":"Solana Labs Maintainers","email":"maintainers@solanalabs.com"},"license":"MIT","_id":"@axvn-vn/keys@0.0.0","maintainers":[{"name":"davidtran76","email":"Farm15ceo@gmail.com"}],"homepage":"https://www.solanakit.com/api#solanakeys","bugs":{"url":"https://github.com/anza-xyz/kit/issues"},"dist":{"shasum":"381f4c9b6ebf9aad662e8e7defe212bcd1f0b6d2","tarball":"https://registry.npmjs.org/@axvn-vn/keys/-/keys-0.0.0.tgz","fileCount":37,"integrity":"sha512-gXlVRyixE5YMWNyDHWJLrGBd9+72zgSZvQCopFoswt1wKc13LIOnB87nqmWMZ+21DNeE9fTKiMhiIE5X3gOXUA==","signatures":[{"sig":"MEQCICGN133PRNIWagWanVh5LdiHtIGTNwvDxBxR3/I5jAryAiB+HcSTQ1skciIPu3UG7XmM6pseN3dm0a0jmtoQ1OKa+Q==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":360499},"main":"./dist/index.node.cjs","type":"commonjs","types":"./dist/types/index.d.ts","module":"./dist/index.node.mjs","browser":{"./dist/index.node.cjs":"./dist/index.browser.cjs","./dist/index.node.mjs":"./dist/index.browser.mjs"},"engines":{"node":">=20.18.0"},"exports":{"node":{"import":"./dist/index.node.mjs","require":"./dist/index.node.cjs"},"types":"./dist/types/index.d.ts","browser":{"import":"./dist/index.browser.mjs","require":"./dist/index.browser.cjs"},"workerd":{"import":"./dist/index.node.mjs","require":"./dist/index.node.cjs"},"edge-light":{"import":"./dist/index.node.mjs","require":"./dist/index.node.cjs"},"react-native":"./dist/index.native.mjs"},"scripts":{"dev":"NODE_OPTIONS=\"--no-experimental-webstorage\" jest -c ../../node_modules/@solana/test-config/jest-dev.config.js --rootDir . --watch","benchmark":"./src/__benchmarks__/run.ts","style:fix":"pnpm eslint --fix src && pnpm prettier --log-level warn --ignore-unknown --write ./*","test:lint":"TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-lint.config.js --rootDir . --silent","compile:js":"tsup --config build-scripts/tsup.config.package.ts","compile:docs":"typedoc","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 && (([ -n \"${GITHUB_OUTPUT:-}\" ] && echo 'published=true' >> \"$GITHUB_OUTPUT\") || true) && (([ \"$PUBLISH_TAG\" != \"canary\" ] && ../build-scripts/maybe-tag-latest.ts --token \"$GITHUB_TOKEN\" $npm_package_name@$npm_package_version) || true))","test:prettier":"TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-prettier.config.js --rootDir . --silent","test:typecheck":"tsc --noEmit","test:unit:node":"NODE_OPTIONS=\"--no-experimental-webstorage\" TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-unit.config.node.js --rootDir . --silent","compile:typedefs":"tsc -p ./tsconfig.declarations.json","publish-packages":"pnpm prepublishOnly && pnpm publish-impl","test:unit:browser":"NODE_OPTIONS=\"--no-experimental-webstorage\" TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-unit.config.browser.js --rootDir . --silent","test:treeshakability:node":"agadoo dist/index.node.mjs","test:treeshakability:native":"agadoo dist/index.native.mjs","test:treeshakability:browser":"agadoo dist/index.browser.mjs"},"_npmUser":{"name":"davidtran76","email":"Farm15ceo@gmail.com"},"repository":{"url":"git+https://github.com/anza-xyz/kit.git","type":"git"},"_npmVersion":"11.17.0","description":"Helpers for generating and transforming key material","directories":{},"sideEffects":false,"_nodeVersion":"24.19.0","browserslist":["supports bigint and not dead","maintained node versions"],"dependencies":{"@axvn-vn/errors":"8.0.0","@axvn-vn/promises":"8.0.0","@axvn-vn/assertions":"8.0.0","@axvn-vn/codecs-core":"8.0.0","@axvn-vn/nominal-types":"8.0.0","@axvn-vn/codecs-strings":"8.0.0"},"react-native":"./dist/index.native.mjs","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"peerDependencies":{"typescript":">=5.4.0"},"peerDependenciesMeta":{"typescript":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/keys_0.0.0_1787355367927_0.8967911813981493","host":"s3://npm-registry-packages-npm-production"},"deprecated":"DEPRECATED: This package has been removed. Do not use."}},"time":{"created":"2026-08-21T23:36:07.670Z","modified":"2026-08-22T16:11:13.161Z","0.0.0":"2026-08-21T23:36:08.100Z"},"bugs":{"url":"https://github.com/anza-xyz/kit/issues"},"author":{"name":"Solana Labs Maintainers","email":"maintainers@solanalabs.com"},"license":"MIT","homepage":"https://www.solanakit.com/api#solanakeys","keywords":["blockchain","solana","web3"],"repository":{"url":"git+https://github.com/anza-xyz/kit.git","type":"git"},"description":"Helpers for generating and transforming key material","maintainers":[{"name":"davidtran76","email":"Farm15ceo@gmail.com"},{"name":"nhamhuan","email":"Nhamhuan@gmail.com"}],"readme":"[![npm][npm-image]][npm-url]\n[![npm-downloads][npm-downloads-image]][npm-url]\n<br />\n[![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]\n\n[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square\n[code-style-prettier-url]: https://github.com/prettier/prettier\n[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/keys?style=flat\n[npm-image]: https://img.shields.io/npm/v/@solana/keys?style=flat\n[npm-url]: https://www.npmjs.com/package/@solana/keys\n\n# @solana/keys\n\nThis package contains utilities for validating, generating, and manipulating addresses and key material. It can be used standalone, but it is also exported as part of Kit [`@solana/kit`](https://github.com/anza-xyz/kit/tree/main/packages/kit).\n\n## Types\n\n### `Signature`\n\nThis type represents a 64-byte Ed25519 signature as a base58-encoded string.\n\n### `SignatureBytes`\n\nThis type represents a 64-byte Ed25519 signature.\n\nWhenever 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.\n\n## Functions\n\n### `assertIsSignature()`\n\nFrom time to time you might acquire a string that you expect to be a base58-encoded signature (eg. of a transaction) from an untrusted network API or user input. To assert that such an arbitrary string is in fact an Ed25519 signature, use the `assertIsSignature` function.\n\n```ts\nimport { assertIsSignature } from '@solana/keys';\n\n// Imagine a function that asserts whether a user-supplied signature is valid or not.\nfunction handleSubmit() {\n    // We know only that what the user typed conforms to the `string` type.\n    const signature: string = signatureInput.value;\n    try {\n        // If this type assertion function doesn't throw, then\n        // Typescript will upcast `signature` to `Signature`.\n        assertIsSignature(signature);\n        // At this point, `signature` is a `Signature` that can be used with the RPC.\n        const {\n            value: [status],\n        } = await rpc.getSignatureStatuses([signature]).send();\n    } catch (e) {\n        // `signature` turned out not to be a base58-encoded signature\n    }\n}\n```\n\n### `generateKeyPair()`\n\nGenerates an Ed25519 public/private key pair for use with other methods in this package that accept `CryptoKey` objects.\n\n```ts\nimport { generateKeyPair } from '@solana/keys';\n\nconst { privateKey, publicKey } = await generateKeyPair();\n```\n\n### `grindKeyPair()`\n\nMines a vanity Ed25519 key pair whose base58-encoded public key satisfies the provided `matches` criterion. The matcher may be a `RegExp` or a predicate function that receives the candidate address as a string. Key pairs are generated in parallel batches until one matches, so the expected time to find a match grows exponentially with the length of the desired prefix.\n\n```ts\nimport { grindKeyPair } from '@solana/keys';\n\nconst keyPair = await grindKeyPair({ matches: /^anza/ });\n```\n\nWhen `matches` is a `RegExp`, its literal characters are validated against the base58 alphabet up front to catch common typos (e.g. `/^sol0/`) before any key is generated. The config also accepts an `extractable` flag (forwarded to `generateKeyPair`), a `concurrency` setting for the batch size (defaulting to `32`), and an `abortSignal` to cancel long-running grinds.\n\n### `grindKeyPairs()`\n\nMines multiple vanity Ed25519 key pairs whose base58-encoded public keys all satisfy the provided `matches` criterion. This is the batch variant of `grindKeyPair()` and accepts the same configuration plus an `amount` field.\n\n```ts\nimport { grindKeyPairs } from '@solana/keys';\n\nconst keyPairs = await grindKeyPairs({ matches: /^anza/, amount: 4 });\n```\n\n### `createKeyPairFromBytes()`\n\nGiven a 64-byte `Uint8Array` secret key, creates an Ed25519 public/private key pair for use with other methods in this package that accept `CryptoKey` objects.\n\n```ts\nimport fs from 'fs';\nimport { createKeyPairFromBytes } from '@solana/keys';\n\n// Get bytes from local keypair file.\nconst keypairFile = fs.readFileSync('~/.config/solana/id.json');\nconst keypairBytes = new Uint8Array(JSON.parse(keypairFile.toString()));\n\n// Create a CryptoKeyPair from the bytes.\nconst { privateKey, publicKey } = await createKeyPairFromBytes(keypairBytes);\n```\n\n### `writeKeyPair()`\n\nWrites an extractable `CryptoKeyPair` to disk as a JSON array of 64 bytes, matching the format produced by `solana-keygen`. The first 32 bytes are the raw Ed25519 seed (private key) and the last 32 bytes are the raw public key. Missing parent directories are created automatically and the file is written with mode `0600` (owner read/write only). This helper requires a writable filesystem and will throw in environments that don't provide one (such as browsers or React Native).\n\n```ts\nimport { generateKeyPair, writeKeyPair } from '@solana/keys';\n\n// Generate an extractable key pair so its bytes can be persisted.\nconst keyPair = await generateKeyPair(true);\nawait writeKeyPair(keyPair, './my-keypair.json');\n```\n\nBy default, `writeKeyPair()` refuses to overwrite an existing file and throws `EEXIST`. Callers can opt in by passing `{ unsafelyOverwriteExistingKeyPair: true }`, but doing so permanently destroys the previous key and, with it, access to any funds or onchain state controlled by that address.\n\n### `createKeyPairFromPrivateKeyBytes()`\n\nGiven a private key represented as a 32-bytes `Uint8Array`, creates an Ed25519 public/private key pair for use with other methods in this package that accept `CryptoKey` objects.\n\n```ts\nimport { createKeyPairFromPrivateKeyBytes } from '@solana/keys';\n\nconst { privateKey, publicKey } = await createKeyPairFromPrivateKeyBytes(new Uint8Array([...]));\n```\n\nThis can be useful when you have a private key but not the corresponding public key or when you need to derive key pairs from seeds. For instance, the following code snippet derives a key pair from the hash of a message.\n\n```ts\nimport { getUtf8Encoder } from '@solana/codecs-strings';\nimport { createKeyPairFromPrivateKeyBytes } from '@solana/keys';\n\nconst message = getUtf8Encoder().encode('Hello, World!');\nconst seed = new Uint8Array(await crypto.subtle.digest('SHA-256', message));\n\nconst derivedKeypair = await createKeyPairFromPrivateKeyBytes(seed);\n```\n\n### `createPrivateKeyFromBytes()`\n\nGiven a private key represented as a 32-byte `Uint8Array`, creates an Ed25519 private key for use with other methods in this package that accept `CryptoKey` objects.\n\n```ts\nimport { createPrivateKeyFromBytes } from '@solana/keys';\n\nconst privateKey = await createPrivateKeyFromBytes(new Uint8Array([...]));\nconst extractablePrivateKey = await createPrivateKeyFromBytes(new Uint8Array([...]), true);\n```\n\n### `getPublicKeyFromPrivateKey()`\n\nGiven an extractable `CryptoKey` private key, gets the corresponding public key as a `CryptoKey`.\n\n```ts\nimport { createPrivateKeyFromBytes, getPublicKeyFromPrivateKey } from '@solana/keys';\n\nconst privateKey = await createPrivateKeyFromBytes(new Uint8Array([...]), true);\n\nconst publicKey = await getPublicKeyFromPrivateKey(privateKey);\nconst extractablePublicKey = await getPublicKeyFromPrivateKey(privateKey, true);\n```\n\n### `isSignature()`\n\nThis is a type guard that accepts a string as input. It will both return `true` if the string conforms to the `Signature` type and will refine the type for use in your program.\n\n```ts\nimport { isSignature } from '@solana/keys';\n\nif (isSignature(signature)) {\n    // At this point, `signature` has been refined to a\n    // `Signature` that can be used with the RPC.\n    const {\n        value: [status],\n    } = await rpc.getSignatureStatuses([signature]).send();\n    setSignatureStatus(status);\n} else {\n    setError(`${signature} is not a transaction signature`);\n}\n```\n\n### `signBytes()`\n\nGiven a private `CryptoKey` and a `Uint8Array` of bytes, this method will return the 64-byte Ed25519 signature of that data as a `Uint8Array`.\n\n```ts\nimport { signBytes } from '@solana/keys';\n\nconst data = new Uint8Array([1, 2, 3]);\nconst signature = await signBytes(privateKey, data);\n```\n\n### `signature()`\n\nThis helper combines _asserting_ that a string is an Ed25519 signature with _coercing_ it to the `Signature` type. It's best used with untrusted input.\n\n```ts\nimport { signature } from '@solana/keys';\n\nconst signature = signature(userSuppliedSignature);\nconst {\n    value: [status],\n} = await rpc.getSignatureStatuses([signature]).send();\n```\n\n### `verifySignature()`\n\nGiven a public `CryptoKey`, some `SignatureBytes`, and a `Uint8Array` of data, this method will return `true` if the signature was produced by signing the data using the private key associated with the public key, and `false` otherwise.\n\n```ts\nimport { verifySignature } from '@solana/keys';\n\nconst data = new Uint8Array([1, 2, 3]);\nif (!(await verifySignature(publicKey, signature, data))) {\n    throw new Error('The data were *not* signed by the private key associated with `publicKey`');\n}\n```\n","readmeFilename":"README.md"}