@sip-protocol/sdk 0.6.0 → 0.6.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.
Files changed (63) hide show
  1. package/README.md +58 -0
  2. package/dist/browser.d.mts +4 -4
  3. package/dist/browser.d.ts +4 -4
  4. package/dist/browser.js +2752 -448
  5. package/dist/browser.mjs +31 -1
  6. package/dist/chunk-7QZPORY5.mjs +15604 -0
  7. package/dist/chunk-C2NPCUAJ.mjs +17010 -0
  8. package/dist/chunk-FCVLFUIC.mjs +16699 -0
  9. package/dist/chunk-G5UHXECN.mjs +16340 -0
  10. package/dist/chunk-GEDEIZHJ.mjs +16798 -0
  11. package/dist/chunk-GOOEOAMV.mjs +17026 -0
  12. package/dist/chunk-MTNYSNR7.mjs +16269 -0
  13. package/dist/chunk-O5PIB2EA.mjs +16698 -0
  14. package/dist/chunk-PCFM7FQO.mjs +17010 -0
  15. package/dist/chunk-QK464ARC.mjs +16946 -0
  16. package/dist/chunk-VNBMNGC3.mjs +16698 -0
  17. package/dist/chunk-W5TUELDQ.mjs +16947 -0
  18. package/dist/index-CD_zShu-.d.ts +10870 -0
  19. package/dist/index-CQBYdLYy.d.mts +10976 -0
  20. package/dist/index-Cg9TYEPv.d.mts +11321 -0
  21. package/dist/index-CqZJOO8C.d.mts +11323 -0
  22. package/dist/index-CywN9Bnp.d.ts +11321 -0
  23. package/dist/index-DHy5ZjCD.d.ts +10976 -0
  24. package/dist/index-DfsVsmxu.d.ts +11323 -0
  25. package/dist/index-ObjwyVDX.d.mts +10870 -0
  26. package/dist/index-m0xbSfmT.d.mts +11318 -0
  27. package/dist/index-rWLEgvhN.d.ts +11318 -0
  28. package/dist/index.d.mts +3 -3
  29. package/dist/index.d.ts +3 -3
  30. package/dist/index.js +2737 -427
  31. package/dist/index.mjs +31 -1
  32. package/dist/noir-DKfEzWy9.d.mts +482 -0
  33. package/dist/noir-DKfEzWy9.d.ts +482 -0
  34. package/dist/proofs/noir.d.mts +1 -1
  35. package/dist/proofs/noir.d.ts +1 -1
  36. package/dist/proofs/noir.js +12 -3
  37. package/dist/proofs/noir.mjs +12 -3
  38. package/package.json +16 -14
  39. package/src/adapters/near-intents.ts +13 -3
  40. package/src/auction/index.ts +20 -0
  41. package/src/auction/sealed-bid.ts +1037 -0
  42. package/src/compliance/derivation.ts +13 -3
  43. package/src/compliance/reports.ts +5 -4
  44. package/src/cosmos/ibc-stealth.ts +2 -2
  45. package/src/cosmos/stealth.ts +2 -2
  46. package/src/governance/index.ts +19 -0
  47. package/src/governance/private-vote.ts +1116 -0
  48. package/src/index.ts +50 -2
  49. package/src/intent.ts +145 -8
  50. package/src/nft/index.ts +27 -0
  51. package/src/nft/private-nft.ts +811 -0
  52. package/src/proofs/browser-utils.ts +1 -7
  53. package/src/proofs/noir.ts +34 -7
  54. package/src/settlement/backends/direct-chain.ts +14 -3
  55. package/src/stealth.ts +31 -13
  56. package/src/types/browser.d.ts +67 -0
  57. package/src/validation.ts +4 -2
  58. package/src/wallet/bitcoin/adapter.ts +159 -15
  59. package/src/wallet/bitcoin/types.ts +340 -15
  60. package/src/wallet/cosmos/mock.ts +16 -12
  61. package/src/wallet/hardware/ledger.ts +82 -12
  62. package/src/wallet/hardware/types.ts +2 -0
  63. package/LICENSE +0 -21
