Skip to content

Commit dca37d7

Browse files
authored
Merge pull request #426 from ckb-devrel/develop
Merge 0.4.6 into master
2 parents 789a00a + eff13fe commit dca37d7

10 files changed

Lines changed: 167 additions & 39 deletions

File tree

.changeset/dry-actors-open.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@offckb/cli': patch
3+
---
4+
5+
Upgrade default CKB version from 0.201.0 to 0.205.0
6+
7+
CKB v0.205.0 includes:
8+
9+
- Terminal module for CKB-TUI
10+
- Proxy protocol support
11+
- RPC logs subscription
12+
- Rust toolchain upgrade to 1.92.0

.changeset/fix-privkey-prefix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@offckb/cli": patch
3+
---
4+
5+
fix(cli): standardize private key inputs and fix 0x prefix parsing error (#422)

.changeset/vast-ravens-invent.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@offckb/cli': patch
3+
---
4+
5+
fix(create): ensure CKB binary and devnet config before generating scripts
6+
7+
Fix issue #396 where `offckb create` failed if user hasn't run `offckb node` first.
8+
9+
**Changes:**
10+
11+
- Add imports for `installCKBBinary`, `initChainIfNeeded`, and `readSettings`
12+
- Call `installCKBBinary` to download CKB binary if not exists
13+
- Call `initChainIfNeeded` to initialize devnet config if not exists
14+
- Both calls happen before `genSystemScriptsJsonFile` to ensure dependencies are ready
15+
16+
This makes `offckb create` self-sufficient and doesn't require prior `offckb node` execution.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@offckb/cli",
3-
"version": "0.4.5",
3+
"version": "0.4.6",
44
"description": "ckb development network for your first try",
55
"author": "CKB EcoFund",
66
"license": "MIT",

pnpm-lock.yaml

Lines changed: 35 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cfg/setting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const defaultSettings: Settings = {
6262
proxy: undefined,
6363
bins: {
6464
rootFolder: path.resolve(dataPath, 'bins'),
65-
defaultCKBVersion: '0.201.0',
65+
defaultCKBVersion: '0.205.0',
6666
downloadPath: path.resolve(cachePath, 'download'),
6767
},
6868
devnet: {

src/cmd/create.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { InteractivePrompts } from '../templates/prompts';
66
import { genSystemScriptsJsonFile } from '../scripts/gen';
77
import { CKBDebugger } from '../tools/ckb-debugger';
88
import { logger } from '../util/logger';
9+
import { installCKBBinary as _installCKBBinary } from '../node/install';
10+
import { initChainIfNeeded as _initChainIfNeeded } from '../node/init-chain';
11+
import { readSettings } from '../cfg/setting';
912

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

101104
await processor.generateProject(fullProjectPath, contextWithPath);
102105

106+
const _settings = readSettings();
107+
108+
await _installCKBBinary(_settings.bins.defaultCKBVersion);
109+
await _initChainIfNeeded();
110+
103111
// Generate system-scripts.json
104112
logger.info('🔧 Generating system scripts configuration...');
105113
try {

src/sdk/ckb.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// to replace lumos with ccc
33

44
import { ccc, ClientPublicMainnet, ClientPublicTestnet, OutPointLike, Script } from '@ckb-ccc/core';
5-
import { isValidNetworkString } from '../util/validator';
5+
import { isValidNetworkString, normalizePrivKey } from '../util/validator';
66
import { networks } from './network';
77
import { buildCCCDevnetKnownScripts } from '../scripts/private';
88
import { Migration } from '../deploy/migration';
@@ -81,7 +81,8 @@ export class CKB {
8181
}
8282

8383
buildSigner(privateKey: HexString) {
84-
const signer = new ccc.SignerCkbPrivateKey(this.client, privateKey);
84+
const normalizedKey = normalizePrivKey(privateKey);
85+
const signer = new ccc.SignerCkbPrivateKey(this.client, normalizedKey);
8586
return signer;
8687
}
8788

src/util/validator.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,43 @@ export function isValidVersion(version: unknown): boolean {
7373
// Test the version against the regex
7474
return versionRegex.test(version);
7575
}
76+
77+
export function normalizePrivKey(privKey: string): string {
78+
// Trim surrounding whitespaces
79+
let key = privKey ? privKey.trim() : '';
80+
81+
if (!key) {
82+
throw new Error('Private key is required.');
83+
}
84+
85+
// Strip surrounding quotes
86+
if (key.startsWith('"') && key.endsWith('"')) {
87+
key = key.slice(1, -1);
88+
}
89+
if (key.startsWith("'") && key.endsWith("'")) {
90+
key = key.slice(1, -1);
91+
}
92+
93+
// Trim again to normalize whitespace that was inside surrounding quotes
94+
key = key.trim();
95+
96+
// Remove standard 0x/0X prefix if it exists manually for normalization
97+
if (/^0x/i.test(key)) {
98+
key = key.slice(2);
99+
}
100+
101+
// Validate only hex characters are left
102+
if (!/^[0-9a-fA-F]+$/.test(key)) {
103+
throw new Error('Invalid private key: contains non-hexadecimal characters.');
104+
}
105+
106+
// Enforce exactly 32 bytes length
107+
if (key.length !== 64) {
108+
throw new Error(
109+
`Invalid private key length: expected 32 bytes (64 hex characters), but got ${key.length} characters (excluding 0x prefix).`,
110+
);
111+
}
112+
113+
// Return the formally strictly padded ckb format `0x` string
114+
return '0x' + key;
115+
}

0 commit comments

Comments
 (0)