diff --git a/examples/cardano-lock-namiwallet/CardanoWitnessLock.ts b/examples/cardano-lock-namiwallet/CardanoWitnessLock.ts index c929e6971..105c44f2b 100644 --- a/examples/cardano-lock-namiwallet/CardanoWitnessLock.ts +++ b/examples/cardano-lock-namiwallet/CardanoWitnessLock.ts @@ -1,14 +1,12 @@ -import { blockchain } from "@ckb-lumos/base"; -import { molecule } from "@ckb-lumos/codec"; +import { blockchain, table } from "@ckb-lumos/lumos/codec"; -const { Byte32, Bytes } = blockchain; const Byte64 = blockchain.createFixedHexBytesCodec(64); -export const CardanoWitnessLock = molecule.table( +export const CardanoWitnessLock = table( { - pubkey: Byte32, + pubkey: blockchain.Byte32, signature: Byte64, - sig_structure: Bytes, + sig_structure: blockchain.Bytes, }, ["pubkey", "signature", "sig_structure"] ); diff --git a/examples/cardano-lock-namiwallet/lib.ts b/examples/cardano-lock-namiwallet/lib.ts index 0ee1783e6..e011a6f43 100644 --- a/examples/cardano-lock-namiwallet/lib.ts +++ b/examples/cardano-lock-namiwallet/lib.ts @@ -1,5 +1,4 @@ -import { bytes } from "@ckb-lumos/codec"; -import { blockchain } from "@ckb-lumos/base"; +import { hexify, blockchain } from "@ckb-lumos/lumos/codec"; import { BI, Cell, config, helpers, RPC, commons, Indexer } from "@ckb-lumos/lumos"; import { COSESign1Builder, @@ -144,7 +143,7 @@ export async function transfer(options: Options): Promise { ); const tmpWitnessArgs = blockchain.WitnessArgs.pack({ lock: placeHolder }); - const witness = bytes.hexify(tmpWitnessArgs); + const witness = hexify(tmpWitnessArgs); for (let i = 0; i < tx.inputs.toArray().length; i++) { tx = tx.update("witnesses", (witnesses) => witnesses.push(witness)); @@ -166,7 +165,7 @@ export async function transfer(options: Options): Promise { const label = Label.new_int(Int.new_negative(BigNum.from_str("2"))); const CBORPubkey = signedKey.header(label)!; - const signedWitnessArgs = bytes.hexify( + const signedWitnessArgs = hexify( CardanoWitnessLock.pack({ pubkey: CBORPubkey.as_bytes()!.buffer, signature: COSESignature.signature().buffer, @@ -174,7 +173,7 @@ export async function transfer(options: Options): Promise { }) ); - const signedWitness = bytes.hexify(blockchain.WitnessArgs.pack({ lock: signedWitnessArgs })); + const signedWitness = hexify(blockchain.WitnessArgs.pack({ lock: signedWitnessArgs })); tx = tx.update("witnesses", (witnesses) => witnesses.set(0, signedWitness)); const signedTx = helpers.createTransactionFromSkeleton(tx); diff --git a/examples/cardano-lock-namiwallet/package.json b/examples/cardano-lock-namiwallet/package.json index 4a651281c..4e4039c73 100644 --- a/examples/cardano-lock-namiwallet/package.json +++ b/examples/cardano-lock-namiwallet/package.json @@ -12,12 +12,15 @@ "author": "", "license": "MIT", "dependencies": { - "@ckb-lumos/lumos": "next", + "@ckb-lumos/lumos": "canary", "@emurgo/cardano-message-signing-asmjs": "^1.0.1", "@emurgo/cardano-serialization-lib-asmjs": "^10.0.4", "@types/react": "^18.0.25", "@types/react-dom": "^18.0.9", "react": "18.2.0", "react-dom": "18.2.0" + }, + "devDependencies": { + "parcel": "^2.9.3" } } diff --git a/examples/exchange-sudt-for-ckb/package.json b/examples/exchange-sudt-for-ckb/package.json index 51ef302f6..40f128bf2 100644 --- a/examples/exchange-sudt-for-ckb/package.json +++ b/examples/exchange-sudt-for-ckb/package.json @@ -16,10 +16,6 @@ "typescript": "5.0.4" }, "dependencies": { - "@ckb-lumos/base": "canary", - "@ckb-lumos/bi": "canary", - "@ckb-lumos/codec": "canary", - "@ckb-lumos/common-scripts": "canary", "@ckb-lumos/lumos": "canary", "@types/react": "^18.0.25", "@types/react-dom": "^18.0.9", diff --git a/examples/exchange-sudt-for-ckb/src/lib.ts b/examples/exchange-sudt-for-ckb/src/lib.ts index 183b6c128..fda2d95b0 100644 --- a/examples/exchange-sudt-for-ckb/src/lib.ts +++ b/examples/exchange-sudt-for-ckb/src/lib.ts @@ -1,12 +1,9 @@ -import { Indexer, helpers, Address, Script, RPC, hd, config, Cell, commons, BI } from "@ckb-lumos/lumos"; -import { sudt } from "@ckb-lumos/common-scripts"; -import { BIish } from "@ckb-lumos/bi"; -import { payFeeByFeeRate } from "@ckb-lumos/common-scripts/lib/common"; -import { addCellDep } from "@ckb-lumos/common-scripts/lib/helper"; +import { Indexer, helpers, Address, Script, RPC, hd, config, Cell, commons, BI, BIish } from "@ckb-lumos/lumos"; +import { sudt, common } from "@ckb-lumos/lumos/common-scripts"; +import { addCellDep } from "@ckb-lumos/lumos/helpers"; +import { hexify, Uint128, blockchain } from "@ckb-lumos/lumos/codec"; +import { computeScriptHash } from "@ckb-lumos/lumos/utils"; import { List } from "immutable"; -import { computeScriptHash } from "@ckb-lumos/base/lib/utils"; -import { bytes } from "@ckb-lumos/codec"; -import { blockchain } from "@ckb-lumos/base"; export const { AGGRON4 } = config.predefined; const CKB_RPC_URL = "https://testnet.ckb.dev/rpc"; @@ -53,7 +50,7 @@ export const issueSUDT = async (privateKey: string) => { config: AGGRON4, }); - txSkeleton = await payFeeByFeeRate(txSkeleton, [account.address], 1000, undefined, { config: AGGRON4 }); + txSkeleton = await common.payFeeByFeeRate(txSkeleton, [account.address], 1000, undefined, { config: AGGRON4 }); const tx = signTx(txSkeleton, [privateKey]); const txHash = await rpc.sendTransaction(tx, "passthrough"); @@ -122,7 +119,7 @@ export async function transferCKB2SUDT(issuerPrivateKey: string, holderPrivateKe break; } inputs = inputs.push(cell); - total = total.add(sudt.unpackAmount(cell.data)); + total = total.add(Uint128.unpack(cell.data)); } return inputs; }); @@ -146,7 +143,7 @@ export async function transferCKB2SUDT(issuerPrivateKey: string, holderPrivateKe lock: holderAccountInfo.lockScript, type: issuerTypeScript, }, - data: sudt.packAmount(SUDTAmount), + data: hexify(Uint128.pack(SUDTAmount)), }; console.log(calculateSUDTAmountSum(issuerSUDTCells).toBigInt()); @@ -157,7 +154,7 @@ export async function transferCKB2SUDT(issuerPrivateKey: string, holderPrivateKe lock: issuerAccountInfo.lockScript, type: issuerTypeScript, }, - data: sudt.packAmount(calculateSUDTAmountSum(issuerSUDTCells).sub(SUDTAmount)), + data: hexify(Uint128.pack(calculateSUDTAmountSum(issuerSUDTCells).sub(SUDTAmount))), }; SUDTTargetOutput.cellOutput.capacity = BI.from(helpers.minimalCellCapacity(SUDTTargetOutput)).toHexString(); @@ -238,7 +235,7 @@ export async function transferCKB2SUDT(issuerPrivateKey: string, holderPrivateKe lock: "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", }; - const witnessArgs = bytes.hexify(blockchain.WitnessArgs.pack(placeholderWitness)); + const witnessArgs = hexify(blockchain.WitnessArgs.pack(placeholderWitness)); for (let index = 0; index < txSkeleton.inputs.size; index++) { witnesses = witnesses.push(witnessArgs); @@ -248,7 +245,9 @@ export async function transferCKB2SUDT(issuerPrivateKey: string, holderPrivateKe }); console.log(txSkeleton.toJS()); - txSkeleton = await payFeeByFeeRate(txSkeleton, [holderAccountInfo.address], 1000, undefined, { config: AGGRON4 }); + txSkeleton = await common.payFeeByFeeRate(txSkeleton, [holderAccountInfo.address], 1000, undefined, { + config: AGGRON4, + }); // STEP2: sign the transaction skeleton const tx = signTx(txSkeleton, [issuerPrivateKey, holderPrivateKey, issuerPrivateKey]); @@ -274,7 +273,7 @@ export function calculateSUDTAmountSum(cells: Cell[]) { let amount = BI.from(0); for (const cell of cells) { if (cell.cellOutput.type?.codeHash === AGGRON4.SCRIPTS.SUDT.CODE_HASH) { - amount = amount.add(sudt.unpackAmount(cell.data)); + amount = amount.add(Uint128.unpack(cell.data)); } } @@ -310,7 +309,7 @@ export async function fetchSUDTBalance(address: string, issuerLockScript: Script let amount = BI.from(0); for await (const cell of collector.collect()) { - amount = amount.add(sudt.unpackAmount(cell.data)); + amount = amount.add(Uint128.unpack(cell.data)); } return amount; } diff --git a/examples/omni-lock-metamask/lib.ts b/examples/omni-lock-metamask/lib.ts index 898034b58..699470625 100644 --- a/examples/omni-lock-metamask/lib.ts +++ b/examples/omni-lock-metamask/lib.ts @@ -1,6 +1,6 @@ -import { bytes } from "@ckb-lumos/codec"; -import { blockchain } from "@ckb-lumos/base"; import { BI, Cell, helpers, Indexer, RPC, config, commons } from "@ckb-lumos/lumos"; +import { blockchain, bytify, hexify } from "@ckb-lumos/lumos/codec"; + const CKB_RPC_URL = "https://testnet.ckb.dev/rpc"; const rpc = new RPC(CKB_RPC_URL); const indexer = new Indexer(CKB_RPC_URL); @@ -30,7 +30,7 @@ interface Options { to: string; amount: string; } -const SECP_SIGNATURE_PLACEHOLDER = bytes.hexify( +const SECP_SIGNATURE_PLACEHOLDER = hexify( new Uint8Array( commons.omnilock.OmnilockWitnessLock.pack({ signature: new Uint8Array(65).buffer, @@ -100,7 +100,7 @@ export async function transfer(options: Options): Promise { ) ); - const witness = bytes.hexify(blockchain.WitnessArgs.pack({ lock: SECP_SIGNATURE_PLACEHOLDER })); + const witness = hexify(blockchain.WitnessArgs.pack({ lock: SECP_SIGNATURE_PLACEHOLDER })); // fill txSkeleton's witness with placeholder for (let i = 0; i < tx.inputs.toArray().length; i++) { @@ -118,10 +118,10 @@ export async function transfer(options: Options): Promise { if (v >= 27) v -= 27; signedMessage = "0x" + signedMessage.slice(2, -2) + v.toString(16).padStart(2, "0"); - const signedWitness = bytes.hexify( + const signedWitness = hexify( blockchain.WitnessArgs.pack({ lock: commons.omnilock.OmnilockWitnessLock.pack({ - signature: bytes.bytify(signedMessage).buffer, + signature: bytify(signedMessage).buffer, }), }) ); diff --git a/examples/omni-lock-metamask/package.json b/examples/omni-lock-metamask/package.json index b9ac1a892..4d50b6587 100644 --- a/examples/omni-lock-metamask/package.json +++ b/examples/omni-lock-metamask/package.json @@ -10,9 +10,7 @@ "author": "", "license": "MIT", "dependencies": { - "@ckb-lumos/base": "next", - "@ckb-lumos/codec": "next", - "@ckb-lumos/lumos": "next", + "@ckb-lumos/lumos": "canary", "@types/react": "^18.0.25", "@types/react-dom": "^18.0.9", "react": "18.2.0", diff --git a/examples/omni-lock-secp256k1-blake160/index.tsx b/examples/omni-lock-secp256k1-blake160/index.tsx index 2eec92c42..919ef30dd 100644 --- a/examples/omni-lock-secp256k1-blake160/index.tsx +++ b/examples/omni-lock-secp256k1-blake160/index.tsx @@ -1,9 +1,9 @@ import React, { useState } from "react"; -import { helpers, Script } from "@ckb-lumos/lumos"; -import { key } from '@ckb-lumos/hd'; +import { Script, hd } from "@ckb-lumos/lumos"; import { ec as EC } from "elliptic"; import ReactDOM from "react-dom"; import { capacityOf, CONFIG, buildTransfer, signByPrivateKey, sendTransaction } from "./lib"; +import { encodeToAddress } from "@ckb-lumos/lumos/helpers"; const app = document.getElementById("root"); ReactDOM.render(, app); @@ -26,17 +26,10 @@ export function Connect({ onConnect }: ConnectProps) {
setPrivateKey(e.target.value)} placeholder="0x..." /> - -
@@ -49,14 +42,16 @@ export function App() { const [omniLock, setOmniLock] = useState