{"_id":"@atlaschain/keys","name":"@atlaschain/keys","dist-tags":{"latest":"3.0.0"},"versions":{"3.0.0":{"name":"@atlaschain/keys","version":"3.0.0","description":"Helpers for generating and transforming key material","exports":{"edge-light":{"import":"./dist/index.node.mjs","require":"./dist/index.node.cjs"},"workerd":{"import":"./dist/index.node.mjs","require":"./dist/index.node.cjs"},"browser":{"import":"./dist/index.browser.mjs","require":"./dist/index.browser.cjs"},"node":{"import":"./dist/index.node.mjs","require":"./dist/index.node.cjs"},"react-native":"./dist/index.native.mjs","types":"./dist/types/index.d.ts"},"browser":{"./dist/index.node.cjs":"./dist/index.browser.cjs","./dist/index.node.mjs":"./dist/index.browser.mjs"},"main":"./dist/index.node.cjs","module":"./dist/index.node.mjs","react-native":"./dist/index.native.mjs","types":"./dist/types/index.d.ts","type":"commonjs","sideEffects":false,"keywords":["blockchain","atlas","web3"],"scripts":{"benchmark":"./src/__benchmarks__/run.ts","compile:docs":"typedoc","compile:js":"tsup --config build-scripts/tsup.config.package.ts","compile:typedefs":"tsc -p ./tsconfig.declarations.json","dev":"jest -c ../../node_modules/@atlas/test-config/jest-dev.config.ts --rootDir . --watch","prepublishOnly":"pnpm pkg delete devDependencies","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 $npm_package_name@$npm_package_version) || true))","publish-packages":"pnpm prepublishOnly && pnpm publish-impl","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/@atlas/test-config/jest-lint.config.ts --rootDir . --silent","test:prettier":"TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@atlas/test-config/jest-prettier.config.ts --rootDir . --silent","test:treeshakability:browser":"agadoo dist/index.browser.mjs","test:treeshakability:native":"agadoo dist/index.native.mjs","test:treeshakability:node":"agadoo dist/index.node.mjs","test:typecheck":"tsc --noEmit","test:unit:browser":"TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@atlas/test-config/jest-unit.config.browser.ts --rootDir . --silent","test:unit:node":"TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@atlas/test-config/jest-unit.config.node.ts --rootDir . --silent"},"author":{"name":"Atlas Chain Foundation"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/anza-xyz/kit.git"},"bugs":{"url":"https://github.com/anza-xyz/kit/issues"},"browserslist":["supports bigint and not dead","maintained node versions"],"dependencies":{"@atlaschain/assertions":"workspace:*","@atlaschain/codecs-core":"workspace:*","@atlaschain/codecs-strings":"workspace:*","@atlaschain/errors":"workspace:*","@atlaschain/nominal-types":"workspace:*"},"peerDependencies":{"typescript":">=5.3.3"},"engines":{"node":">=20.18.0"},"_id":"@atlaschain/keys@3.0.0","homepage":"https://github.com/anza-xyz/kit#readme","_nodeVersion":"22.12.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-xq2oeGgE2FKQOipSYNytKfPp2P8PXaXDCWgNPh+luAE9Wy2SvAzBoofy/eSwuFXrf3VbSP3pQ/cr1Rf34feEdg==","shasum":"e7ba790c02ba8032017b6528586e40351b9cc4d5","tarball":"https://registry.npmjs.org/@atlaschain/keys/-/keys-3.0.0.tgz","fileCount":5,"unpackedSize":19647,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDeUm3rXTNTS4Ura6BAAPRW3G62RQJ9dyfaeWKcTrGgVwIgCvci0/pDJ4ak8TNtg/jdgJBwkqYnEPD4b91SZsMmtOE="}]},"_npmUser":{"name":"atlaschain","email":"jq@atlaschain.org"},"directories":{},"maintainers":[{"name":"atlaschain","email":"jq@atlaschain.org"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/keys_3.0.0_1756885190551_0.07892085816132965"},"_hasShrinkwrap":false}},"time":{"created":"2025-09-03T07:39:50.447Z","3.0.0":"2025-09-03T07:39:50.715Z","modified":"2025-09-03T07:39:50.984Z"},"maintainers":[{"name":"atlaschain","email":"jq@atlaschain.org"}],"description":"Helpers for generating and transforming key material","homepage":"https://github.com/anza-xyz/kit#readme","keywords":["blockchain","atlas","web3"],"repository":{"type":"git","url":"git+https://github.com/anza-xyz/kit.git"},"author":{"name":"Atlas Chain Foundation"},"bugs":{"url":"https://github.com/anza-xyz/kit/issues"},"license":"MIT","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/@atlas/keys?style=flat\n[npm-image]: https://img.shields.io/npm/v/@atlas/keys?style=flat\n[npm-url]: https://www.npmjs.com/package/@atlas/keys\n\n# @atlas/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 [`@atlas/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 '@atlas/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 '@atlas/keys';\n\nconst { privateKey, publicKey } = await generateKeyPair();\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 '@atlas/keys';\n\n// Get bytes from local keypair file.\nconst keypairFile = fs.readFileSync('~/.config/atlas/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### `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 '@atlas/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 '@atlas/codecs-strings';\nimport { createKeyPairFromPrivateKeyBytes } from '@atlas/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 '@atlas/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 '@atlas/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 '@atlas/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 '@atlas/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 '@atlas/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 '@atlas/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","_rev":"1-1d486db808e72fb03beb619fe1e4d411"}