@callcium/sdk 0.7.0 → 0.8.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.
- package/README.md +77 -2
- package/dist/index.js +1 -1
- package/package.json +5 -2
- package/src/policy-coder.ts +1 -1
- package/src/signature.ts +1 -1
package/README.md
CHANGED
|
@@ -1,16 +1,91 @@
|
|
|
1
1
|
# @callcium/sdk
|
|
2
2
|
|
|
3
|
-
TypeScript
|
|
3
|
+
TypeScript SDK for the [Callcium](https://callcium.dev) policy engine.
|
|
4
|
+
|
|
5
|
+
Callcium defines type-safe constraints on ABI-encoded data, such as function arguments or a raw payload with no selector, using value ranges, set membership, array quantifiers, and transaction context. This SDK builds policies into canonical policy bytes and validates ABI-encoded data, such as transaction calldata, against a policy offchain, before it is signed.
|
|
4
6
|
|
|
5
7
|
## Install
|
|
6
8
|
|
|
9
|
+
```bash
|
|
10
|
+
npm install @callcium/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
7
13
|
```bash
|
|
8
14
|
bun add @callcium/sdk
|
|
9
15
|
```
|
|
10
16
|
|
|
17
|
+
## Requirements
|
|
18
|
+
|
|
19
|
+
Node.js >=22.11.0. Ships as ESM, built to ES2024 — any browser or runtime with ES2024 support works; no browser floor is tested or declared.
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { PolicyBuilder, PolicyEnforcer, arg } from "@callcium/sdk";
|
|
25
|
+
|
|
26
|
+
// function approve(address spender, uint256 amount)
|
|
27
|
+
const policy = PolicyBuilder.create("approve(address,uint256)")
|
|
28
|
+
.add(arg(0).isIn(trustedSpenders)) // spender
|
|
29
|
+
.add(arg(1).lte(1_000_000n * 10n ** 6n)) // amount
|
|
30
|
+
.build();
|
|
31
|
+
|
|
32
|
+
// throws on a violation
|
|
33
|
+
PolicyEnforcer.enforce(policy, calldata);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## More examples
|
|
37
|
+
|
|
38
|
+
**Nested structs** — target fields deep inside struct arguments by path.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
// struct SwapParams { address tokenIn; address tokenOut; uint256 amount; }
|
|
42
|
+
// function swap(SwapParams params)
|
|
43
|
+
const policy = PolicyBuilder.create("swap((address,address,uint256))")
|
|
44
|
+
.add(arg(0, 0).notIn(denied)) // params.tokenIn
|
|
45
|
+
.add(arg(0, 1).notIn(denied)) // params.tokenOut
|
|
46
|
+
.add(arg(0, 2).gt(0n)) // params.amount
|
|
47
|
+
.build();
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**Arrays** — `ANY`/`ALL` quantifiers across array elements, with length bounds.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// struct Transfer { address to; uint256 value; }
|
|
54
|
+
// function batch(Transfer[] transfers)
|
|
55
|
+
const policy = PolicyBuilder.create("batch((address,uint256)[])")
|
|
56
|
+
.add(arg(0).lengthBetween(1, 50)) // transfers.length
|
|
57
|
+
.add(arg(0, Quantifier.ALL, 0).notIn(denied)) // transfers[*].to
|
|
58
|
+
.add(arg(0, Quantifier.ALL, 1).lte(1n * 10n ** 18n)) // transfers[*].value
|
|
59
|
+
.build();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Context** — constrain `msg.sender`, `msg.value`, `block.timestamp`, `block.number`, `block.chainid`, `tx.origin`, `block.basefee`, and `tx.gasprice`, not just calldata.
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
// function transfer(address to, uint256 amount)
|
|
66
|
+
const policy = PolicyBuilder.create("transfer(address,uint256)")
|
|
67
|
+
.add(msgSender().isIn(operators)) // msg.sender
|
|
68
|
+
.add(msgValue().eq(0n)) // msg.value
|
|
69
|
+
.add(arg(1).lte(100n * 10n ** 18n)) // amount
|
|
70
|
+
.build();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**OR groups** — compose alternative rule paths; all constraints hold within a group.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
// function supply(address asset, uint256 amount)
|
|
77
|
+
const policy = PolicyBuilder.create("supply(address,uint256)")
|
|
78
|
+
.add(msgSender().eq(OPERATOR)) // path A
|
|
79
|
+
.or()
|
|
80
|
+
.add(arg(0).isIn(allowed)) // path B
|
|
81
|
+
.build();
|
|
82
|
+
```
|
|
83
|
+
|
|
11
84
|
## Documentation
|
|
12
85
|
|
|
13
|
-
Full
|
|
86
|
+
Full API reference, guides, and the policy spec: [callcium.dev/docs/sdk](https://callcium.dev/docs/sdk).
|
|
87
|
+
|
|
88
|
+
For onchain policy enforcement in Solidity, see [callcium.dev/docs/solidity](https://callcium.dev/docs/solidity).
|
|
14
89
|
|
|
15
90
|
## License
|
|
16
91
|
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@callcium/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "TypeScript implementation of the Callcium policy engine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"abi",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"typedoc": "typedoc"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@noble/hashes": "
|
|
49
|
+
"@noble/hashes": "2.3.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@vitest/coverage-v8": "4.1.5",
|
|
@@ -57,5 +57,8 @@
|
|
|
57
57
|
"typedoc": "0.28.19",
|
|
58
58
|
"typescript": "6.0.3",
|
|
59
59
|
"vitest": "4.1.5"
|
|
60
|
+
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=22.11.0"
|
|
60
63
|
}
|
|
61
64
|
}
|
package/src/policy-coder.ts
CHANGED
package/src/signature.ts
CHANGED