package/src/index.ts CHANGED
@@ -93,8 +93,9 @@ export {
93
93
 
94
94
  export type { StealthCurve } from './stealth'
95
95
 
96
- // Move blockchain stealth addresses (Aptos)
96
+ // Move blockchain stealth addresses (Aptos, Sui)
97
97
  export {
98
+ // Aptos
98
99
  AptosStealthService,
99
100
  generateAptosStealthAddress,
100
101
  deriveAptosStealthPrivateKey,
@@ -102,9 +103,17 @@ export {
102
103
  ed25519PublicKeyToAptosAddress,
103
104
  aptosAddressToAuthKey,
104
105
  isValidAptosAddress,
106
+ // Sui
107
+ SuiStealthService,
108
+ generateSuiStealthAddress,
109
+ deriveSuiStealthPrivateKey,
110
+ checkSuiStealthAddress,
111
+ ed25519PublicKeyToSuiAddress,
112
+ normalizeSuiAddress,
113
+ isValidSuiAddress,
105
114
  } from './move'
106
115
 
107
- export type { AptosStealthResult } from './move'
116
+ export type { AptosStealthResult, SuiStealthResult } from './move'
108
117
 
109
118
  // Cosmos blockchain stealth addresses
110
119
  export {
@@ -297,6 +306,12 @@ export type {
297
306
  CreatePaymentParams,
298
307
  PaymentReceipt,
299
308
  TrackedPayment,
309
+ // NFT types
310
+ PrivateNFTOwnership,
311
+ OwnershipProof,
312
+ CreatePrivateOwnershipParams,
313
+ ProveOwnershipParams,
314
+ OwnershipVerification,
300
315
  } from '@sip-protocol/types'
301
316
 
302
317
  // Payment status enum
@@ -566,6 +581,39 @@ export {
566
581
  type TimeLockParams,
567
582
  } from './compliance'
568
583
 
584
+ // Sealed-Bid Auctions
585
+ export {
586
+ SealedBidAuction,
587
+ createSealedBidAuction,
588
+ } from './auction'
589
+
590
+ export type {
591
+ SealedBid,
592
+ BidReceipt,
593
+ CreateBidParams,
594
+ VerifyBidParams,
595
+ } from './auction'
596
+
597
+ // Governance (Private Voting)
598
+ export {
599
+ PrivateVoting,
600
+ createPrivateVoting,
601
+ } from './governance'
602
+
603
+ export type {
604
+ EncryptedVote,
605
+ RevealedVote,
606
+ CastVoteParams,
607
+ } from './governance'
608
+
609
+ // NFT Module
610
+ export {
611
+ PrivateNFT,
612
+ createPrivateOwnership,
613
+ proveOwnership,
614
+ verifyOwnership,
615
+ } from './nft'
616
+
569
617
  // Wallet Adapters
570
618
  export {
571
619
  BaseWalletAdapter,
package/src/intent.ts CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  type HexString,
19
19
  type Hash,
20
20
  type PrivacyLevel,
21
+ type ChainId,
21
22
  } from '@sip-protocol/types'
22
23
  import { generateStealthAddress, decodeStealthMetaAddress } from './stealth'
23
24
  import {
@@ -84,6 +85,48 @@ export interface CreateIntentOptions {
84
85
  * ```
85
86
  */
86
87
  proofProvider?: ProofProvider
88
+
89
+ /**
90
+ * Signature proving ownership of the sender's address
91
+ *
92
+ * Required for production proof generation. This signature proves
93
+ * the sender controls the address that holds the input funds.
94
+ *
95
+ * Should be a 64-byte ECDSA signature over the address.
96
+ */
97
+ ownershipSignature?: Uint8Array
98
+
99
+ /**
100
+ * Sender's secret key for nullifier derivation
101
+ *
102
+ * Required for production proof generation. Used to derive:
103
+ * - Public key for ECDSA verification in proofs
104
+ * - Nullifier to prevent double-spending
105
+ *
106
+ * Should be a 32-byte secret. Keep this secure!
107
+ */
108
+ senderSecret?: Uint8Array
109
+
110
+ /**
111
+ * Signature authorizing this specific intent
112
+ *
113
+ * Required for production proof generation. This signature proves
114
+ * the sender authorized this intent (signs the intent hash).
115
+ *
116
+ * Should be a 64-byte ECDSA signature over the intent hash.
117
+ */
118
+ authorizationSignature?: Uint8Array
119
+
120
+ /**
121
+ * Allow placeholder signatures for development/testing
122
+ *
123
+ * When true, allows proof generation with empty placeholder signatures.
124
+ * **WARNING**: Never use this in production! Proofs with placeholders
125
+ * are not cryptographically valid.
126
+ *
127
+ * @default false
128
+ */
129
+ allowPlaceholders?: boolean
87
130
  }
88
131
 
89
132
  /**
@@ -137,6 +180,10 @@ export class IntentBuilder {
137
180
  private params: Partial<CreateIntentParams> = {}
138
181
  private senderAddress?: string
139
182
  private proofProvider?: ProofProvider
183
+ private ownershipSignature?: Uint8Array
184
+ private senderSecret?: Uint8Array
185
+ private authorizationSignature?: Uint8Array
186
+ private allowPlaceholders?: boolean
140
187
 
141
188
  /**
142
189
  * Set the input for the intent
@@ -170,7 +217,7 @@ export class IntentBuilder {
170
217
 
171
218
  this.params.input = {
172
219
  asset: {
173
- chain: chain as any,
220
+ chain: chain as ChainId,
174
221
  symbol: token,
175
222
  address: null,
176
223
  decimals: 18, // Default, should be looked up
@@ -214,7 +261,7 @@ export class IntentBuilder {
214
261
 
215
262
  this.params.output = {
216
263
  asset: {
217
- chain: chain as any,
264
+ chain: chain as ChainId,
218
265
  symbol: token,
219
266
  address: null,
220
267
  decimals: 18,
@@ -316,6 +363,55 @@ export class IntentBuilder {
316
363
  return this
317
364
  }
318
365
 
366
+ /**
367
+ * Set the signatures and secret for proof generation
368
+ *
369
+ * Required for production proof generation. Provides the cryptographic
370
+ * materials needed to generate valid ZK proofs.
371
+ *
372
+ * @param signatures - Object containing ownership signature, sender secret, and authorization signature
373
+ * @returns this for chaining
374
+ *
375
+ * @example
376
+ * ```typescript
377
+ * const intent = await builder
378
+ * .input('near', 'NEAR', 100n)
379
+ * .output('zcash', 'ZEC', 95n)
380
+ * .privacy(PrivacyLevel.SHIELDED)
381
+ * .withProvider(noirProvider)
382
+ * .withSignatures({
383
+ * ownershipSignature: await wallet.signMessage(address),
384
+ * senderSecret: wallet.privateKey,
385
+ * authorizationSignature: await wallet.signMessage(intentHash),
386
+ * })
387
+ * .build()
388
+ * ```
389
+ */
390
+ withSignatures(signatures: {
391
+ ownershipSignature: Uint8Array
392
+ senderSecret: Uint8Array
393
+ authorizationSignature: Uint8Array
394
+ }): this {
395
+ this.ownershipSignature = signatures.ownershipSignature
396
+ this.senderSecret = signatures.senderSecret
397
+ this.authorizationSignature = signatures.authorizationSignature
398
+ return this
399
+ }
400
+
401
+ /**
402
+ * Allow placeholder signatures for development/testing
403
+ *
404
+ * **WARNING**: Never use this in production! Proofs with placeholders
405
+ * are not cryptographically valid.
406
+ *
407
+ * @param allow - Whether to allow placeholders (default: true)
408
+ * @returns this for chaining
409
+ */
410
+ withPlaceholders(allow: boolean = true): this {
411
+ this.allowPlaceholders = allow
412
+ return this
413
+ }
414
+
319
415
  /**
320
416
  * Build the shielded intent
321
417
  *
@@ -328,6 +424,10 @@ export class IntentBuilder {
328
424
  return createShieldedIntent(this.params as CreateIntentParams, {
329
425
  senderAddress: this.senderAddress,
330
426
  proofProvider: this.proofProvider,
427
+ ownershipSignature: this.ownershipSignature,
428
+ senderSecret: this.senderSecret,
429
+ authorizationSignature: this.authorizationSignature,
430
+ allowPlaceholders: this.allowPlaceholders,
331
431
  })
332
432
  }
333
433
  }
@@ -359,7 +459,14 @@ export async function createShieldedIntent(
359
459
  validateCreateIntentParams(params)
360
460
 
361
461
  const { input, output, privacy, recipientMetaAddress, viewingKey, ttl = 300 } = params
362
- const { senderAddress, proofProvider } = options ?? {}
462
+ const {
463
+ senderAddress,
464
+ proofProvider,
465
+ ownershipSignature,
466
+ senderSecret,
467
+ authorizationSignature,
468
+ allowPlaceholders = false,
469
+ } = options ?? {}
363
470
 
364
471
  // Get privacy configuration
365
472
  // Compute viewing key hash the same way as generateViewingKey():
@@ -409,12 +516,42 @@ export async function createShieldedIntent(
409
516
  const requiresProofs = privacy !== PrivacyLevelEnum.TRANSPARENT
410
517
 
411
518
  if (requiresProofs && proofProvider && proofProvider.isReady) {
519
+ // Check if signatures are provided or placeholders are allowed
520
+ const hasSignatures = ownershipSignature && senderSecret && authorizationSignature
521
+ const usingPlaceholders = !hasSignatures
522
+
523
+ if (usingPlaceholders && !allowPlaceholders) {
524
+ throw new ValidationError(
525
+ 'Proof generation requires signatures. Provide ownershipSignature, senderSecret, and authorizationSignature in options, or set allowPlaceholders: true for development/testing.',
526
+ 'options',
527
+ {
528
+ missing: [
529
+ !ownershipSignature && 'ownershipSignature',
530
+ !senderSecret && 'senderSecret',
531
+ !authorizationSignature && 'authorizationSignature',
532
+ ].filter(Boolean),
533
+ }
534
+ )
535
+ }
536
+
537
+ if (usingPlaceholders) {
538
+ console.warn(
539
+ '[createShieldedIntent] WARNING: Using placeholder signatures for proof generation. ' +
540
+ 'These proofs are NOT cryptographically valid. Do NOT use in production!'
541
+ )
542
+ }
543
+
412
544
  // Helper to convert HexString to Uint8Array
413
545
  const hexToUint8 = (hex: HexString): Uint8Array => {
414
546
  const cleanHex = hex.startsWith('0x') ? hex.slice(2) : hex
415
547
  return hexToBytes(cleanHex)
416
548
  }
417
549
 
550
+ // Use provided signatures or placeholders (if allowed)
551
+ const effectiveOwnershipSig = ownershipSignature ?? new Uint8Array(64)
552
+ const effectiveSenderSecret = senderSecret ?? new Uint8Array(32)
553
+ const effectiveAuthSig = authorizationSignature ?? new Uint8Array(64)
554
+
418
555
  // Generate funding proof
419
556
  const fundingResult = await proofProvider.generateFundingProof({
420
557
  balance: input.amount,
@@ -422,7 +559,7 @@ export async function createShieldedIntent(
422
559
  blindingFactor: hexToUint8(inputCommitment.blindingFactor as HexString),
423
560
  assetId: input.asset.symbol,
424
561
  userAddress: senderAddress ?? '0x0',
425
- ownershipSignature: new Uint8Array(64), // Placeholder - would come from wallet
562
+ ownershipSignature: effectiveOwnershipSig,
426
563
  })
427
564
  fundingProof = fundingResult.proof
428
565
 
@@ -431,8 +568,8 @@ export async function createShieldedIntent(
431
568
  intentHash: hash(intentId) as HexString,
432
569
  senderAddress: senderAddress ?? '0x0',
433
570
  senderBlinding: hexToUint8(senderCommitment.blindingFactor as HexString),
434
- senderSecret: new Uint8Array(32), // Placeholder - would come from wallet
435
- authorizationSignature: new Uint8Array(64), // Placeholder - would come from wallet
571
+ senderSecret: effectiveSenderSecret,
572
+ authorizationSignature: effectiveAuthSig,
436
573
  nonce: new Uint8Array(32), // Could use randomBytes here
437
574
  timestamp: now,
438
575
  expiry: now + ttl,
@@ -459,8 +596,8 @@ export async function createShieldedIntent(
459
596
  // - TRANSPARENT mode (not required)
460
597
  // - No proof provider given
461
598
  // - Provider not ready
462
- fundingProof: fundingProof as any,
463
- validityProof: validityProof as any,
599
+ fundingProof,
600
+ validityProof,
464
601
 
465
602
  viewingKeyHash: privacyConfig.viewingKey?.hash,
466
603
  }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * NFT Module for SIP Protocol
3
+ *
4
+ * Private NFT ownership using stealth addresses and zero-knowledge proofs.
5
+ *
6
+ * @module nft
7
+ */
8
+
9
+ export {
10
+ PrivateNFT,
11
+ createPrivateOwnership,
12
+ proveOwnership,
13
+ verifyOwnership,
14
+ } from './private-nft'
15
+
16
+ // Re-export types for convenience
17
+ export type {
18
+ PrivateNFTOwnership,
19
+ OwnershipProof,
20
+ OwnershipVerification,
21
+ CreatePrivateOwnershipParams,
22
+ ProveOwnershipParams,
23
+ TransferPrivatelyParams,
24
+ TransferResult,
25
+ NFTTransfer,
26
+ OwnedNFT,
27
+ } from '@sip-protocol/types'