@sip-protocol/sdk 0.3.2 → 0.5.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/dist/browser.d.mts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +2881 -295
- package/dist/browser.mjs +62 -2
- package/dist/chunk-AOZIY3GU.mjs +12995 -0
- package/dist/chunk-BCLIX5T2.mjs +12940 -0
- package/dist/chunk-DMHBKRWV.mjs +14712 -0
- package/dist/chunk-FKXPHKYD.mjs +12955 -0
- package/dist/chunk-HGU6HZRC.mjs +231 -0
- package/dist/chunk-J4Q4NJ2U.mjs +13544 -0
- package/dist/chunk-OPQ2GQIO.mjs +13013 -0
- package/dist/chunk-W2B7T6WU.mjs +14714 -0
- package/dist/index-5jAdWMA-.d.ts +8973 -0
- package/dist/index-B9Vkpaao.d.mts +8973 -0
- package/dist/index-BcWNakUD.d.ts +7990 -0
- package/dist/index-BsKY3Hr0.d.mts +7990 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2852 -266
- package/dist/index.mjs +62 -2
- package/dist/proofs/noir.mjs +1 -1
- package/package.json +2 -1
- package/src/adapters/near-intents.ts +8 -0
- package/src/bitcoin/index.ts +51 -0
- package/src/bitcoin/silent-payments.ts +865 -0
- package/src/bitcoin/taproot.ts +590 -0
- package/src/compliance/compliance-manager.ts +87 -0
- package/src/compliance/conditional-threshold.ts +379 -0
- package/src/compliance/conditional.ts +382 -0
- package/src/compliance/derivation.ts +489 -0
- package/src/compliance/index.ts +50 -8
- package/src/compliance/pdf.ts +365 -0
- package/src/compliance/reports.ts +644 -0
- package/src/compliance/threshold.ts +529 -0
- package/src/compliance/types.ts +223 -0
- package/src/cosmos/ibc-stealth.ts +825 -0
- package/src/cosmos/index.ts +83 -0
- package/src/cosmos/stealth.ts +487 -0
- package/src/errors.ts +8 -0
- package/src/index.ts +80 -1
- package/src/move/aptos.ts +369 -0
- package/src/move/index.ts +35 -0
- package/src/move/sui.ts +367 -0
- package/src/oracle/types.ts +8 -0
- package/src/settlement/backends/direct-chain.ts +8 -0
- package/src/stealth.ts +3 -3
- package/src/validation.ts +42 -1
- package/src/wallet/aptos/adapter.ts +422 -0
- package/src/wallet/aptos/index.ts +10 -0
- package/src/wallet/aptos/mock.ts +410 -0
- package/src/wallet/aptos/types.ts +278 -0
- package/src/wallet/bitcoin/adapter.ts +470 -0
- package/src/wallet/bitcoin/index.ts +38 -0
- package/src/wallet/bitcoin/mock.ts +516 -0
- package/src/wallet/bitcoin/types.ts +274 -0
- package/src/wallet/cosmos/adapter.ts +484 -0
- package/src/wallet/cosmos/index.ts +63 -0
- package/src/wallet/cosmos/mock.ts +596 -0
- package/src/wallet/cosmos/types.ts +462 -0
- package/src/wallet/index.ts +127 -0
- package/src/wallet/sui/adapter.ts +471 -0
- package/src/wallet/sui/index.ts +10 -0
- package/src/wallet/sui/mock.ts +439 -0
- package/src/wallet/sui/types.ts +245 -0
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auditor Key Derivation for SIP Protocol
|
|
3
|
+
*
|
|
4
|
+
* Provides standardized BIP-44 style hierarchical key derivation
|
|
5
|
+
* for different auditor types, enabling secure and isolated viewing
|
|
6
|
+
* keys for regulatory, internal, and tax auditors.
|
|
7
|
+
*
|
|
8
|
+
* ## Derivation Path Format
|
|
9
|
+
*
|
|
10
|
+
* m/44'/COIN_TYPE'/account'/auditor_type
|
|
11
|
+
*
|
|
12
|
+
* Where:
|
|
13
|
+
* - 44' = BIP-44 standard (hardened)
|
|
14
|
+
* - COIN_TYPE' = 1234 (SIP Protocol registered coin type, hardened)
|
|
15
|
+
* - account' = Account index (default: 0, hardened)
|
|
16
|
+
* - auditor_type = Auditor type index (non-hardened)
|
|
17
|
+
*
|
|
18
|
+
* ## Auditor Types
|
|
19
|
+
*
|
|
20
|
+
* - 0 = PRIMARY - Primary viewing key for organization
|
|
21
|
+
* - 1 = REGULATORY - Regulatory auditor key (SEC, FINRA, etc.)
|
|
22
|
+
* - 2 = INTERNAL - Internal audit key (company auditors)
|
|
23
|
+
* - 3 = TAX - Tax authority key (IRS, local tax agencies)
|
|
24
|
+
*
|
|
25
|
+
* ## Security Properties
|
|
26
|
+
*
|
|
27
|
+
* - Uses HMAC-SHA512 for key derivation (BIP-32 standard)
|
|
28
|
+
* - Hardened derivation for coin type and account (prevents parent key recovery)
|
|
29
|
+
* - Non-hardened derivation for auditor type (allows extended public keys)
|
|
30
|
+
* - Keys are cryptographically isolated (no correlation between types)
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { AuditorKeyDerivation, AuditorType } from '@sip-protocol/sdk'
|
|
35
|
+
*
|
|
36
|
+
* // Generate master seed (32 bytes)
|
|
37
|
+
* const masterSeed = randomBytes(32)
|
|
38
|
+
*
|
|
39
|
+
* // Derive regulatory auditor key
|
|
40
|
+
* const regulatoryKey = AuditorKeyDerivation.deriveViewingKey({
|
|
41
|
+
* masterSeed,
|
|
42
|
+
* auditorType: AuditorType.REGULATORY,
|
|
43
|
+
* })
|
|
44
|
+
* // Path: m/44'/1234'/0'/1
|
|
45
|
+
*
|
|
46
|
+
* // Derive tax authority key
|
|
47
|
+
* const taxKey = AuditorKeyDerivation.deriveViewingKey({
|
|
48
|
+
* masterSeed,
|
|
49
|
+
* auditorType: AuditorType.TAX,
|
|
50
|
+
* account: 1, // Different account
|
|
51
|
+
* })
|
|
52
|
+
* // Path: m/44'/1234'/1'/3
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
import type { ViewingKey, HexString, Hash } from '@sip-protocol/types'
|
|
57
|
+
import { sha256 } from '@noble/hashes/sha256'
|
|
58
|
+
import { sha512 } from '@noble/hashes/sha512'
|
|
59
|
+
import { hmac } from '@noble/hashes/hmac'
|
|
60
|
+
import { bytesToHex, hexToBytes, utf8ToBytes } from '@noble/hashes/utils'
|
|
61
|
+
import { ValidationError, ErrorCode } from '../errors'
|
|
62
|
+
import { secureWipe } from '../secure-memory'
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Auditor type enumeration
|
|
66
|
+
*
|
|
67
|
+
* Defines the standard auditor types for key derivation.
|
|
68
|
+
*/
|
|
69
|
+
export enum AuditorType {
|
|
70
|
+
/** Primary viewing key for organization */
|
|
71
|
+
PRIMARY = 0,
|
|
72
|
+
/** Regulatory auditor key (SEC, FINRA, etc.) */
|
|
73
|
+
REGULATORY = 1,
|
|
74
|
+
/** Internal audit key (company auditors) */
|
|
75
|
+
INTERNAL = 2,
|
|
76
|
+
/** Tax authority key (IRS, local tax agencies) */
|
|
77
|
+
TAX = 3,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Derived viewing key with metadata
|
|
82
|
+
*/
|
|
83
|
+
export interface DerivedViewingKey {
|
|
84
|
+
/** BIP-44 style derivation path */
|
|
85
|
+
path: string
|
|
86
|
+
/** The derived viewing key (hex encoded) */
|
|
87
|
+
viewingKey: ViewingKey
|
|
88
|
+
/** Auditor type this key is for */
|
|
89
|
+
auditorType: AuditorType
|
|
90
|
+
/** Account index used in derivation */
|
|
91
|
+
account: number
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Parameters for deriving a viewing key
|
|
96
|
+
*/
|
|
97
|
+
export interface DeriveViewingKeyParams {
|
|
98
|
+
/** Master seed (32 bytes minimum) */
|
|
99
|
+
masterSeed: Uint8Array
|
|
100
|
+
/** Type of auditor key to derive */
|
|
101
|
+
auditorType: AuditorType
|
|
102
|
+
/** Account index (default: 0, hardened) */
|
|
103
|
+
account?: number
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Parameters for deriving multiple viewing keys
|
|
108
|
+
*/
|
|
109
|
+
export interface DeriveMultipleParams {
|
|
110
|
+
/** Master seed (32 bytes minimum) */
|
|
111
|
+
masterSeed: Uint8Array
|
|
112
|
+
/** Auditor types to derive keys for */
|
|
113
|
+
auditorTypes: AuditorType[]
|
|
114
|
+
/** Account index (default: 0, hardened) */
|
|
115
|
+
account?: number
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Auditor Key Derivation
|
|
120
|
+
*
|
|
121
|
+
* Provides BIP-44 style hierarchical key derivation for auditor viewing keys.
|
|
122
|
+
*/
|
|
123
|
+
export class AuditorKeyDerivation {
|
|
124
|
+
/**
|
|
125
|
+
* SIP Protocol coin type (BIP-44 registered)
|
|
126
|
+
*
|
|
127
|
+
* Note: This is a placeholder. In production, register with SLIP-44:
|
|
128
|
+
* https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
|
129
|
+
*/
|
|
130
|
+
static readonly COIN_TYPE = 1234
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* BIP-44 purpose field
|
|
134
|
+
*/
|
|
135
|
+
static readonly PURPOSE = 44
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Hardened derivation flag (2^31)
|
|
139
|
+
*/
|
|
140
|
+
private static readonly HARDENED = 0x80000000
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Generate BIP-44 derivation path
|
|
144
|
+
*
|
|
145
|
+
* @param auditorType - Type of auditor key
|
|
146
|
+
* @param account - Account index (default: 0)
|
|
147
|
+
* @returns BIP-44 style path string
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* AuditorKeyDerivation.derivePath(AuditorType.REGULATORY)
|
|
152
|
+
* // Returns: "m/44'/1234'/0'/1"
|
|
153
|
+
*
|
|
154
|
+
* AuditorKeyDerivation.derivePath(AuditorType.TAX, 5)
|
|
155
|
+
* // Returns: "m/44'/1234'/5'/3"
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
static derivePath(auditorType: AuditorType, account: number = 0): string {
|
|
159
|
+
this.validateAuditorType(auditorType)
|
|
160
|
+
this.validateAccount(account)
|
|
161
|
+
|
|
162
|
+
// m/44'/1234'/account'/auditorType
|
|
163
|
+
return `m/${this.PURPOSE}'/${this.COIN_TYPE}'/${account}'/${auditorType}`
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Derive a viewing key for an auditor
|
|
168
|
+
*
|
|
169
|
+
* Uses BIP-32 style hierarchical deterministic key derivation:
|
|
170
|
+
* 1. Derive master key from seed
|
|
171
|
+
* 2. Harden purpose (44')
|
|
172
|
+
* 3. Harden coin type (1234')
|
|
173
|
+
* 4. Harden account index
|
|
174
|
+
* 5. Derive auditor type (non-hardened)
|
|
175
|
+
*
|
|
176
|
+
* @param params - Derivation parameters
|
|
177
|
+
* @returns Derived viewing key with metadata
|
|
178
|
+
*
|
|
179
|
+
* @throws {ValidationError} If parameters are invalid
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const regulatoryKey = AuditorKeyDerivation.deriveViewingKey({
|
|
184
|
+
* masterSeed: randomBytes(32),
|
|
185
|
+
* auditorType: AuditorType.REGULATORY,
|
|
186
|
+
* })
|
|
187
|
+
*
|
|
188
|
+
* console.log(regulatoryKey.path) // "m/44'/1234'/0'/1"
|
|
189
|
+
* console.log(regulatoryKey.viewingKey.key) // "0x..."
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
static deriveViewingKey(params: DeriveViewingKeyParams): DerivedViewingKey {
|
|
193
|
+
const { masterSeed, auditorType, account = 0 } = params
|
|
194
|
+
|
|
195
|
+
// Validate inputs
|
|
196
|
+
this.validateMasterSeed(masterSeed)
|
|
197
|
+
this.validateAuditorType(auditorType)
|
|
198
|
+
this.validateAccount(account)
|
|
199
|
+
|
|
200
|
+
const path = this.derivePath(auditorType, account)
|
|
201
|
+
|
|
202
|
+
// BIP-32 derivation path indices
|
|
203
|
+
const indices = [
|
|
204
|
+
this.PURPOSE | this.HARDENED, // 44' (hardened)
|
|
205
|
+
this.COIN_TYPE | this.HARDENED, // 1234' (hardened)
|
|
206
|
+
account | this.HARDENED, // account' (hardened)
|
|
207
|
+
auditorType, // auditorType (non-hardened)
|
|
208
|
+
]
|
|
209
|
+
|
|
210
|
+
// Derive key through the path - Initialize master key and chain code from seed
|
|
211
|
+
const masterData = hmac(sha512, utf8ToBytes('SIP-MASTER-SEED'), masterSeed)
|
|
212
|
+
let currentKey: Uint8Array = new Uint8Array(masterData.slice(0, 32))
|
|
213
|
+
let chainCode: Uint8Array = new Uint8Array(masterData.slice(32, 64))
|
|
214
|
+
|
|
215
|
+
try {
|
|
216
|
+
|
|
217
|
+
// Derive through each level
|
|
218
|
+
for (let i = 0; i < indices.length; i++) {
|
|
219
|
+
const index = indices[i]
|
|
220
|
+
const derived = this.deriveChildKey(currentKey, chainCode, index)
|
|
221
|
+
|
|
222
|
+
// Wipe previous key data
|
|
223
|
+
if (i > 0) {
|
|
224
|
+
secureWipe(currentKey)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
currentKey = new Uint8Array(derived.key)
|
|
228
|
+
chainCode = new Uint8Array(derived.chainCode)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Convert to hex
|
|
232
|
+
const keyHex = `0x${bytesToHex(currentKey)}` as HexString
|
|
233
|
+
|
|
234
|
+
// Compute hash
|
|
235
|
+
const hashBytes = sha256(currentKey)
|
|
236
|
+
const hash = `0x${bytesToHex(hashBytes)}` as Hash
|
|
237
|
+
|
|
238
|
+
const viewingKey: ViewingKey = {
|
|
239
|
+
key: keyHex,
|
|
240
|
+
path,
|
|
241
|
+
hash,
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
path,
|
|
246
|
+
viewingKey,
|
|
247
|
+
auditorType,
|
|
248
|
+
account,
|
|
249
|
+
}
|
|
250
|
+
} finally {
|
|
251
|
+
// Securely wipe sensitive data
|
|
252
|
+
secureWipe(currentKey)
|
|
253
|
+
secureWipe(chainCode)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Derive multiple viewing keys at once
|
|
259
|
+
*
|
|
260
|
+
* Efficiently derives keys for multiple auditor types from the same
|
|
261
|
+
* master seed. This is more efficient than calling deriveViewingKey
|
|
262
|
+
* multiple times as it reuses intermediate derivations.
|
|
263
|
+
*
|
|
264
|
+
* @param params - Derivation parameters
|
|
265
|
+
* @returns Array of derived viewing keys
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* const keys = AuditorKeyDerivation.deriveMultiple({
|
|
270
|
+
* masterSeed: randomBytes(32),
|
|
271
|
+
* auditorTypes: [
|
|
272
|
+
* AuditorType.PRIMARY,
|
|
273
|
+
* AuditorType.REGULATORY,
|
|
274
|
+
* AuditorType.INTERNAL,
|
|
275
|
+
* ],
|
|
276
|
+
* })
|
|
277
|
+
*
|
|
278
|
+
* // keys[0] -> PRIMARY key (m/44'/1234'/0'/0)
|
|
279
|
+
* // keys[1] -> REGULATORY key (m/44'/1234'/0'/1)
|
|
280
|
+
* // keys[2] -> INTERNAL key (m/44'/1234'/0'/2)
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
static deriveMultiple(params: DeriveMultipleParams): DerivedViewingKey[] {
|
|
284
|
+
const { masterSeed, auditorTypes, account = 0 } = params
|
|
285
|
+
|
|
286
|
+
// Validate inputs
|
|
287
|
+
this.validateMasterSeed(masterSeed)
|
|
288
|
+
this.validateAccount(account)
|
|
289
|
+
|
|
290
|
+
if (!auditorTypes || auditorTypes.length === 0) {
|
|
291
|
+
throw new ValidationError(
|
|
292
|
+
'at least one auditor type is required',
|
|
293
|
+
'auditorTypes',
|
|
294
|
+
{ received: auditorTypes },
|
|
295
|
+
ErrorCode.MISSING_REQUIRED
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Validate all auditor types
|
|
300
|
+
for (const type of auditorTypes) {
|
|
301
|
+
this.validateAuditorType(type)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Remove duplicates
|
|
305
|
+
const uniqueTypes = Array.from(new Set(auditorTypes))
|
|
306
|
+
|
|
307
|
+
// Derive common path up to account level
|
|
308
|
+
const commonIndices = [
|
|
309
|
+
this.PURPOSE | this.HARDENED, // 44' (hardened)
|
|
310
|
+
this.COIN_TYPE | this.HARDENED, // 1234' (hardened)
|
|
311
|
+
account | this.HARDENED, // account' (hardened)
|
|
312
|
+
]
|
|
313
|
+
|
|
314
|
+
// Initialize master key and chain code
|
|
315
|
+
const masterData = hmac(sha512, utf8ToBytes('SIP-MASTER-SEED'), masterSeed)
|
|
316
|
+
let commonKey = new Uint8Array(masterData.slice(0, 32))
|
|
317
|
+
let commonChainCode = new Uint8Array(masterData.slice(32, 64))
|
|
318
|
+
|
|
319
|
+
try {
|
|
320
|
+
|
|
321
|
+
// Derive to account level
|
|
322
|
+
for (let i = 0; i < commonIndices.length; i++) {
|
|
323
|
+
const index = commonIndices[i]
|
|
324
|
+
const derived = this.deriveChildKey(commonKey, commonChainCode, index)
|
|
325
|
+
|
|
326
|
+
if (i > 0) {
|
|
327
|
+
secureWipe(commonKey)
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
commonKey = new Uint8Array(derived.key)
|
|
331
|
+
commonChainCode = new Uint8Array(derived.chainCode)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Derive each auditor type from common account key
|
|
335
|
+
const results: DerivedViewingKey[] = []
|
|
336
|
+
|
|
337
|
+
for (const auditorType of uniqueTypes) {
|
|
338
|
+
const derived = this.deriveChildKey(commonKey, commonChainCode, auditorType)
|
|
339
|
+
|
|
340
|
+
try {
|
|
341
|
+
const keyHex = `0x${bytesToHex(derived.key)}` as HexString
|
|
342
|
+
const hashBytes = sha256(derived.key)
|
|
343
|
+
const hash = `0x${bytesToHex(hashBytes)}` as Hash
|
|
344
|
+
const path = this.derivePath(auditorType, account)
|
|
345
|
+
|
|
346
|
+
const viewingKey: ViewingKey = {
|
|
347
|
+
key: keyHex,
|
|
348
|
+
path,
|
|
349
|
+
hash,
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
results.push({
|
|
353
|
+
path,
|
|
354
|
+
viewingKey,
|
|
355
|
+
auditorType,
|
|
356
|
+
account,
|
|
357
|
+
})
|
|
358
|
+
} finally {
|
|
359
|
+
secureWipe(derived.key)
|
|
360
|
+
secureWipe(derived.chainCode)
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return results
|
|
365
|
+
} finally {
|
|
366
|
+
secureWipe(commonKey)
|
|
367
|
+
secureWipe(commonChainCode)
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Get human-readable name for auditor type
|
|
373
|
+
*
|
|
374
|
+
* @param auditorType - Auditor type enum value
|
|
375
|
+
* @returns Friendly name string
|
|
376
|
+
*/
|
|
377
|
+
static getAuditorTypeName(auditorType: AuditorType): string {
|
|
378
|
+
switch (auditorType) {
|
|
379
|
+
case AuditorType.PRIMARY:
|
|
380
|
+
return 'Primary'
|
|
381
|
+
case AuditorType.REGULATORY:
|
|
382
|
+
return 'Regulatory'
|
|
383
|
+
case AuditorType.INTERNAL:
|
|
384
|
+
return 'Internal'
|
|
385
|
+
case AuditorType.TAX:
|
|
386
|
+
return 'Tax Authority'
|
|
387
|
+
default:
|
|
388
|
+
return `Unknown (${auditorType})`
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// ─── Private Helpers ─────────────────────────────────────────────────────────
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Derive a child key using BIP-32 HMAC-SHA512 derivation
|
|
396
|
+
*
|
|
397
|
+
* @param parentKey - Parent key bytes (32 bytes)
|
|
398
|
+
* @param chainCode - Parent chain code (32 bytes)
|
|
399
|
+
* @param index - Child index (use | HARDENED for hardened derivation)
|
|
400
|
+
* @returns Derived key and chain code
|
|
401
|
+
*/
|
|
402
|
+
private static deriveChildKey(
|
|
403
|
+
parentKey: Uint8Array,
|
|
404
|
+
chainCode: Uint8Array,
|
|
405
|
+
index: number,
|
|
406
|
+
): { key: Uint8Array; chainCode: Uint8Array } {
|
|
407
|
+
const isHardened = (index & this.HARDENED) !== 0
|
|
408
|
+
|
|
409
|
+
// Build HMAC input data
|
|
410
|
+
const data = new Uint8Array(37) // 1 byte prefix + 32 bytes key + 4 bytes index
|
|
411
|
+
|
|
412
|
+
if (isHardened) {
|
|
413
|
+
// Hardened: 0x00 || parentKey || index
|
|
414
|
+
data[0] = 0x00
|
|
415
|
+
data.set(parentKey, 1)
|
|
416
|
+
} else {
|
|
417
|
+
// Non-hardened: 0x01 || parentKey || index
|
|
418
|
+
// Note: In full BIP-32, this would use the public key
|
|
419
|
+
// For viewing keys, we use the private key directly
|
|
420
|
+
data[0] = 0x01
|
|
421
|
+
data.set(parentKey, 1)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// Write index as big-endian uint32
|
|
425
|
+
const indexView = new DataView(data.buffer, 33, 4)
|
|
426
|
+
indexView.setUint32(0, index, false) // false = big-endian
|
|
427
|
+
|
|
428
|
+
// HMAC-SHA512(chainCode, data)
|
|
429
|
+
const hmacResult = hmac(sha512, chainCode, data)
|
|
430
|
+
|
|
431
|
+
// Split result: first 32 bytes = child key, last 32 bytes = child chain code
|
|
432
|
+
const childKey = new Uint8Array(hmacResult.slice(0, 32))
|
|
433
|
+
const childChainCode = new Uint8Array(hmacResult.slice(32, 64))
|
|
434
|
+
|
|
435
|
+
return {
|
|
436
|
+
key: childKey,
|
|
437
|
+
chainCode: childChainCode,
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Validate master seed
|
|
443
|
+
*/
|
|
444
|
+
private static validateMasterSeed(seed: Uint8Array): void {
|
|
445
|
+
if (!seed || seed.length < 32) {
|
|
446
|
+
throw new ValidationError(
|
|
447
|
+
'master seed must be at least 32 bytes',
|
|
448
|
+
'masterSeed',
|
|
449
|
+
{ received: seed?.length ?? 0 },
|
|
450
|
+
ErrorCode.INVALID_INPUT
|
|
451
|
+
)
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Validate auditor type
|
|
457
|
+
*/
|
|
458
|
+
private static validateAuditorType(type: AuditorType): void {
|
|
459
|
+
const validTypes = [
|
|
460
|
+
AuditorType.PRIMARY,
|
|
461
|
+
AuditorType.REGULATORY,
|
|
462
|
+
AuditorType.INTERNAL,
|
|
463
|
+
AuditorType.TAX,
|
|
464
|
+
]
|
|
465
|
+
|
|
466
|
+
if (!validTypes.includes(type)) {
|
|
467
|
+
throw new ValidationError(
|
|
468
|
+
`invalid auditor type: ${type}`,
|
|
469
|
+
'auditorType',
|
|
470
|
+
{ received: type, valid: validTypes },
|
|
471
|
+
ErrorCode.INVALID_INPUT
|
|
472
|
+
)
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Validate account index
|
|
478
|
+
*/
|
|
479
|
+
private static validateAccount(account: number): void {
|
|
480
|
+
if (!Number.isInteger(account) || account < 0 || account >= this.HARDENED) {
|
|
481
|
+
throw new ValidationError(
|
|
482
|
+
`account must be a non-negative integer less than ${this.HARDENED}`,
|
|
483
|
+
'account',
|
|
484
|
+
{ received: account },
|
|
485
|
+
ErrorCode.INVALID_INPUT
|
|
486
|
+
)
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
package/src/compliance/index.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import { ComplianceManager } from '@sip-protocol/sdk'
|
|
9
|
+
* import { ComplianceManager, ComplianceReporter } from '@sip-protocol/sdk'
|
|
10
10
|
*
|
|
11
11
|
* // Create compliance manager
|
|
12
12
|
* const compliance = await ComplianceManager.create({
|
|
@@ -27,17 +27,59 @@
|
|
|
27
27
|
* },
|
|
28
28
|
* }, adminAddress)
|
|
29
29
|
*
|
|
30
|
-
* // Generate
|
|
31
|
-
* const
|
|
32
|
-
*
|
|
33
|
-
*
|
|
30
|
+
* // Generate audit report using ComplianceReporter
|
|
31
|
+
* const reporter = new ComplianceReporter()
|
|
32
|
+
* const report = await reporter.generateAuditReport({
|
|
33
|
+
* viewingKey: myViewingKey,
|
|
34
|
+
* transactions: encryptedTransactions,
|
|
35
|
+
* startDate: new Date('2025-01-01'),
|
|
36
|
+
* endDate: new Date('2025-12-31'),
|
|
34
37
|
* format: 'json',
|
|
35
|
-
*
|
|
36
|
-
* endDate: quarterEnd,
|
|
37
|
-
* }, requesterAddress)
|
|
38
|
+
* })
|
|
38
39
|
* ```
|
|
39
40
|
*
|
|
40
41
|
* @module compliance
|
|
41
42
|
*/
|
|
42
43
|
|
|
43
44
|
export { ComplianceManager } from './compliance-manager'
|
|
45
|
+
export { ComplianceReporter } from './reports'
|
|
46
|
+
export { generatePdfReport } from './pdf'
|
|
47
|
+
export type {
|
|
48
|
+
GenerateAuditReportParams,
|
|
49
|
+
AuditReport,
|
|
50
|
+
DecryptedTransaction,
|
|
51
|
+
PdfExportOptions,
|
|
52
|
+
ExportForRegulatorParams,
|
|
53
|
+
RegulatoryExport,
|
|
54
|
+
RegulatoryFormat,
|
|
55
|
+
Jurisdiction,
|
|
56
|
+
FATFExport,
|
|
57
|
+
FATFTransaction,
|
|
58
|
+
FINCENExport,
|
|
59
|
+
FINCENTransaction,
|
|
60
|
+
CSVExport,
|
|
61
|
+
} from './types'
|
|
62
|
+
export type { ComplianceMetrics } from '@sip-protocol/types'
|
|
63
|
+
export {
|
|
64
|
+
ConditionalDisclosure,
|
|
65
|
+
type TimeLockResult,
|
|
66
|
+
type UnlockResult,
|
|
67
|
+
type TimeLockParams,
|
|
68
|
+
} from './conditional'
|
|
69
|
+
export {
|
|
70
|
+
createAmountThreshold,
|
|
71
|
+
proveExceedsThreshold,
|
|
72
|
+
verifyThresholdProof,
|
|
73
|
+
shouldDisclose,
|
|
74
|
+
type ThresholdDisclosure,
|
|
75
|
+
type RangeProof,
|
|
76
|
+
type CreateAmountThresholdParams,
|
|
77
|
+
} from './conditional-threshold'
|
|
78
|
+
export { ThresholdViewingKey, type ThresholdShares } from './threshold'
|
|
79
|
+
export {
|
|
80
|
+
AuditorKeyDerivation,
|
|
81
|
+
AuditorType,
|
|
82
|
+
type DerivedViewingKey,
|
|
83
|
+
type DeriveViewingKeyParams,
|
|
84
|
+
type DeriveMultipleParams,
|
|
85
|
+
} from './derivation'
|