Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fuzzy-years-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ckb-ccc/core": minor
---

feat(core): relax `@ccc.codec`'s type restriction

6 changes: 6 additions & 0 deletions .changeset/little-zebras-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ckb-ccc/core": minor
---

feat(core): multisig Signers

6 changes: 6 additions & 0 deletions .changeset/orange-goats-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ckb-ccc/core": minor
---

feat(core): `Transaction.getWitnessArgsAtUnsafe`

6 changes: 6 additions & 0 deletions .changeset/vast-trees-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ckb-ccc/core": minor
---

feat(core): bump @noble packages

39 changes: 18 additions & 21 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,42 @@
},
"sideEffects": false,
"main": "./dist.commonjs/index.js",
"module": "./dist/index.js",
"module": "./dist/index.mjs",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist.commonjs/index.js",
"default": "./dist.commonjs/index.js"
"import": "./dist/index.mjs"
},
"./barrel": {
"import": "./dist/barrel.js",
"require": "./dist.commonjs/barrel.js",
"default": "./dist.commonjs/barrel.js"
"./advanced": {
"require": "./dist.commonjs/advanced.js",
"import": "./dist/advanced.mjs"
},
"./advancedBarrel": {
"import": "./dist/advancedBarrel.js",
"require": "./dist.commonjs/advancedBarrel.js",
"default": "./dist.commonjs/advancedBarrel.js"
"import": "./dist/advancedBarrel.mjs"
},
"./advanced": {
"import": "./dist/advanced.js",
"require": "./dist.commonjs/advanced.js",
"default": "./dist.commonjs/advanced.js"
}
"./barrel": {
"require": "./dist.commonjs/barrel.js",
"import": "./dist/barrel.mjs"
},
"./package.json": "./package.json"
},
"scripts": {
"test": "vitest",
"test:ci": "vitest run",
"build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
"build": "tsdown",
"lint": "eslint ./src",
"format": "prettier --write . && eslint --fix ./src"
},
"devDependencies": {
"@eslint/js": "^9.34.0",
"@types/ws": "^8.18.1",
"copyfiles": "^2.4.1",
"eslint": "^9.34.0",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.4",
"prettier": "^3.6.2",
"prettier-plugin-organize-imports": "^4.2.0",
"rimraf": "^6.0.1",
"tsdown": "0.19.0-beta.3",
"typescript": "^5.9.2",
"typescript-eslint": "^8.41.0",
"vitest": "^3.2.4"
Expand All @@ -61,15 +57,16 @@
},
"dependencies": {
"@joyid/ckb": "^1.1.2",
"@noble/ciphers": "^0.5.3",
"@noble/curves": "^1.9.7",
"@noble/hashes": "^1.8.0",
"@noble/ciphers": "^2.1.1",
"@noble/curves": "^2.0.1",
"@noble/hashes": "^2.0.1",
"bech32": "^2.0.0",
"bs58check": "^4.0.0",
"buffer": "^6.0.3",
"ethers": "^6.15.0",
"isomorphic-ws": "^5.0.0",
"ws": "^8.18.3"
},
"packageManager": "pnpm@10.8.1"
"packageManager": "pnpm@10.8.1",
"types": "./dist.commonjs/index.d.ts"
}
21 changes: 20 additions & 1 deletion packages/core/src/ckb/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1768,10 +1768,29 @@ export class Transaction extends Entity.Base<TransactionLike, Transaction>() {
*
* @example
* ```typescript
* const witnessArgs = await tx.getWitnessArgsAt(0);
* const witnessArgs = tx.getWitnessArgsAt(0);
* ```
*/
getWitnessArgsAt(index: number): WitnessArgs | undefined {
try {
return this.getWitnessArgsAtUnsafe(index);
} catch (_) {
return undefined;
}
}

/**
* Get witness at index as WitnessArgs, throw if failed to decode
*
* @param index - The index of the witness.
* @returns The witness parsed as WitnessArgs.
*
* @example
* ```typescript
* const witnessArgs = tx.getWitnessArgsAtUnsafe(0);
* ```
*/
getWitnessArgsAtUnsafe(index: number): WitnessArgs | undefined {
const rawWitness = this.witnesses[index];
return (rawWitness ?? "0x") !== "0x"
? WitnessArgs.fromBytes(rawWitness)
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/client/clientPublicMainnet.advanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ export const MAINNET_SCRIPTS: Record<KnownScript, ScriptInfoLike | undefined> =
},
],
},
[KnownScript.Secp256k1MultisigV2Beta]: {
codeHash:
"0xd1a9f877aed3f5e07cb9c52b61ab96d06f250ae6883cc7f0a2423db0976fc821",
hashType: "type",
cellDeps: [
{
cellDep: {
outPoint: {
txHash:
"0x44be4f4feda80c0e41783ab10e191df3b2bb5c3731b0970c916dbec385dcdc60",
index: 0,
},
depType: "depGroup",
},
},
],
},
[KnownScript.Secp256k1MultisigV2]: {
codeHash:
"0x36c971b8d41fbd94aabca77dc75e826729ac98447b46f91e00796155dddb0d29",
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/client/clientPublicTestnet.advanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ export const TESTNET_SCRIPTS: Record<KnownScript, ScriptInfoLike> =
},
],
},
[KnownScript.Secp256k1MultisigV2Beta]: {
codeHash:
"0x765b3ed6ae264b335d07e73ac332bf2c0f38f8d3340ed521cb447b4c42dd5f09",
hashType: "type",
cellDeps: [
{
cellDep: {
outPoint: {
txHash:
"0xf2013f123b2cb745e3fdf5c935a3925647496f88090503eef58332a9245b4172",
index: 0,
},
depType: "depGroup",
},
},
],
},
[KnownScript.Secp256k1MultisigV2]: {
codeHash:
"0x36c971b8d41fbd94aabca77dc75e826729ac98447b46f91e00796155dddb0d29",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/client/knownScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum KnownScript {
NervosDao = "NervosDao",
Secp256k1Blake160 = "Secp256k1Blake160",
Secp256k1Multisig = "Secp256k1Multisig",
Secp256k1MultisigV2Beta = "Secp256k1MultisigV2Beta", // Fix rare failing case (https://github.com/nervosnetwork/ckb-system-scripts/pull/98)
Secp256k1MultisigV2 = "Secp256k1MultisigV2", // Enhanced since handling (https://github.com/nervosnetwork/ckb-system-scripts/pull/99)
AnyoneCanPay = "AnyoneCanPay",
TypeId = "TypeId",
Expand Down
16 changes: 11 additions & 5 deletions packages/core/src/codec/entity.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Bytes, bytesEq, BytesLike } from "../bytes/index.js";
import { Bytes, bytesEq, bytesFrom, BytesLike } from "../bytes/index.js";
import { hashCkb } from "../hasher/index.js";
import { Hex, hexFrom } from "../hex/index.js";
import { Constructor } from "../utils/index.js";
import { Codec } from "./codec.js";

/**
* The base class of CCC to create a serializable instance. This should be used with the {@link codec} decorator.
Expand Down Expand Up @@ -172,7 +171,14 @@ export function codec<
Encodable,
TypeLike extends Encodable,
Decoded extends TypeLike,
>(codec: Codec<Encodable, Decoded>) {
>(codec: {
encode: (encodable: Encodable) => Bytes;
decode: (
decodable: Bytes,
config?: { isExtraFieldIgnored?: boolean },
) => Decoded;
byteLength?: number;
}) {
return function <
Type extends TypeLike,
ConstructorType extends Constructor<Type> & {
Expand All @@ -191,12 +197,12 @@ export function codec<
}
if (Constructor.decode === undefined) {
Constructor.decode = function (bytesLike: BytesLike) {
return Constructor.from(codec.decode(bytesLike));
return Constructor.from(codec.decode(bytesFrom(bytesLike)));
};
}
if (Constructor.fromBytes === undefined) {
Constructor.fromBytes = function (bytes: BytesLike) {
return Constructor.from(codec.decode(bytes));
return Constructor.from(codec.decode(bytesFrom(bytes)));
};
}

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/hasher/advanced.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const CKB_BLAKE2B_PERSONAL = "ckb-default-hash";
import { bytesFrom } from "../bytes";

export const CKB_BLAKE2B_PERSONAL = bytesFrom("ckb-default-hash", "utf8");
6 changes: 4 additions & 2 deletions packages/core/src/hasher/hasherCkb.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { blake2b } from "@noble/hashes/blake2b";
import { blake2b } from "@noble/hashes/blake2.js";
import { BytesLike, bytesFrom } from "../bytes/index.js";
import { Hex, hexFrom } from "../hex/index.js";
import { CKB_BLAKE2B_PERSONAL } from "./advanced.js";
import { Hasher } from "./hasher.js";

export const HASH_CKB_LENGTH = 32;
export const HASH_CKB_SHORT_LENGTH = 20;

/**
* @public
*/
Expand Down Expand Up @@ -73,7 +76,6 @@ export class HasherCkb implements Hasher {
* const hash = hashCkb("some data"); // Outputs something like "0x..."
* ```
*/

export function hashCkb(...data: BytesLike[]): Hex {
const hasher = new HasherCkb();
data.forEach((d) => hasher.update(d));
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/hasher/hasherKeecak256.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { keccak_256 } from "@noble/hashes/sha3";
import { keccak_256 } from "@noble/hashes/sha3.js";
import { BytesLike, bytesFrom } from "../bytes/index.js";
import { Hex, hexFrom } from "../hex/index.js";
import { Hasher } from "./hasher.js";
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/keystore/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ctr } from "@noble/ciphers/aes";
import { scryptAsync } from "@noble/hashes/scrypt";
import { keccak_256 } from "@noble/hashes/sha3";
import { randomBytes } from "@noble/hashes/utils";
import { ctr } from "@noble/ciphers/aes.js";
import { scryptAsync } from "@noble/hashes/scrypt.js";
import { keccak_256 } from "@noble/hashes/sha3.js";
import { randomBytes } from "@noble/hashes/utils.js";
import { Bytes, BytesLike, bytesConcat, bytesFrom } from "../bytes/index.js";
import { hexFrom } from "../hex/index.js";

Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/molecule/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ export {
*/
Codec,
/**
* @deprecated Use ccc.CodecLike instead
* @deprecated Use ccc.codecUint instead
*/
CodecLike,
codecUint as uint,
/**
* @deprecated Use ccc.DecodedType instead
* @deprecated Use ccc.codecUintNumber instead
*/
DecodedType,
codecUintNumber as uintNumber,
/**
* @deprecated Use ccc.EncodableType instead
* @deprecated Use ccc.CodecLike instead
*/
EncodableType,
type CodecLike,
/**
* @deprecated Use ccc.codecUint instead
* @deprecated Use ccc.DecodedType instead
*/
codecUint as uint,
type DecodedType,
/**
* @deprecated Use ccc.codecUintNumber instead
* @deprecated Use ccc.EncodableType instead
*/
codecUintNumber as uintNumber,
type EncodableType,
} from "../codec/index.js";

function uint32To(numLike: NumLike) {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/signer/btc/verify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { secp256k1 } from "@noble/curves/secp256k1";
import { secp256k1 } from "@noble/curves/secp256k1.js";
import { ripemd160 } from "@noble/hashes/legacy.js";
import { sha256 } from "@noble/hashes/sha2.js";
import bs58check from "bs58check";
Expand Down Expand Up @@ -98,5 +98,6 @@ export function verifyMessageBtcEcdsa(
bytesFrom(rawSign),
messageHashBtcEcdsa(challenge),
bytesFrom(publicKey),
{ prehash: false },
);
}
4 changes: 3 additions & 1 deletion packages/core/src/signer/ckb/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export * from "./secp256k1Signing.js";
export * from "./signerCkbPrivateKey.js";
export * from "./signerCkbPublicKey.js";
export * from "./signerCkbScriptReadonly.js";
export * from "./verifyCkbSecp256k1.js";
export * from "./signerMultisigCkbPrivateKey.js";
export * from "./signerMultisigCkbReadonly.js";
export * from "./verifyJoyId.js";
Loading