{"bugs":{"url":"https://github.com/dfinity/ic-js"},"dist":{"shasum":"dd3b0d5fed11081443ad3ef7ba7c38c75f287119","tarball":"https://registry.npmjs.org/@dfinity/ledger/-/ledger-0.0.13-next-2023-08-20.tgz","fileCount":42,"integrity":"sha512-t5BSscCroAKEe8xfGRd8Z1+nRky4/I/VtRC65eFYTYl1FqcFLkcheSX/NJPOtAFPRdlBB891VzyNXJBcc5jFZQ==","signatures":[{"sig":"MEUCIAZJDp4lmTNwZIi5e4mICknOs84cMCuKlD/VeFSKlklPAiEAwiudW0zcNej1z1s5YN46a/ohdn872dKXQJ7KGlewU8Y=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@dfinity%2fledger@0.0.13-next-2023-08-20","provenance":{"predicateType":"https://slsa.dev/provenance/v0.2"}},"unpackedSize":191901},"main":"dist/cjs/index.cjs.js","name":"@dfinity/ledger","types":"dist/types/index.d.ts","module":"dist/esm/index.js","readme":"# ledger-js\n\nA library for interfacing with [ICRC ledger](https://github.com/dfinity/ic/tree/master/rs/rosetta-api/icrc1) on the Internet Computer.\n\n[![npm version](https://img.shields.io/npm/v/@dfinity/ledger.svg?logo=npm)](https://www.npmjs.com/package/@dfinity/ledger) [![GitHub license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n## Table of contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Features](#features)\n- [Resources](#resources)\n\n## Installation\n\nYou can use `ledger-js` by installing it in your project.\n\n```bash\nnpm i @dfinity/ledger\n```\n\nThe bundle needs peer dependencies, be sure that following resources are available in your project as well.\n\n```bash\nnpm i @dfinity/agent @dfinity/candid @dfinity/principal @dfinity/utils\n```\n\n## Usage\n\nThe features are available through the class `LedgerCanister`. It has to be instantiated with a canister ID.\n\ne.g. fetching a token metadata.\n\n```ts\nimport { IcrcLedgerCanister } from \"@dfinity/ledger\";\nimport { createAgent } from \"@dfinity/utils\";\n\nconst agent = await createAgent({\n  identity,\n  host: HOST,\n});\n\nconst { metadata } = LedgerCanister.create({\n  agent,\n  canisterId: MY_LEDGER_CANISTER_ID,\n});\n\nconst data = await metadata();\n```\n\n## Features\n\n`ledger-js` implements following features:\n\n<!-- TSDOC_START -->\n\n### :toolbox: Functions\n\n- [encodeIcrcAccount](#gear-encodeicrcaccount)\n- [decodeIcrcAccount](#gear-decodeicrcaccount)\n- [decodePayment](#gear-decodepayment)\n\n#### :gear: encodeIcrcAccount\n\nEncodes an Icrc-1 account compatible into a string.\nFormatting Reference: https://github.com/dfinity/ICRC-1/blob/main/standards/ICRC-1/TextualEncoding.md\n\n| Function            | Type                                              |\n| ------------------- | ------------------------------------------------- |\n| `encodeIcrcAccount` | `({ owner, subaccount, }: IcrcAccount) => string` |\n\nParameters:\n\n- `account`: : Principal, subaccount?: Uint8Array }\n\n[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ledger/src/utils/ledger.utils.ts#L21)\n\n#### :gear: decodeIcrcAccount\n\nDecodes a string into an Icrc-1 compatible account.\nFormatting Reference: https://github.com/dfinity/ICRC-1/blob/main/standards/ICRC-1/TextualEncoding.md\n\n| Function            | Type                                     |\n| ------------------- | ---------------------------------------- |\n| `decodeIcrcAccount` | `(accountString: string) => IcrcAccount` |\n\nParameters:\n\n- `accountString`: string\n\n[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ledger/src/utils/ledger.utils.ts#L59)\n\n#### :gear: decodePayment\n\n👀 This feature is currently in draft. You can find more information about it at https://github.com/dfinity/ICRC/issues/22.\n\nA naive implementation of a payment parser. Given a code, the function attempts to extract a token name, account identifier (textual representation), and an optional amount.\n\nIf the code doesn't match the expected pattern, `undefined` is returned for simplicity.\nSimilarly, if an optional amount is provided but it's not a valid number, the parser will not throw an exception and returns `undefined`.\n\nPlease note that this function doesn't perform any validity checks on the extracted information.\nIt does not verify if the token is known or if the identifier is a valid address.\n\n```\nurn            = token \":\" address [ \"?\" params]\ntoken         = [ ckbtc / icp / chat / bitcoin / ethereum ... ]\naddress       = STRING\nparams        = param [ \"&\" params ]\nparam         = [ amountparam ]\namountparam   = \"amount=\" *digit [ \".\" *digit ]\n```\n\n| Function        | Type                                                                        |\n| --------------- | --------------------------------------------------------------------------- |\n| `decodePayment` | `(code: string) => { token: string; identifier: string; amount?: number; }` |\n\nParameters:\n\n- `code`: string\n\n[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ledger/src/utils/payment.utils.ts#L26)\n\n### :factory: IcrcLedgerCanister\n\n[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ledger/src/ledger.canister.ts#L16)\n\n#### Methods\n\n- [create](#gear-create)\n- [metadata](#gear-metadata)\n- [transactionFee](#gear-transactionfee)\n- [balance](#gear-balance)\n- [transfer](#gear-transfer)\n- [totalTokensSupply](#gear-totaltokenssupply)\n\n##### :gear: create\n\n| Method   | Type                                                                   |\n| -------- | ---------------------------------------------------------------------- |\n| `create` | `(options: IcrcLedgerCanisterOptions<_SERVICE>) => IcrcLedgerCanister` |\n\n[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ledger/src/ledger.canister.ts#L17)\n\n##### :gear: metadata\n\nThe token metadata (name, symbol, etc.).\n\n| Method     | Type                                                          |\n| ---------- | ------------------------------------------------------------- |\n| `metadata` | `(params: QueryParams) => Promise<IcrcTokenMetadataResponse>` |\n\n[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ledger/src/ledger.canister.ts#L31)\n\n##### :gear: transactionFee\n\nThe ledger transaction fees.\n\n| Method           | Type                                       |\n| ---------------- | ------------------------------------------ |\n| `transactionFee` | `(params: QueryParams) => Promise<bigint>` |\n\n[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ledger/src/ledger.canister.ts#L39)\n\n##### :gear: balance\n\nReturns the balance for a given account provided as owner and with optional subaccount.\n\n| Method    | Type                                         |\n| --------- | -------------------------------------------- |\n| `balance` | `(params: BalanceParams) => Promise<bigint>` |\n\nParameters:\n\n- `params`: The parameters to get the balance of an account.\n\n[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ledger/src/ledger.canister.ts#L48)\n\n##### :gear: transfer\n\nTransfers tokens from the sender to the given account.\n\n| Method     | Type                                          |\n| ---------- | --------------------------------------------- |\n| `transfer` | `(params: TransferParams) => Promise<bigint>` |\n\nParameters:\n\n- `params`: The parameters to transfer tokens.\n\n[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ledger/src/ledger.canister.ts#L61)\n\n##### :gear: totalTokensSupply\n\nReturns the total supply of tokens.\n\n| Method              | Type                                       |\n| ------------------- | ------------------------------------------ |\n| `totalTokensSupply` | `(params: QueryParams) => Promise<bigint>` |\n\n[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ledger/src/ledger.canister.ts#L77)\n\n### :factory: IcrcIndexCanister\n\n[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ledger/src/index.canister.ts#L13)\n\n#### Methods\n\n- [create](#gear-create)\n- [getTransactions](#gear-gettransactions)\n\n##### :gear: create\n\n| Method   | Type                                                                  |\n| -------- | --------------------------------------------------------------------- |\n| `create` | `(options: IcrcLedgerCanisterOptions<_SERVICE>) => IcrcIndexCanister` |\n\n[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ledger/src/index.canister.ts#L14)\n\n##### :gear: getTransactions\n\nGet the transactions of an account\n\nAlways certified.\n`get_account_transactions` needs to be called with an update\nbecause the index canisters makes a call to the ledger canister to get the transaction data.\nIndex Canister only holds the transactions ids in state, not the whole transaction data.\n\n| Method            | Type                                                                 |\n| ----------------- | -------------------------------------------------------------------- |\n| `getTransactions` | `(params: GetAccountTransactionsParams) => Promise<GetTransactions>` |\n\n[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ledger/src/index.canister.ts#L33)\n\n<!-- TSDOC_END -->\n\n## Resources\n\n- [Ledger & Tokenization Working Group Standards](https://github.com/dfinity/ICRC-1/)\n- [ICRC-1 Ledger](https://github.com/dfinity/ic/tree/master/rs/rosetta-api/icrc1)\n","gitHead":"e5679f7f7773ed7e389ee8488c765e0ad7490fdc","license":"Apache-2.0","scripts":{"test":"jest","build":"npm run rmdir && mkdir -p dist && cp -R candid dist && node esbuild.mjs && npm run ts-declaration","rmdir":"node ../../scripts/rmdir.mjs","prepack":"npm run build","ts-declaration":"tsc --emitDeclarationOnly --outDir dist/types"},"_npmUser":{"name":"bitdivine","email":"bitdivine69@gmail.com"},"homepage":"https://github.com/dfinity/ic-js#readme","keywords":["internet computer","internet-computer","ic","dfinity","Ledger","ICRC-1 ledger","token"],"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.","repository":{"url":"git+https://github.com/dfinity/ic-js.git","type":"git","directory":"packages/ledger"},"_npmVersion":"9.6.7","description":"A library for interfacing with ICRC ledgers on the Internet Computer.","directories":{},"maintainers":[{"name":"dfx-json","email":"jason.ibrahim@dfinity.org"},{"name":"dfn_wndlng","email":"jan.wendling@dfinity.org"},{"name":"nathan.mcgrath.dfinity","email":"nathan.mcgrath@dfinity.org"},{"name":"frederikrothenberger","email":"frederik.rothenberger@dfinity.org"},{"name":"bitdivine","email":"bitdivine69@gmail.com"},{"name":"ielashi","email":"diner-rodding@ic8.org"},{"name":"liadrit","email":"lia.bajraliu@dfinity.org"},{"name":"dayyildiz","email":"dominik.ayyildiz@dfinity.org"},{"name":"eric-swanson-dfinity","email":"eric.swanson@dfinity.org"},{"name":"krpeacock","email":"kylpeacock@gmail.com"},{"name":"terrorjack","email":"astrohavoc@gmail.com"},{"name":"npm-dfinity-org","email":"npm@dfinity.org"}],"_nodeVersion":"18.17.0","_hasShrinkwrap":false,"readmeFilename":"README.md","peerDependencies":{"@dfinity/agent":"*","@dfinity/utils":"*","@dfinity/candid":"*","@dfinity/principal":"*"},"_npmOperationalInternal":{"tmp":"tmp/ledger_0.0.13-next-2023-08-20_1692490285239_0.8267899297702983","host":"s3://npm-registry-packages"},"_id":"@dfinity/ledger@0.0.13-next-2023-08-20","version":"0.0.13-next-2023-08-20"}