Skip to content

Commit 382f73b

Browse files
committed
Merge remote-tracking branch 'origin/develop' into secp256k1-transfer
2 parents 9f62443 + f244d81 commit 382f73b

File tree

229 files changed

+19340
-11608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+19340
-11608
lines changed

examples/cardano-lock-namiwallet/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export function App() {
3939
setCardanoAddr(address);
4040

4141
const cardanoLock: Script = {
42-
code_hash: CONFIG.SCRIPTS.CARDANO_LOCK.CODE_HASH,
43-
hash_type: CONFIG.SCRIPTS.CARDANO_LOCK.HASH_TYPE,
42+
codeHash: CONFIG.SCRIPTS.CARDANO_LOCK.CODE_HASH,
43+
hashType: CONFIG.SCRIPTS.CARDANO_LOCK.HASH_TYPE,
4444
args: address,
4545
};
4646
const ckbAddr = helpers.generateAddress(cardanoLock);

examples/cardano-lock-namiwallet/lib.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { BI, Cell, config, core, helpers, Indexer, RPC, toolkit, utils, commons } from "@ckb-lumos/lumos";
1+
import { bytes } from '@ckb-lumos/codec';
2+
import { blockchain } from '@ckb-lumos/base';
3+
import { BI, Cell, config, helpers, RPC, commons, Indexer } from "@ckb-lumos/lumos";
24
import {
35
COSESign1Builder,
46
HeaderMap,
@@ -83,7 +85,7 @@ export async function transfer(options: Options): Promise<string> {
8385
const collectedCells: Cell[] = [];
8486
const collector = indexer.collector({ lock: fromScript, type: "empty" });
8587
for await (const cell of collector.collect()) {
86-
collectedSum = collectedSum.add(cell.cell_output.capacity);
88+
collectedSum = collectedSum.add(cell.cellOutput.capacity);
8789
collectedCells.push(cell);
8890
if (BI.from(collectedSum).gte(neededCapacity)) break;
8991
}
@@ -93,15 +95,15 @@ export async function transfer(options: Options): Promise<string> {
9395
}
9496

9597
const transferOutput: Cell = {
96-
cell_output: {
98+
cellOutput: {
9799
capacity: BI.from(options.amount).toHexString(),
98100
lock: toScript,
99101
},
100102
data: "0x",
101103
};
102104

103105
const changeOutput: Cell = {
104-
cell_output: {
106+
cellOutput: {
105107
capacity: collectedSum.sub(neededCapacity).toHexString(),
106108
lock: fromScript,
107109
},
@@ -112,11 +114,11 @@ export async function transfer(options: Options): Promise<string> {
112114
tx = tx.update("outputs", (outputs) => outputs.push(transferOutput, changeOutput));
113115
tx = tx.update("cellDeps", (cellDeps) =>
114116
cellDeps.push({
115-
out_point: {
116-
tx_hash: CONFIG.SCRIPTS.CARDANO_LOCK.TX_HASH,
117+
outPoint: {
118+
txHash: CONFIG.SCRIPTS.CARDANO_LOCK.TX_HASH,
117119
index: CONFIG.SCRIPTS.CARDANO_LOCK.INDEX,
118120
},
119-
dep_type: CONFIG.SCRIPTS.CARDANO_LOCK.DEP_TYPE,
121+
depType: CONFIG.SCRIPTS.CARDANO_LOCK.DEP_TYPE,
120122
})
121123
);
122124

@@ -132,25 +134,25 @@ export async function transfer(options: Options): Promise<string> {
132134
let builder = COSESign1Builder.new(headers, Buffer.from(payload, "hex"), false);
133135
let toSign = builder.make_data_to_sign().to_bytes();
134136

135-
const placeHolder = new toolkit.Reader(
137+
const placeHolder = (
136138
"0x" +
137139
"00".repeat(
138140
SerializeCardanoWitnessLock({
139-
pubkey: new toolkit.Reader("0x" + "00".repeat(32)).toArrayBuffer(),
140-
signature: new toolkit.Reader("0x" + "00".repeat(64)).toArrayBuffer(),
141+
pubkey: new Uint8Array(32),
142+
signature: new Uint8Array(64),
141143
sig_structure: toSign.buffer,
142144
}).byteLength
143145
)
144146
);
145147

146-
const tmpWitnessArgs = core.SerializeWitnessArgs(toolkit.normalizers.NormalizeWitnessArgs({ lock: placeHolder }));
147-
const witness = new toolkit.Reader(tmpWitnessArgs).serializeJson();
148+
const tmpWitnessArgs = blockchain.WitnessArgs.pack({ lock: placeHolder });
149+
const witness = bytes.hexify(tmpWitnessArgs);
148150

149151
for (let i = 0; i < tx.inputs.toArray().length; i++) {
150152
tx = tx.update("witnesses", (witnesses) => witnesses.push(witness));
151153
}
152154

153-
const signLock = tx.inputs.get(0)?.cell_output.lock!;
155+
const signLock = tx.inputs.get(0)?.cellOutput.lock!;
154156
const messageGroup = commons.createP2PKHMessageGroup(tx, [signLock]);
155157
const messageForSigning = messageGroup[0].message.slice(2);
156158

@@ -166,21 +168,19 @@ export async function transfer(options: Options): Promise<string> {
166168
const label = Label.new_int(Int.new_negative(BigNum.from_str("2")));
167169
const CBORPubkey = signedKey.header(label)!;
168170

169-
const signedWitnessArgs = new toolkit.Reader(
171+
const signedWitnessArgs = bytes.hexify(
170172
SerializeCardanoWitnessLock({
171173
pubkey: CBORPubkey.as_bytes()!.buffer,
172174
signature: COSESignature.signature().buffer,
173175
sig_structure: toSign.buffer,
174176
})
175177
);
176178

177-
const signedWitness = new toolkit.Reader(
178-
core.SerializeWitnessArgs(toolkit.normalizers.NormalizeWitnessArgs({ lock: signedWitnessArgs }))
179-
).serializeJson();
179+
const signedWitness = bytes.hexify(blockchain.WitnessArgs.pack({ lock: signedWitnessArgs }))
180180
tx = tx.update("witnesses", (witnesses) => witnesses.set(0, signedWitness));
181181

182182
const signedTx = helpers.createTransactionFromSkeleton(tx);
183-
const txHash = await rpc.send_transaction(signedTx, "passthrough");
183+
const txHash = await rpc.sendTransaction(signedTx, "passthrough");
184184

185185
return txHash;
186186
}
@@ -192,7 +192,7 @@ export async function capacityOf(address: string): Promise<BI> {
192192

193193
let balance = BI.from(0);
194194
for await (const cell of collector.collect()) {
195-
balance = balance.add(cell.cell_output.capacity);
195+
balance = balance.add(cell.cellOutput.capacity);
196196
}
197197

198198
return balance;

examples/cardano-lock-namiwallet/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@lumos-examples/cardano-lock-namiwallet",
4-
"version": "0.18.0",
4+
"version": "0.19.0-alpha.0",
55
"description": "",
66
"main": "index.js",
77
"scripts": {
@@ -12,7 +12,7 @@
1212
"author": "",
1313
"license": "MIT",
1414
"dependencies": {
15-
"@ckb-lumos/lumos": "0.18.0",
15+
"@ckb-lumos/lumos": "0.19.0-alpha.0",
1616
"@emurgo/cardano-message-signing-asmjs": "^1.0.1",
1717
"@emurgo/cardano-serialization-lib-asmjs": "^10.0.4",
1818
"@types/react": "^17.0.34",

examples/ckb-indexer-collector.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// This example shows how to use the CkbIndexer to collect cells
22

3-
import { Script, Indexer as CkbIndexer, helpers, config, BI } from "@ckb-lumos/lumos";
3+
import { Script, Indexer, helpers, config, BI } from "@ckb-lumos/lumos";
44

55
config.initializeConfig(config.predefined.AGGRON4);
66

77
const CKB_RPC_URL = "https://testnet.ckb.dev/rpc";
88
const CKB_INDEXER_URL = "https://testnet.ckb.dev/indexer";
9-
const indexer = new CkbIndexer(CKB_INDEXER_URL, CKB_RPC_URL);
9+
const indexer = new Indexer(CKB_INDEXER_URL, CKB_RPC_URL);
1010

1111
async function capacityOf(lock: Script): Promise<BI> {
1212
const collector = indexer.collector({ lock });
1313

1414
let balance: BI = BI.from(0);
1515
for await (const cell of collector.collect()) {
16-
balance = balance.add(cell.cell_output.capacity);
16+
balance = balance.add(cell.cellOutput.capacity);
1717
}
1818

1919
return balance;

examples/config-manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { config, helpers } from "@ckb-lumos/lumos";
22

33
const script = {
4-
code_hash: config.predefined.AGGRON4.SCRIPTS.SECP256K1_BLAKE160.CODE_HASH,
5-
hash_type: config.predefined.AGGRON4.SCRIPTS.SECP256K1_BLAKE160.HASH_TYPE,
4+
codeHash: config.predefined.AGGRON4.SCRIPTS.SECP256K1_BLAKE160.CODE_HASH,
5+
hashType: config.predefined.AGGRON4.SCRIPTS.SECP256K1_BLAKE160.HASH_TYPE,
66
args: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
77
};
88

examples/omni-lock-metamask/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export function App() {
3030
.enable()
3131
.then(([ethAddr]: string[]) => {
3232
const omniLock: Script = {
33-
code_hash: CONFIG.SCRIPTS.OMNI_LOCK.CODE_HASH,
34-
hash_type: CONFIG.SCRIPTS.OMNI_LOCK.HASH_TYPE,
33+
codeHash: CONFIG.SCRIPTS.OMNI_LOCK.CODE_HASH,
34+
hashType: CONFIG.SCRIPTS.OMNI_LOCK.HASH_TYPE,
3535
// omni flag pubkey hash omni lock flags
3636
// chain identity eth addr function flag()
3737
// 00: Nervos 👇 00: owner

examples/omni-lock-metamask/lib.ts

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { BI, Cell, config, core, helpers, Indexer, RPC, toolkit, utils, commons } from "@ckb-lumos/lumos";
1+
import { bytes } from '@ckb-lumos/codec';
2+
import { blockchain } from '@ckb-lumos/base';
3+
import { BI, Cell, config, helpers, Indexer, RPC, utils, commons } from "@ckb-lumos/lumos";
24
import { SerializeRcLockWitnessLock } from "./generated/omni";
35

46
export const CONFIG = config.createConfig({
@@ -63,7 +65,7 @@ export async function transfer(options: Options): Promise<string> {
6365
const collectedCells: Cell[] = [];
6466
const collector = indexer.collector({ lock: fromScript, type: "empty" });
6567
for await (const cell of collector.collect()) {
66-
collectedSum = collectedSum.add(cell.cell_output.capacity);
68+
collectedSum = collectedSum.add(cell.cellOutput.capacity);
6769
collectedCells.push(cell);
6870
if (BI.from(collectedSum).gte(neededCapacity)) break;
6971
}
@@ -73,15 +75,15 @@ export async function transfer(options: Options): Promise<string> {
7375
}
7476

7577
const transferOutput: Cell = {
76-
cell_output: {
78+
cellOutput: {
7779
capacity: BI.from(options.amount).toHexString(),
7880
lock: toScript,
7981
},
8082
data: "0x",
8183
};
8284

8385
const changeOutput: Cell = {
84-
cell_output: {
86+
cellOutput: {
8587
capacity: collectedSum.sub(neededCapacity).toHexString(),
8688
lock: fromScript,
8789
},
@@ -94,51 +96,49 @@ export async function transfer(options: Options): Promise<string> {
9496
cellDeps.push(
9597
// omni lock dep
9698
{
97-
out_point: {
98-
tx_hash: CONFIG.SCRIPTS.OMNI_LOCK.TX_HASH,
99+
outPoint: {
100+
txHash: CONFIG.SCRIPTS.OMNI_LOCK.TX_HASH,
99101
index: CONFIG.SCRIPTS.OMNI_LOCK.INDEX,
100102
},
101-
dep_type: CONFIG.SCRIPTS.OMNI_LOCK.DEP_TYPE,
103+
depType: CONFIG.SCRIPTS.OMNI_LOCK.DEP_TYPE,
102104
},
103105
// SECP256K1 lock is depended by omni lock
104106
{
105-
out_point: {
106-
tx_hash: CONFIG.SCRIPTS.SECP256K1_BLAKE160.TX_HASH,
107+
outPoint: {
108+
txHash: CONFIG.SCRIPTS.SECP256K1_BLAKE160.TX_HASH,
107109
index: CONFIG.SCRIPTS.SECP256K1_BLAKE160.INDEX,
108110
},
109-
dep_type: CONFIG.SCRIPTS.SECP256K1_BLAKE160.DEP_TYPE,
111+
depType: CONFIG.SCRIPTS.SECP256K1_BLAKE160.DEP_TYPE,
110112
}
111113
)
112114
);
113115

114116
const messageForSigning = (() => {
115117
const hasher = new utils.CKBHasher();
116118

117-
const SECP_SIGNATURE_PLACEHOLDER = new toolkit.Reader(
119+
const SECP_SIGNATURE_PLACEHOLDER = (
118120
"0x" +
119121
"00".repeat(
120122
SerializeRcLockWitnessLock({
121-
signature: new toolkit.Reader("0x" + "00".repeat(65)),
123+
signature: new Uint8Array(65),
122124
}).byteLength
123125
)
124126
);
125127
const newWitnessArgs = { lock: SECP_SIGNATURE_PLACEHOLDER };
126-
const witness = new toolkit.Reader(
127-
core.SerializeWitnessArgs(toolkit.normalizers.NormalizeWitnessArgs(newWitnessArgs))
128-
).serializeJson();
128+
const witness = bytes.hexify(blockchain.WitnessArgs.pack(newWitnessArgs))
129129

130130
// fill txSkeleton's witness with 0
131131
for (let i = 0; i < tx.inputs.toArray().length; i++) {
132132
tx = tx.update("witnesses", (witnesses) => witnesses.push(witness));
133133
}
134134

135135
// locks you want to sign
136-
const signLock = tx.inputs.get(0)?.cell_output.lock!;
136+
const signLock = tx.inputs.get(0)?.cellOutput.lock!;
137137

138138
const messageGroup = commons.createP2PKHMessageGroup(tx, [signLock], {
139139
hasher: {
140140
update: (message) => hasher.update(message.buffer),
141-
digest: () => new Uint8Array(hasher.digestReader().toArrayBuffer()),
141+
digest: () => new Uint8Array(bytes.bytify(hasher.digestHex())),
142142
},
143143
});
144144

@@ -154,18 +154,16 @@ export async function transfer(options: Options): Promise<string> {
154154
if (v >= 27) v -= 27;
155155
signedMessage = "0x" + signedMessage.slice(2, -2) + v.toString(16).padStart(2, "0");
156156

157-
const signedWitness = new toolkit.Reader(
158-
core.SerializeWitnessArgs({
159-
lock: SerializeRcLockWitnessLock({
160-
signature: new toolkit.Reader(signedMessage),
161-
}),
162-
})
163-
).serializeJson();
157+
const signedWitness = bytes.hexify(blockchain.WitnessArgs.pack({
158+
lock: bytes.hexify( SerializeRcLockWitnessLock({
159+
signature: bytes.bytify(signedMessage),
160+
})),
161+
}))
164162

165163
tx = tx.update("witnesses", (witnesses) => witnesses.set(0, signedWitness));
166164

167165
const signedTx = helpers.createTransactionFromSkeleton(tx);
168-
const txHash = await rpc.send_transaction(signedTx, "passthrough");
166+
const txHash = await rpc.sendTransaction(signedTx, "passthrough");
169167

170168
return txHash;
171169
}
@@ -177,7 +175,7 @@ export async function capacityOf(address: string): Promise<BI> {
177175

178176
let balance = BI.from(0);
179177
for await (const cell of collector.collect()) {
180-
balance = balance.add(cell.cell_output.capacity);
178+
balance = balance.add(cell.cellOutput.capacity);
181179
}
182180

183181
return balance;

examples/omni-lock-metamask/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@lumos-examples/omni-lock-metamask",
4-
"version": "0.18.0",
4+
"version": "0.19.0-alpha.0",
55
"description": "",
66
"main": "index.js",
77
"scripts": {
@@ -12,7 +12,7 @@
1212
"author": "",
1313
"license": "MIT",
1414
"dependencies": {
15-
"@ckb-lumos/lumos": "0.18.0",
15+
"@ckb-lumos/lumos": "0.19.0-alpha.0",
1616
"@types/react": "^17.0.34",
1717
"@types/react-dom": "^17.0.11",
1818
"react": "^17.0.2",

examples/omni-lock-secp256k1-blake160/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ export function App() {
5959
const pubkeyHash = key.privateKeyToBlake160(pk);
6060

6161
const omniLock: Script = {
62-
code_hash: CONFIG.SCRIPTS.OMNI_LOCK.CODE_HASH,
63-
hash_type: CONFIG.SCRIPTS.OMNI_LOCK.HASH_TYPE,
62+
codeHash: CONFIG.SCRIPTS.OMNI_LOCK.CODE_HASH,
63+
hashType: CONFIG.SCRIPTS.OMNI_LOCK.HASH_TYPE,
6464
// omni flag pubkey hash omni lock flags
6565
// chain identity eth addr function flag()
6666
// 00: Nervos 👇 00: owner

0 commit comments

Comments
 (0)