Skip to content
Merged
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
12 changes: 12 additions & 0 deletions .changeset/dry-actors-open.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@offckb/cli': patch
---

Upgrade default CKB version from 0.201.0 to 0.205.0

CKB v0.205.0 includes:

- Terminal module for CKB-TUI
- Proxy protocol support
- RPC logs subscription
- Rust toolchain upgrade to 1.92.0
5 changes: 5 additions & 0 deletions .changeset/fix-privkey-prefix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@offckb/cli": patch
---

fix(cli): standardize private key inputs and fix 0x prefix parsing error (#422)
16 changes: 16 additions & 0 deletions .changeset/vast-ravens-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@offckb/cli': patch
---

fix(create): ensure CKB binary and devnet config before generating scripts

Fix issue #396 where `offckb create` failed if user hasn't run `offckb node` first.

**Changes:**

- Add imports for `installCKBBinary`, `initChainIfNeeded`, and `readSettings`
- Call `installCKBBinary` to download CKB binary if not exists
- Call `initChainIfNeeded` to initialize devnet config if not exists
- Both calls happen before `genSystemScriptsJsonFile` to ensure dependencies are ready

This makes `offckb create` self-sufficient and doesn't require prior `offckb node` execution.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@offckb/cli",
"version": "0.4.5",
"version": "0.4.6",
"description": "ckb development network for your first try",
"author": "CKB EcoFund",
"license": "MIT",
Expand Down
70 changes: 35 additions & 35 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/cfg/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
proxy: undefined,
bins: {
rootFolder: path.resolve(dataPath, 'bins'),
defaultCKBVersion: '0.201.0',
defaultCKBVersion: '0.205.0',
downloadPath: path.resolve(cachePath, 'download'),
},
devnet: {
Expand Down Expand Up @@ -129,7 +129,7 @@
return path.join(getCKBBinaryInstallPath(version), binaryName);
}

function deepMerge(target: any, source: any): any {

Check warning on line 132 in src/cfg/setting.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 132 in src/cfg/setting.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 132 in src/cfg/setting.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 132 in src/cfg/setting.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 132 in src/cfg/setting.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 132 in src/cfg/setting.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 132 in src/cfg/setting.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 132 in src/cfg/setting.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 132 in src/cfg/setting.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
for (const key in source) {
if (source[key] && typeof source[key] === 'object') {
if (!target[key]) {
Expand Down
8 changes: 8 additions & 0 deletions src/cmd/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { InteractivePrompts } from '../templates/prompts';
import { genSystemScriptsJsonFile } from '../scripts/gen';
import { CKBDebugger } from '../tools/ckb-debugger';
import { logger } from '../util/logger';
import { installCKBBinary as _installCKBBinary } from '../node/install';
import { initChainIfNeeded as _initChainIfNeeded } from '../node/init-chain';
import { readSettings } from '../cfg/setting';

export interface CreateScriptProjectOptions {
manager?: 'pnpm' | 'yarn' | 'npm';
Expand Down Expand Up @@ -100,6 +103,11 @@ export async function createScriptProject(name?: string, options: CreateScriptPr

await processor.generateProject(fullProjectPath, contextWithPath);

const _settings = readSettings();

await _installCKBBinary(_settings.bins.defaultCKBVersion);
await _initChainIfNeeded();

// Generate system-scripts.json
logger.info('🔧 Generating system scripts configuration...');
try {
Expand Down
5 changes: 3 additions & 2 deletions src/sdk/ckb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// to replace lumos with ccc

import { ccc, ClientPublicMainnet, ClientPublicTestnet, OutPointLike, Script } from '@ckb-ccc/core';
import { isValidNetworkString } from '../util/validator';
import { isValidNetworkString, normalizePrivKey } from '../util/validator';
import { networks } from './network';
import { buildCCCDevnetKnownScripts } from '../scripts/private';
import { Migration } from '../deploy/migration';
Expand Down Expand Up @@ -81,7 +81,8 @@ export class CKB {
}

buildSigner(privateKey: HexString) {
const signer = new ccc.SignerCkbPrivateKey(this.client, privateKey);
const normalizedKey = normalizePrivKey(privateKey);
const signer = new ccc.SignerCkbPrivateKey(this.client, normalizedKey);
return signer;
}

Expand Down
40 changes: 40 additions & 0 deletions src/util/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,43 @@ export function isValidVersion(version: unknown): boolean {
// Test the version against the regex
return versionRegex.test(version);
}

export function normalizePrivKey(privKey: string): string {
// Trim surrounding whitespaces
let key = privKey ? privKey.trim() : '';

if (!key) {
throw new Error('Private key is required.');
}

// Strip surrounding quotes
if (key.startsWith('"') && key.endsWith('"')) {
key = key.slice(1, -1);
}
if (key.startsWith("'") && key.endsWith("'")) {
key = key.slice(1, -1);
}

// Trim again to normalize whitespace that was inside surrounding quotes
key = key.trim();

// Remove standard 0x/0X prefix if it exists manually for normalization
if (/^0x/i.test(key)) {
key = key.slice(2);
}

// Validate only hex characters are left
if (!/^[0-9a-fA-F]+$/.test(key)) {
throw new Error('Invalid private key: contains non-hexadecimal characters.');
}

// Enforce exactly 32 bytes length
if (key.length !== 64) {
throw new Error(
`Invalid private key length: expected 32 bytes (64 hex characters), but got ${key.length} characters (excluding 0x prefix).`,
);
}

// Return the formally strictly padded ckb format `0x` string
return '0x' + key;
}
Loading
Loading