ckb-session-kit 0.0.0-stage → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { type Session } from "./session.js";
3
+ export declare class ScopeError extends Error {
4
+ constructor(reason: string);
5
+ }
6
+ export declare function sessionSigner(session: Session, client: ccc.Client): ccc.SignerCkbPrivateKey;
7
+ /** The address the session key controls. Fund it to give the session a budget. */
8
+ export declare function sessionAddress(session: Session, client: ccc.Client): Promise<string>;
9
+ /**
10
+ * Sends `amount` shannons to `to`, signed by the session key with no wallet
11
+ * dialog. The scope is checked before anything is built or signed.
12
+ *
13
+ * Until the session lock lands, the scope is enforced here in the browser only;
14
+ * the on-chain lock will make the same refusal binding.
15
+ */
16
+ export declare function sendInScope(session: Session, client: ccc.Client, request: {
17
+ to: string;
18
+ amount: bigint;
19
+ }, now?: Date): Promise<ccc.Hex>;
@@ -0,0 +1,33 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { checkRequest } from "./session.js";
3
+ export class ScopeError extends Error {
4
+ constructor(reason) {
5
+ super(`refused by session scope: ${reason}`);
6
+ this.name = "ScopeError";
7
+ }
8
+ }
9
+ export function sessionSigner(session, client) {
10
+ return new ccc.SignerCkbPrivateKey(client, session.privateKey);
11
+ }
12
+ /** The address the session key controls. Fund it to give the session a budget. */
13
+ export async function sessionAddress(session, client) {
14
+ return sessionSigner(session, client).getRecommendedAddress();
15
+ }
16
+ /**
17
+ * Sends `amount` shannons to `to`, signed by the session key with no wallet
18
+ * dialog. The scope is checked before anything is built or signed.
19
+ *
20
+ * Until the session lock lands, the scope is enforced here in the browser only;
21
+ * the on-chain lock will make the same refusal binding.
22
+ */
23
+ export async function sendInScope(session, client, request, now = new Date()) {
24
+ const check = checkRequest(session, request, now);
25
+ if (!check.ok)
26
+ throw new ScopeError(check.reason);
27
+ const signer = sessionSigner(session, client);
28
+ const { script: lock } = await ccc.Address.fromString(request.to, client);
29
+ const tx = ccc.Transaction.from({ outputs: [{ lock, capacity: request.amount }] });
30
+ await tx.completeInputsByCapacity(signer);
31
+ await tx.completeFeeBy(signer);
32
+ return signer.sendTransaction(tx);
33
+ }
package/package.json CHANGED
@@ -1,6 +1,80 @@
1
- {
2
- "name": "ckb-session-kit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "ckb-session-kit",
3
+ "version": "2.0.0",
4
+ "description": "Browser-held self-custody sessions for CKB applications",
5
+ "keywords": [
6
+ "ckb",
7
+ "nervos",
8
+ "session-keys",
9
+ "lock-script",
10
+ "self-custody",
11
+ "ccc"
12
+ ],
13
+ "license": "MIT",
14
+ "author": "Luong Thanh Tung (https://github.com/luongthanhtung03)",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/luongthanhtung03/ckb-session-kit.git"
18
+ },
19
+ "homepage": "https://github.com/luongthanhtung03/ckb-session-kit#readme",
20
+ "bugs": "https://github.com/luongthanhtung03/ckb-session-kit/issues",
21
+ "type": "module",
22
+ "main": "dist/index.js",
23
+ "types": "dist/index.d.ts",
24
+ "files": [
25
+ "dist",
26
+ "CHANGELOG.md"
27
+ ],
28
+ "engines": {
29
+ "node": ">=20"
30
+ },
31
+ "scripts": {
32
+ "build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
33
+ "typecheck": "tsc --noEmit && tsc -p examples && tsc -p e2e && tsc -p scripts",
34
+ "check:lock-hash": "node scripts/check-lock-hash.mjs",
35
+ "evidence": "node scripts/evidence.mjs",
36
+ "test": "vitest run",
37
+ "e2e": "playwright test -c e2e",
38
+ "smoke:testnet": "tsx scripts/testnet-smoke.ts",
39
+ "demo": "npm run build && npm run dev -w demo",
40
+ "build:demo": "npm run build && npm run build -w demo",
41
+ "deploy:testnet": "tsx scripts/deploy-session-lock.ts",
42
+ "smoke:lock": "tsx scripts/testnet-lock-smoke.ts",
43
+ "smoke:flow": "tsx scripts/testnet-session-flow.ts",
44
+ "smoke:pay-per-read": "tsx scripts/testnet-pay-per-read.ts",
45
+ "setup:creator": "tsx scripts/setup-creator.ts",
46
+ "setup:board": "tsx scripts/setup-board.ts",
47
+ "setup:charger": "tsx scripts/setup-charger.ts",
48
+ "setup:token": "tsx scripts/setup-token.ts",
49
+ "setup:subscription-payout": "tsx scripts/setup-subscription-payout.ts",
50
+ "smoke:recover": "tsx scripts/testnet-recover.ts",
51
+ "smoke:place": "tsx scripts/testnet-place.ts",
52
+ "smoke:listen": "tsx --tsconfig examples/tsconfig.json scripts/testnet-listen.ts",
53
+ "smoke:token": "tsx scripts/testnet-token.ts",
54
+ "smoke:read-tokens": "tsx scripts/testnet-read-tokens.ts",
55
+ "smoke:subscription": "tsx scripts/testnet-subscription.ts",
56
+ "smoke:subscription-token": "tsx scripts/testnet-subscription-token.ts",
57
+ "smoke:contention": "tsx scripts/testnet-contention.ts",
58
+ "smoke:clear-planted": "tsx scripts/testnet-clear-planted.ts",
59
+ "smoke:owner-locks": "tsx scripts/testnet-owner-locks.ts",
60
+ "matrix:wallets": "tsx scripts/wallet-matrix.ts",
61
+ "prepack": "npm run build",
62
+ "pack:check": "node scripts/pack-check.mjs"
63
+ },
64
+ "devDependencies": {
65
+ "@noble/curves": "^2.4.0",
66
+ "@noble/hashes": "^2.4.0",
67
+ "@playwright/test": "^1.64.1",
68
+ "@types/node": "^22.20.5",
69
+ "ckb-testtool": "^1.0.5",
70
+ "tsx": "^4.23.15",
71
+ "typescript": "~5.8.2",
72
+ "vitest": "^4.1.12"
73
+ },
74
+ "dependencies": {
75
+ "@ckb-ccc/core": "^1.23.0"
76
+ },
77
+ "workspaces": [
78
+ "demo"
79
+ ]
80
+ }