@volr/sdk-core 0.1.0 → 0.1.2
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 +238 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# @volr/sdk-core
|
|
2
|
+
|
|
3
|
+
Core cryptography, wallet providers, and EVM utilities for Volr SDK.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @volr/sdk-core
|
|
9
|
+
# or
|
|
10
|
+
yarn add @volr/sdk-core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **EVM Cryptography**: secp256k1 and P-256 (WebAuthn) signing
|
|
16
|
+
- **Passkey Providers**: WebAuthn-based wallet providers
|
|
17
|
+
- **Master Key Encryption**: AES-256-GCM encryption with HKDF key derivation
|
|
18
|
+
- **EIP-7702 Support**: Authorization tuple signing
|
|
19
|
+
- **Session Keys**: EIP-712 session authentication
|
|
20
|
+
- **Type-Safe**: Full TypeScript support with strict types
|
|
21
|
+
|
|
22
|
+
## Core Concepts
|
|
23
|
+
|
|
24
|
+
### Wallet Providers
|
|
25
|
+
|
|
26
|
+
Wallet providers implement the `WalletProviderPort` interface for signing transactions:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { createPasskeyProvider } from '@volr/sdk-core';
|
|
30
|
+
|
|
31
|
+
// Create a passkey-based provider
|
|
32
|
+
const provider = createPasskeyProvider(adapter, {
|
|
33
|
+
prfInput: { origin, projectId, credentialId },
|
|
34
|
+
encryptedBlob: { cipher, nonce },
|
|
35
|
+
aad: new TextEncoder().encode('volr/master-seed/v1|userId|passkey|v1'),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Get EVM address
|
|
39
|
+
const address = await provider.getAddress();
|
|
40
|
+
|
|
41
|
+
// Sign message
|
|
42
|
+
const signature = await provider.signMessage(messageHash);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Signers
|
|
46
|
+
|
|
47
|
+
Signers are lightweight interfaces for signing operations:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { createSecp256k1Signer } from '@volr/sdk-core';
|
|
51
|
+
|
|
52
|
+
// Create signer from private key
|
|
53
|
+
const signer = createSecp256k1Signer(privateKeyBytes);
|
|
54
|
+
|
|
55
|
+
// Sign message
|
|
56
|
+
const signature = await signer.signMessage(messageHash);
|
|
57
|
+
|
|
58
|
+
// Get address
|
|
59
|
+
const address = await signer.getAddress();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### EIP-7702 Authorization
|
|
63
|
+
|
|
64
|
+
Sign authorization tuples for EIP-7702 transactions:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { signAuthorization } from '@volr/sdk-core';
|
|
68
|
+
|
|
69
|
+
const authTuple = await signAuthorization({
|
|
70
|
+
signer,
|
|
71
|
+
chainId: 8453,
|
|
72
|
+
address: invokerAddress,
|
|
73
|
+
nonce: 0n,
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Session Signing (EIP-712)
|
|
78
|
+
|
|
79
|
+
Sign session authentication for sponsored transactions:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { signSession } from '@volr/sdk-core';
|
|
83
|
+
|
|
84
|
+
const { sessionSig } = await signSession({
|
|
85
|
+
signer,
|
|
86
|
+
from: userAddress,
|
|
87
|
+
auth: {
|
|
88
|
+
chainId: 8453,
|
|
89
|
+
sessionKey: userAddress,
|
|
90
|
+
expiresAt: Math.floor(Date.now() / 1000) + 900,
|
|
91
|
+
nonce: 0n,
|
|
92
|
+
policyId: '0x' + '0'.repeat(64),
|
|
93
|
+
},
|
|
94
|
+
calls: [{ target, data, value, gasLimit }],
|
|
95
|
+
invokerAddress,
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Master Key Encryption
|
|
100
|
+
|
|
101
|
+
Encrypt and decrypt master seeds with AES-256-GCM:
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { encryptMasterSeed, decryptMasterSeed } from '@volr/sdk-core';
|
|
105
|
+
|
|
106
|
+
// Encrypt
|
|
107
|
+
const { cipher, nonce } = await encryptMasterSeed({
|
|
108
|
+
masterSeed: new Uint8Array(32),
|
|
109
|
+
wrapKey: new Uint8Array(32),
|
|
110
|
+
aad: new TextEncoder().encode('context'),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Decrypt
|
|
114
|
+
const masterSeed = await decryptMasterSeed({
|
|
115
|
+
cipher,
|
|
116
|
+
nonce,
|
|
117
|
+
wrapKey,
|
|
118
|
+
aad,
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Key Derivation (HKDF)
|
|
123
|
+
|
|
124
|
+
Derive keys using HMAC-based Key Derivation Function:
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { hkdf } from '@volr/sdk-core';
|
|
128
|
+
|
|
129
|
+
const derivedKey = await hkdf({
|
|
130
|
+
ikm: inputKeyMaterial,
|
|
131
|
+
salt: new Uint8Array(32),
|
|
132
|
+
info: new TextEncoder().encode('context'),
|
|
133
|
+
length: 32,
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## API Reference
|
|
138
|
+
|
|
139
|
+
### Types
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
// Wallet provider interface
|
|
143
|
+
interface WalletProviderPort {
|
|
144
|
+
getAddress(): Promise<`0x${string}`>;
|
|
145
|
+
signMessage(messageHash: Uint8Array): Promise<Uint8Array>;
|
|
146
|
+
lock?(): Promise<void>;
|
|
147
|
+
ensureSession?(opts?: { interactive?: boolean; force?: boolean }): Promise<void>;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Signer interface
|
|
151
|
+
interface SignerPort {
|
|
152
|
+
getAddress(): Promise<`0x${string}`>;
|
|
153
|
+
signMessage(messageHash: Uint8Array): Promise<Uint8Array>;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// EIP-7702 authorization tuple
|
|
157
|
+
interface AuthorizationTuple {
|
|
158
|
+
chainId: bigint;
|
|
159
|
+
address: `0x${string}`;
|
|
160
|
+
nonce: bigint;
|
|
161
|
+
v: bigint;
|
|
162
|
+
r: `0x${string}`;
|
|
163
|
+
s: `0x${string}`;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Session authentication
|
|
167
|
+
interface SessionAuth {
|
|
168
|
+
chainId: number;
|
|
169
|
+
sessionKey: `0x${string}`;
|
|
170
|
+
expiresAt: number;
|
|
171
|
+
nonce: bigint;
|
|
172
|
+
policyId: `0x${string}`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Call structure
|
|
176
|
+
interface Call {
|
|
177
|
+
target: `0x${string}`;
|
|
178
|
+
data: `0x${string}`;
|
|
179
|
+
value: bigint;
|
|
180
|
+
gasLimit: bigint;
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Cryptography
|
|
185
|
+
|
|
186
|
+
- `encryptMasterSeed()`: Encrypt master seed with AES-256-GCM
|
|
187
|
+
- `decryptMasterSeed()`: Decrypt master seed
|
|
188
|
+
- `hkdf()`: HMAC-based key derivation
|
|
189
|
+
- `zeroize()`: Securely zero out sensitive data
|
|
190
|
+
|
|
191
|
+
### Signers
|
|
192
|
+
|
|
193
|
+
- `createSecp256k1Signer()`: Create secp256k1 signer
|
|
194
|
+
- `createPasskeyP256Signer()`: Create P-256 passkey signer
|
|
195
|
+
- `createExternalWalletSigner()`: Create external wallet signer (MetaMask, etc.)
|
|
196
|
+
|
|
197
|
+
### Providers
|
|
198
|
+
|
|
199
|
+
- `createPasskeyProvider()`: Create passkey-based wallet provider
|
|
200
|
+
- `createMpcProvider()`: Create MPC-based wallet provider
|
|
201
|
+
|
|
202
|
+
### EVM Utilities
|
|
203
|
+
|
|
204
|
+
- `signAuthorization()`: Sign EIP-7702 authorization tuple
|
|
205
|
+
- `signSession()`: Sign EIP-712 session authentication
|
|
206
|
+
- `getAuthNonce()`: Get authorization nonce from RPC
|
|
207
|
+
|
|
208
|
+
## Security
|
|
209
|
+
|
|
210
|
+
### Key Management
|
|
211
|
+
|
|
212
|
+
- Master seeds are encrypted with AES-256-GCM
|
|
213
|
+
- Wrap keys are derived from passkey PRF
|
|
214
|
+
- Private keys are zeroized after use
|
|
215
|
+
- No keys are stored in plain text
|
|
216
|
+
|
|
217
|
+
### Session Security
|
|
218
|
+
|
|
219
|
+
- Sessions expire after configurable TTL (default: 15 minutes)
|
|
220
|
+
- Each transaction requires fresh signature
|
|
221
|
+
- Policy constraints enforced on-chain
|
|
222
|
+
- Nonce prevents replay attacks
|
|
223
|
+
|
|
224
|
+
## Testing
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
# Run tests
|
|
228
|
+
yarn test
|
|
229
|
+
|
|
230
|
+
# Run tests with coverage
|
|
231
|
+
yarn test:coverage
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## License
|
|
235
|
+
|
|
236
|
+
MIT
|
|
237
|
+
|
|
238
|
+
|