@kasplex/kiwi
Advanced tools
Sorry, the diff of this file is too big to display
+5
-5
| export * as Wasm from './wasm'; | ||
| export { Kiwi } from './kiwi'; | ||
| export { Rpc } from './rpc/client'; | ||
| export { KRC20 } from './krc20'; | ||
| export { Utils, Enum } from './utils'; | ||
| export * from "./address/mnemonic"; | ||
| export * from "./address/wallet"; | ||
| export * from "./rpc/client"; | ||
| export * from "./api/kasplexApi"; | ||
@@ -9,7 +12,4 @@ export * from "./api/kaspaApi"; | ||
| export * from "./script/script"; | ||
| export * from "./krc20"; | ||
| export * from './kiwi'; | ||
| export * from './init'; | ||
| export * from "./utils/index"; | ||
| export * as Modules from "./types/index"; | ||
| export * as Modules from "./types"; | ||
| export * as Tx from "./tx"; |
+51
-12
| import { Wasm } from "./index"; | ||
| import { Krc20Data } from './types/interface'; | ||
| import { Krc20Data, EncodablePayload } from './types/interface'; | ||
| declare class KRC20 { | ||
| static executeCommit(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint): Promise<string | undefined>; | ||
| static executeReveal(privateKey: Wasm.PrivateKey, data: Krc20Data, commitTxid: string): Promise<string | undefined>; | ||
| static executeReveal(privateKey: Wasm.PrivateKey, data: Krc20Data, commitTxid: string, payload?: EncodablePayload): Promise<string | undefined>; | ||
| private static isHexString; | ||
| private static normalizePayload; | ||
| /** | ||
@@ -14,4 +16,41 @@ * Executes a KRC20 operation. | ||
| */ | ||
| static executeOperation(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: Wasm.HexString | Uint8Array): Promise<string | undefined>; | ||
| static executeOperation(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: EncodablePayload): Promise<string | undefined>; | ||
| /** | ||
| * Executes a direct KRC20 payload transaction. | ||
| * | ||
| * This is different from executeOperation/mint/transfer/deploy: | ||
| * - executeOperation uses the original P2SH commit-reveal flow. | ||
| * - executePayloadOperation creates a normal Kaspa transaction with the KRC20 JSON in tx payload. | ||
| * | ||
| * If payload is not provided, the KRC20 data itself will be used as the transaction payload. | ||
| * This keeps the payload in the standard KRC20 JSON shape: | ||
| * { p: "krc-20", op: "mint" | "transfer" | "deploy", ... } | ||
| * | ||
| * If you pass a custom payload, that custom payload will be written instead. | ||
| * Be careful: custom wrapped payload may not be recognized by a standard KRC20 indexer. | ||
| */ | ||
| static executePayloadOperation(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: EncodablePayload): Promise<string | undefined>; | ||
| /** | ||
| * Mints KRC20 by direct transaction payload. | ||
| * | ||
| * Default payload: data itself. | ||
| * Optional custom payload: pass payload as the 4th arg. | ||
| */ | ||
| static mintByPayload(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: EncodablePayload): Promise<string | undefined>; | ||
| /** | ||
| * Transfers KRC20 by direct transaction payload. | ||
| * | ||
| * Required fields: to, amt. | ||
| * Default payload: data itself. | ||
| * Optional custom payload: pass payload as the 4th arg. | ||
| */ | ||
| static transferByPayload(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: EncodablePayload): Promise<string | undefined>; | ||
| /** | ||
| * Deploys KRC20 by direct transaction payload. | ||
| * | ||
| * Default payload: data itself. | ||
| * Optional custom payload: pass payload as the 4th arg. | ||
| */ | ||
| static deployByPayload(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: EncodablePayload): Promise<string | undefined>; | ||
| /** | ||
| * Gets the script public key from a transaction output. | ||
@@ -30,3 +69,3 @@ * .param txOutput - The transaction output. | ||
| */ | ||
| static mint(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: Wasm.HexString | Uint8Array): Promise<string | undefined>; | ||
| static mint(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: EncodablePayload): Promise<string | undefined>; | ||
| /** | ||
@@ -39,3 +78,3 @@ * Deploys a new KRC20 token contract. | ||
| */ | ||
| static deploy(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: Wasm.HexString | Uint8Array): Promise<string | undefined>; | ||
| static deploy(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: EncodablePayload): Promise<string | undefined>; | ||
| /** | ||
@@ -48,3 +87,3 @@ * Transfers KRC20 tokens to another address. | ||
| */ | ||
| static transfer(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: Wasm.HexString | Uint8Array): Promise<string | undefined>; | ||
| static transfer(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: EncodablePayload): Promise<string | undefined>; | ||
| /** | ||
@@ -57,3 +96,3 @@ * Lists KRC20 token details. | ||
| */ | ||
| static list(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint): Promise<string | undefined>; | ||
| static list(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: EncodablePayload): Promise<string | undefined>; | ||
| /** | ||
@@ -69,3 +108,3 @@ * Signs a transaction. | ||
| */ | ||
| static sendTransaction(privateKey: Wasm.PrivateKey, data: Krc20Data, hash: string, amount: bigint, payload?: string): Promise<string>; | ||
| static sendTransaction(privateKey: Wasm.PrivateKey, data: Krc20Data, hash: string, amount: bigint, payload: EncodablePayload): Promise<string>; | ||
| /** | ||
@@ -119,7 +158,7 @@ * Sends KRC20 tokens to another address. | ||
| private static createP2SHAddress; | ||
| static issue(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: Wasm.HexString | Uint8Array): Promise<string | undefined>; | ||
| static burn(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: Wasm.HexString | Uint8Array): Promise<string | undefined>; | ||
| static blacklist(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: Wasm.HexString | Uint8Array): Promise<string | undefined>; | ||
| static chown(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: Wasm.HexString | Uint8Array): Promise<string | undefined>; | ||
| static issue(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: EncodablePayload): Promise<string | undefined>; | ||
| static burn(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: EncodablePayload): Promise<string | undefined>; | ||
| static blacklist(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: EncodablePayload): Promise<string | undefined>; | ||
| static chown(privateKey: Wasm.PrivateKey, data: Krc20Data, fee?: bigint, payload?: EncodablePayload): Promise<string | undefined>; | ||
| } | ||
| export { KRC20 }; |
@@ -25,2 +25,3 @@ import { Wasm } from "../index"; | ||
| ca?: string; | ||
| memo?: string; | ||
| } | ||
@@ -35,1 +36,5 @@ export interface addressList { | ||
| } | ||
| export interface Krc20DataV2 extends Krc20Data { | ||
| payload: string; | ||
| } | ||
| export type EncodablePayload = string | Wasm.HexString | Uint8Array | Record<string, unknown> | Array<unknown> | number | boolean | null | undefined; |
@@ -38,2 +38,3 @@ import { Wasm } from "../index"; | ||
| ca?: string; | ||
| memo?: string; | ||
| }; | ||
@@ -40,0 +41,0 @@ declare function getScriptLockTime(oneHourInSeconds?: number): bigint; |
+6
-1
| { | ||
| "name": "@kasplex/kiwi", | ||
| "version": "1.0.28", | ||
| "version": "1.0.29", | ||
| "type": "module", | ||
@@ -37,2 +37,7 @@ "main": "dist/index.js", | ||
| "license": "ISC", | ||
| "pnpm": { | ||
| "overrides": { | ||
| "minimatch": "^10.2.3" | ||
| } | ||
| }, | ||
| "devDependencies": { | ||
@@ -39,0 +44,0 @@ "@types/node": "^22.14.1", |
+77
-22
@@ -1,4 +0,4 @@ | ||
| # Kasplex Wallet SDK - Kiwi | ||
| # Kasplex Wallet SDK for web - Kiwi | ||
| **Kasplex Wallet SDK - Kasplex in Wallet Integration (Kiwi) is a powerful and easy-to-use SDK designed to simplify the management of Kaspa wallet assets. It provides seamless integration with Kaspa nodes, KRC20 tokens, and essential wallet functionalities, enabling developers to build robust Kaspa-based applications effortlessly. | ||
| **Kasplex Wallet SDK for web - Kasplex in Wallet Integration (Kiwi) is a powerful and easy-to-use SDK designed to simplify the management of Kaspa wallet assets. It provides seamless integration with Kaspa nodes, KRC20 tokens, and essential wallet functionalities, enabling developers to build robust Kaspa-based applications effortlessly. | ||
@@ -10,3 +10,3 @@ ## Features | ||
| - **KRC20 Protocol Implementation & API Integration**: Easily interact with **KRC20 tokens** using built-in API functions. | ||
| - **Kaspa API & Node Connectivity**: Connect to Kaspa nodes for real-time blockchain data and transaction process. | ||
| - **Kaspa API & Node Connectivity**: Connect to Kaspa nodes for real-time blockchain data and transaction processing. | ||
| - **Multi-Signature Wallet Support**: Implement enhanced security with multi-signature wallet functionality. | ||
@@ -16,3 +16,6 @@ - **Message Subscription**: Subscribe to blockchain events, transaction updates, and real-time notifications. | ||
| ## Installation | ||
| Node.js Version Requirement: This SDK requires Node.js version 20.13.1 or higher. You can check the version of Node.js while it is running. | ||
| Node.js Version Requirement: This SDK requires Node.js version 20.13.1 or higher. You can check your Node.js version by running: | ||
| ```sh | ||
| node -v | ||
| ``` | ||
@@ -25,9 +28,27 @@ ## Getting Started | ||
| ```sh | ||
| npm install @kasplex/kiwi | ||
| npm install @kasplex/kiwi-web | ||
| ``` | ||
| 2. **Set up networkType and init rpc client for use**: | ||
| ```typescript | ||
| import { Kiwi, Rpc, Wasm } from "@kasplex/kiwi"; | ||
| await initialize("path to kaspa_bg.wasm"); // you can find kaspa_bg.wasm in @kasplex-web/dist | ||
| await Rpc.setInstance(Wasm.NetworkType.Mainnet).connect(); // connect kaspa node for fetch information from the node if needed | ||
| import { Kiwi, Rpc, Wasm, initialize } from '@kasplex/kiwi-web' | ||
| // Initialize WASM | ||
| // ⚠️ The wasm file MUST be from kaspa-wasm v1.1.0 | ||
| // You can find `kaspa_bg.wasm` in: | ||
| // node_modules/@kasplex/kiwi-web/dist/kaspa_bg.wasm | ||
| // | ||
| // In browser environments, the wasm file should be copied | ||
| // to your project's public directory and referenced by URL. | ||
| // The path must be publicly accessible and served with `application/wasm` MIME type. | ||
| await initialize('/wasm/kaspa_bg.wasm') | ||
| // Set network type (Mainnet or Testnet) | ||
| await Kiwi.setNetwork(Wasm.NetworkType.Mainnet) | ||
| // Use NetworkType.Testnet for testnet | ||
| // await Kiwi.setNetwork(Wasm.NetworkType.Testnet) | ||
| // Initialize and connect RPC client (optional but required for node queries) | ||
| const rpc = Rpc.setInstance(Wasm.NetworkType.Mainnet) | ||
| await rpc.connect() | ||
| ``` | ||
@@ -37,3 +58,3 @@ | ||
| ```typescript | ||
| import { Mnemonic, Wallet } from "@kasplex/kiwi"; | ||
| import { Mnemonic, Wallet } from "@kasplex/kiwi-web"; | ||
| const mnemonic = Mnemonic.random(12); | ||
@@ -44,11 +65,5 @@ console.log("Generated Mnemonic:", mnemonic); | ||
| 4. **send $KAS**: | ||
| 4. **KAS Transfer**: | ||
| ```typescript | ||
| import { KaspaTransaction, Rpc, Wasm } from "@kasplex/kiwi"; | ||
| // Connect to Kaspa testnet node using WebAssembly (Wasm) network type | ||
| // This establishes the RPC connection needed for subsequent transactions | ||
| await Rpc.setInstance(Wasm.NetworkType.Testnet).connect() | ||
| // Transfer KAS from privateKey to toAddress with amount and fee | ||
| import { KaspaTransaction } from "@kasplex/kiwi-web"; | ||
| const resp = await KaspaTransaction.transferKas(privateKey, toAddress, 130000000n, 10000n) | ||
@@ -59,3 +74,3 @@ ``` | ||
| ```typescript | ||
| import { Wasm, Enum, Utils, KRC20 } from "@kasplex/kiwi"; | ||
| import { Enum, Utils, KRC20 } from "@kasplex/kiwi-web"; | ||
| const krc20data = Utils.createKrc20Data({ | ||
@@ -69,10 +84,50 @@ p: "krc-20", | ||
| ``` | ||
| 6. **Browser Extension Integration**: | ||
| ```typescript | ||
| import { BrowerWallet, WalletApi } from "@kasplex/kiwi-web"; | ||
| const walletList = await BrowerWallet.getBrowerWalletList(); | ||
| console.log("walletList", walletList); | ||
| // Create and initialize wallet instance | ||
| const wallet = await WalletApi.create('kasware'); | ||
| // Request account access | ||
| const accounts = await wallet.requestAccounts(); | ||
| console.log('Connected accounts:', accounts); | ||
| // Get wallet balance | ||
| const balance = await wallet.getBalance(); | ||
| console.log('Wallet balance:', balance); | ||
| ``` | ||
| For detailed browser extension integration guide, please refer to our [Browser Extension Documentation](./README-WalletExt.md) | ||
| ## WASM Initialization (Web) | ||
| The Kiwi Web SDK depends on a WebAssembly module (`kaspa_bg.wasm`). | ||
| You must initialize it **once** before using any wallet, RPC, or transaction-related functionality. | ||
| WASM version requirement | ||
| 🔒 WASM Version Compatibility | ||
| This SDK is tested and compatible only with kaspa-wasm@1.1.0. | ||
| ❌ 0.x versions are not supported | ||
| ❌ Mixing JS and WASM from different versions will cause runtime errors | ||
| ✅ Recommended: kaspa-wasm@1.1.0-rc.2 | ||
| 💡 Tip: | ||
| If you encounter errors like | ||
| expected magic word 00 61 73 6d or __wbindgen_closure_wrapper | ||
| please double-check your WASM version and loading path. | ||
| ## More Examples | ||
| - For more detailed usage examples, check out our [Examples Directory](./examples/) | ||
| - For web usage, check out our [Kiwi for WEB](./README-WEB.md) | ||
| - For usage of node, check out our [Kiwi for NODE](./README.md) | ||
| ## Integrated wallet method | ||
| - Please refer to the details for the method of providing a wallet in the [WalletExt](./README-WalletExt.md) | ||
| ## Contribution | ||
@@ -79,0 +134,0 @@ |
Sorry, the diff of this file is too big to display
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
12347145
4.49%40
2.56%35238
69.47%135
68.75%5
66.67%8
100%