{"_id":"@1tokenfe/cardano-coin-selection-asmjs","name":"@1tokenfe/cardano-coin-selection-asmjs","dist-tags":{"latest":"1.1.5"},"versions":{"1.1.5":{"name":"@1tokenfe/cardano-coin-selection-asmjs","version":"1.1.5","description":"Minimal implementation of Cardano coin selection algorithms (see [CIP-2](https://cips.cardano.org/cips/cip2/)) developed solely for OneTokenHQ. Under the hood it leverages Cardano Serialization Lib via WASM module.","keywords":["coin selection"],"license":"MIT","author":{"name":"OneTokenHQ"},"homepage":"https://github.com/OneTokenHQ/coin-selection","repository":{"type":"git","url":"git+https://github.com/OneTokenHQ/coin-selection.git"},"publishConfig":{"access":"public"},"main":"lib/cjs/index.js","module":"lib/esm/index.js","scripts":{"build":"yarn clean && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json","clean":"rimraf lib","lint":"eslint ./src/**/*.ts","prepublishOnly":"yarn build","type-check":"yarn tsc -p tsconfig.types.json","test":"yarn run-s 'test:*'","test:unit":"jest -c ./jest.config.js","test:badges":"make-coverage-badge --output-path ./docs/badge-coverage.svg"},"devDependencies":{"@emurgo/cardano-serialization-lib-nodejs":"13.2.0","@eslint/js":"^9.11.1","@swc-node/jest":"^1.8.12","@swc/core":"1.7.26","@swc/helpers":"^0.5.13","@types/jest":"^29.5.13","@types/node":"^16.3.2","@typescript-eslint/eslint-plugin":"^8.8.0","@typescript-eslint/parser":"8.8.0","bignumber.js":"^9.0.1","eslint":"^9.11.1","eslint-config-prettier":"^9.1.0","eslint-plugin-import":"^2.30.0","eslint-plugin-prettier":"^5.2.1","jest":"^29.7.0","make-coverage-badge":"^1.2.0","npm-run-all":"^4.1.5","prettier":"3.3.3","rimraf":"^6.0.1","typescript":"^5.6.2","typescript-eslint":"^8.8.0"},"dependencies":{"@emurgo/cardano-message-signing-asmjs":"^1.0.1","@emurgo/cardano-serialization-lib-asmjs":"13.2.0"},"peerDependencies":{"bignumber.js":"^9.0.1"},"packageManager":"yarn@4.5.0","_id":"@1tokenfe/cardano-coin-selection-asmjs@1.1.5","gitHead":"fff2ff3ee95128881a5cd78ee594d6fbc06d40eb","types":"./lib/cjs/index.d.ts","bugs":{"url":"https://github.com/OneTokenHQ/coin-selection/issues"},"_nodeVersion":"20.18.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-evrirHwm2GrHbzrwAM6hZJFKu1VJg7xg+UZdXHtFXtS3Z4B4Fx0VDBEsgctUVrflkElVgTCp8usYYXT2Yfmk6g==","shasum":"a094f8cb03c673b2cb6fa760f8868380a18142a4","tarball":"https://registry.npmjs.org/@1tokenfe/cardano-coin-selection-asmjs/-/cardano-coin-selection-asmjs-1.1.5.tgz","fileCount":82,"unpackedSize":280662,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCrUISa6OwfoBwBLOqY9L55qNEe9L3zrK0SZxhFjFodLwIgRTQVwX+k8e/wJb4jPCd2dHCjIZJ3+kFQngFHqivqQnU="}]},"_npmUser":{"name":"dihuase0411","email":"dihuase0411@gmail.com"},"directories":{},"maintainers":[{"name":"vici1573","email":"vici1573@outlook.com"},{"name":"onetokenwallet","email":"yf860412@gmail.com"},{"name":"dihuase0411","email":"dihuase0411@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/cardano-coin-selection-asmjs_1.1.5_1763430806778_0.3020388957515161"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-18T01:53:26.678Z","1.1.5":"2025-11-18T01:53:26.982Z","modified":"2025-11-18T01:53:27.324Z"},"maintainers":[{"name":"vici1573","email":"vici1573@outlook.com"},{"name":"onetokenwallet","email":"yf860412@gmail.com"},{"name":"dihuase0411","email":"dihuase0411@gmail.com"}],"description":"Minimal implementation of Cardano coin selection algorithms (see [CIP-2](https://cips.cardano.org/cips/cip2/)) developed solely for OneTokenHQ. Under the hood it leverages Cardano Serialization Lib via WASM module.","homepage":"https://github.com/OneTokenHQ/coin-selection","keywords":["coin selection"],"repository":{"type":"git","url":"git+https://github.com/OneTokenHQ/coin-selection.git"},"author":{"name":"OneTokenHQ"},"bugs":{"url":"https://github.com/OneTokenHQ/coin-selection/issues"},"license":"MIT","readme":"# coin-selection\n\nMinimal implementation of Cardano coin selection algorithms (see [CIP-2](https://cips.cardano.org/cips/cip2/)) developed solely for OneTokenHQ.\nUnder the hood it leverages Cardano Serialization Lib via WASM module.\n\n## Features\n\n- Final tx plan: Compose transaction plan for given inputs (shelley utxos only), certificates (support for stake (de)registration and delegation), withdrawals,...\n- Draft tx plan: Return basic information about potential transaction (such as a size and fee) even for incomplete inputs (without an recipient address or an amount)\n- Set max: Calculate the max amount of an asset that is possible to include in a transaction output\n\n## Usage\n\n```typescript\nconst txPlan = coinSelection(\n\ttxParams: {\n        utxos: Utxo[];\n        outputs: UserOutput[];\n        changeAddress: string;\n        certificates: Certificate[];\n        withdrawals: Withdrawal[];\n        accountPubKey: string;\n        ttl?: number;\n    },\n\toptions: {\n        feeParams?: { a: string };\n        debug?: boolean;\n        forceLargestFirstSelection?: boolean;\n\t}\n);\n```\n\n### `coinSelection(txParams, options)`\n\n#### `txParams`\n\n- `utxos`: Array of account's utxo\n- `outputs`: Requested outputs provided by an user\n- `changeAddress`: An address where the change will be sent\n- `certificates`: Stake registration and/or delegation certificates (stake pool registration is not supported)\n- `withdrawals`: Withdrawal requests\n- `accountPubKey`: Account public key\n- `ttl`: Time-to-live for the transaction\n\n#### `Options`\n\n- `forceLargestFirstSelection`: Always use largest-first algorithm\n- `debug`: print debug information about coin-selection (selected utxos, outputs including change output,...)\n\n## Example\n\n### Final tx plan\n\n```typescript\n\nexport const utxo1 = {\n  address:\n    'addr1q860vxljhadqxnrrsr2j6yxnwpdkyquq74lmghx502aj0r28d2kd47hsre5v9urjyu8s0ryk38dxzw0t5jesncw4v90sp0878u',\n  txHash: '3c388acb799a37a4f1cc99bec7626637b0b80626b9ef7c7a687282cab701178d',\n  outputIndex: 0,\n  amount: [\n    {\n      quantity: '5000000',\n      unit: 'lovelace',\n    },\n  ],\n};\n\nexport const utxo2 = {\n  address:\n    'addr1q860vxljhadqxnrrsr2j6yxnwpdkyquq74lmghx502aj0r28d2kd47hsre5v9urjyu8s0ryk38dxzw0t5jesncw4v90sp0878u',\n  txHash: '9e63fddf20cb7b5472e2c9a1bb4bbe3112b8f2b22e45bc441206bcddde5c58a0',\n  outputIndex: 1,\n  amount: [\n    {\n      quantity: '5000000',\n      unit: 'lovelace',\n    },\n    {\n      quantity: '1000',\n      unit: '02477d7c23b4c2834b0be8ca8578dde47af0cc82a964688f6fc95a7a47524943',\n    },\n  ],\n};\n\nconst txPlan = coinSelection(\n\ttxParams: {\n        utxos: Utxo[];\n        outputs: [\n        {\n            address:\n            'addr1qya0nkzrf04gmcpu66vdt7sudwptnyg5df6475y7jhtt2wc44vzmgrfy6wwf69xlaszdslksw8evveyykw4c82eavq7sx29tlc',\n            amount: '1000000',\n            assets: [],\n            setMax: false,\n        },\n        {\n            address:\n            'addr1qya0nkzrf04gmcpu66vdt7sudwptnyg5df6475y7jhtt2wc44vzmgrfy6wwf69xlaszdslksw8evveyykw4c82eavq7sx29tlc',\n            amount: undefined,\n            assets: [],\n            setMax: true,\n        },\n        ],\n        changeAddress: `addr1q8u2f05rprqjhygz22m06mhy4xrnqvqqpyuzhmxqfxnwvxz8d2kd47hsre5v9urjyu8s0ryk38dxzw0t5jesncw4v90s22tk0f`,\n        certificates: [],\n        withdrawals: [],\n        accountPubKey:\n        'ec8fdf616242f430855ad7477acda53395eb30c295f5a7ef038712578877375b5a2f00353c9c5cc88c7ff18e71dc08724d90fc238213b789c0b02438e336be07',\n    },\n);\n\n// txPlan\n// {\n//   max: '7480901',\n//   totalSpent: '8655202',\n//   fee: '174301',\n//   inputs: [utxo1, utxo2],\n//   outputs: [\n//     {\n//       address:\n//         'addr1qya0nkzrf04gmcpu66vdt7sudwptnyg5df6475y7jhtt2wc44vzmgrfy6wwf69xlaszdslksw8evveyykw4c82eavq7sx29tlc',\n//       amount: '1000000',\n//       assets: [],\n//       setMax: false,\n//     },\n//     {\n//       address:\n//         'addr1qya0nkzrf04gmcpu66vdt7sudwptnyg5df6475y7jhtt2wc44vzmgrfy6wwf69xlaszdslksw8evveyykw4c82eavq7sx29tlc',\n//       amount: '7480901',\n//       assets: [],\n//       setMax: true,\n//     },\n//     {\n//       isChange: true,\n//       address: changeAddress,\n//       amount: '1344798',\n//       assets: [\n//         {\n//           quantity: '1000',\n//           unit: '02477d7c23b4c2834b0be8ca8578dde47af0cc82a964688f6fc95a7a47524943',\n//         },\n//       ],\n//     },\n//   ],\n// },\n;\n```\n\n### Draft tx plan\n\n```typescript\n\nconst txPlan = coinSelection(\n\t{\n        utxos: [utxo1];\n        outputs: [\n            {\n                address: undefined, // address not filled\n                amount: '2000000',\n                assets: [],\n                setMax: false,\n            },\n        ],\n        changeAddress: `addr1q8u2f05rprqjhygz22m06mhy4xrnqvqqpyuzhmxqfxnwvxz8d2kd47hsre5v9urjyu8s0ryk38dxzw0t5jesncw4v90s22tk0f`,\n        certificates: [],\n        withdrawals: [],\n        accountPubKey:\n        'ec8fdf616242f430855ad7477acda53395eb30c295f5a7ef038712578877375b5a2f00353c9c5cc88c7ff18e71dc08724d90fc238213b789c0b02438e336be07',\n    },\n);\n\n// txPlan:\n// {\n//     totalSpent: '2168053',\n//     fee: '168053',\n// },\n\n```\n\n## Notes\n\n- If there are certificates present or the transaction includes an output with `setMax: true` then largest-first algorithm will be used instead of random-improve.\n","readmeFilename":"README.md","_rev":"1-1f7778b3254766f3feb4fb1e24ca4021"}