@sip-protocol/sdk 0.5.1 → 0.6.1

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 (76) hide show
  1. package/README.md +58 -0
  2. package/dist/TransportWebUSB-TQ7WZ4LE.mjs +3098 -0
  3. package/dist/browser.d.mts +4 -4
  4. package/dist/browser.d.ts +4 -4
  5. package/dist/browser.js +10133 -4664
  6. package/dist/browser.mjs +32 -1
  7. package/dist/chunk-7QZPORY5.mjs +15604 -0
  8. package/dist/chunk-C2NPCUAJ.mjs +17010 -0
  9. package/dist/chunk-FCVLFUIC.mjs +16699 -0
  10. package/dist/chunk-G5UHXECN.mjs +16340 -0
  11. package/dist/chunk-GEDEIZHJ.mjs +16798 -0
  12. package/dist/chunk-KBS3OMSZ.mjs +14737 -0
  13. package/dist/chunk-MTNYSNR7.mjs +16269 -0
  14. package/dist/chunk-O5PIB2EA.mjs +16698 -0
  15. package/dist/chunk-PCFM7FQO.mjs +17010 -0
  16. package/dist/chunk-QK464ARC.mjs +16946 -0
  17. package/dist/chunk-TK3FWQNC.mjs +14737 -0
  18. package/dist/chunk-UJCSKKID.mjs +30 -0
  19. package/dist/chunk-VNBMNGC3.mjs +16698 -0
  20. package/dist/chunk-W5TUELDQ.mjs +16947 -0
  21. package/dist/index-05W_S8A7.d.mts +9237 -0
  22. package/dist/index-C5ehlFhR.d.mts +9443 -0
  23. package/dist/index-CD_zShu-.d.ts +10870 -0
  24. package/dist/index-CNzhx-WH.d.mts +9316 -0
  25. package/dist/index-CQBYdLYy.d.mts +10976 -0
  26. package/dist/index-Cg9TYEPv.d.mts +11321 -0
  27. package/dist/index-CqSppS4i.d.ts +9237 -0
  28. package/dist/index-CqZJOO8C.d.mts +11323 -0
  29. package/dist/index-CywN9Bnp.d.ts +11321 -0
  30. package/dist/index-DBa_jiZF.d.mts +9606 -0
  31. package/dist/index-DHy5ZjCD.d.ts +10976 -0
  32. package/dist/index-DLNdSQFQ.d.ts +9316 -0
  33. package/dist/index-DfsVsmxu.d.ts +11323 -0
  34. package/dist/index-Ink8HnKW.d.ts +9606 -0
  35. package/dist/index-ObjwyVDX.d.mts +10870 -0
  36. package/dist/index-h7B23m5b.d.ts +9443 -0
  37. package/dist/index-m0xbSfmT.d.mts +11318 -0
  38. package/dist/index-rWLEgvhN.d.ts +11318 -0
  39. package/dist/index.d.mts +3 -3
  40. package/dist/index.d.ts +3 -3
  41. package/dist/index.js +10112 -4637
  42. package/dist/index.mjs +32 -1
  43. package/dist/noir-DKfEzWy9.d.mts +482 -0
  44. package/dist/noir-DKfEzWy9.d.ts +482 -0
  45. package/dist/proofs/noir.d.mts +1 -1
  46. package/dist/proofs/noir.d.ts +1 -1
  47. package/dist/proofs/noir.js +12 -3
  48. package/dist/proofs/noir.mjs +13 -3
  49. package/package.json +5 -3
  50. package/src/adapters/near-intents.ts +13 -3
  51. package/src/auction/index.ts +20 -0
  52. package/src/auction/sealed-bid.ts +1037 -0
  53. package/src/compliance/derivation.ts +13 -3
  54. package/src/compliance/reports.ts +5 -4
  55. package/src/cosmos/ibc-stealth.ts +2 -2
  56. package/src/cosmos/stealth.ts +2 -2
  57. package/src/crypto.ts +79 -9
  58. package/src/governance/index.ts +19 -0
  59. package/src/governance/private-vote.ts +1116 -0
  60. package/src/index.ts +50 -2
  61. package/src/intent.ts +227 -12
  62. package/src/nft/index.ts +27 -0
  63. package/src/nft/private-nft.ts +811 -0
  64. package/src/privacy.ts +88 -2
  65. package/src/proofs/browser-utils.ts +1 -7
  66. package/src/proofs/noir.ts +34 -7
  67. package/src/settlement/backends/direct-chain.ts +14 -3
  68. package/src/sip.ts +324 -25
  69. package/src/stealth.ts +120 -9
  70. package/src/types/browser.d.ts +67 -0
  71. package/src/validation.ts +4 -2
  72. package/src/wallet/bitcoin/adapter.ts +159 -15
  73. package/src/wallet/bitcoin/types.ts +340 -15
  74. package/src/wallet/cosmos/mock.ts +16 -12
  75. package/src/wallet/hardware/ledger.ts +83 -14
  76. package/src/wallet/hardware/types.ts +2 -0
@@ -122,10 +122,20 @@ export interface DeriveMultipleParams {
122
122
  */
123
123
  export class AuditorKeyDerivation {
124
124
  /**
125
- * SIP Protocol coin type (BIP-44 registered)
125
+ * SIP Protocol coin type for BIP-44 derivation
126
126
  *
127
- * Note: This is a placeholder. In production, register with SLIP-44:
128
- * https://github.com/satoshilabs/slips/blob/master/slip-0044.md
127
+ * This uses 1234 as SIP Protocol's internal coin type identifier.
128
+ *
129
+ * **Registration Status**: Not registered with SLIP-44
130
+ *
131
+ * **Why this is acceptable**:
132
+ * - SIP viewing keys are protocol-specific, not wallet-portable
133
+ * - Keys derived here are for auditor access, not user funds
134
+ * - SLIP-44 registration is for coin types that need hardware wallet support
135
+ *
136
+ * **Future consideration**: If hardware wallet integration for SIP auditor keys
137
+ * is desired, submit a PR to https://github.com/satoshilabs/slips to register
138
+ * an official coin type. Current value (1234) is in the unregistered range.
129
139
  */
130
140
  static readonly COIN_TYPE = 1234
131
141
 
@@ -24,6 +24,7 @@ import type {
24
24
  FINCENExport,
25
25
  FINCENTransaction,
26
26
  CSVExport,
27
+ Jurisdiction,
27
28
  } from './types'
28
29
  import { generatePdfReport } from './pdf'
29
30
 
@@ -533,7 +534,7 @@ export class ComplianceReporter {
533
534
  private exportToFATF(
534
535
  reportId: string,
535
536
  transactions: DecryptedTransaction[],
536
- jurisdiction: string,
537
+ jurisdiction: Jurisdiction,
537
538
  currency: string
538
539
  ): FATFExport {
539
540
  const fatfTransactions: FATFTransaction[] = transactions.map((tx) => ({
@@ -548,7 +549,7 @@ export class ComplianceReporter {
548
549
  return {
549
550
  reportId,
550
551
  generatedAt: new Date().toISOString(),
551
- jurisdiction: jurisdiction as any,
552
+ jurisdiction,
552
553
  transactions: fatfTransactions,
553
554
  }
554
555
  }
@@ -612,7 +613,7 @@ export class ComplianceReporter {
612
613
  private exportToCSV(
613
614
  reportId: string,
614
615
  transactions: DecryptedTransaction[],
615
- jurisdiction: string,
616
+ jurisdiction: Jurisdiction,
616
617
  currency: string
617
618
  ): CSVExport {
618
619
  const headers = [
@@ -636,7 +637,7 @@ export class ComplianceReporter {
636
637
  return {
637
638
  reportId,
638
639
  generatedAt: new Date().toISOString(),
639
- jurisdiction: jurisdiction as any,
640
+ jurisdiction,
640
641
  headers,
641
642
  rows,
642
643
  }
@@ -34,7 +34,7 @@ import {
34
34
  type CosmosStealthResult,
35
35
  CHAIN_PREFIXES,
36
36
  } from './stealth'
37
- import type { HexString, StealthMetaAddress } from '@sip-protocol/types'
37
+ import type { HexString, StealthMetaAddress, ChainId } from '@sip-protocol/types'
38
38
  import { ValidationError } from '../errors'
39
39
 
40
40
  /**
@@ -679,7 +679,7 @@ export class CosmosIBCStealthService {
679
679
 
680
680
  const [, chain, spendingKey, viewingKey] = parts
681
681
  return {
682
- chain: chain as any,
682
+ chain: chain as ChainId,
683
683
  spendingKey: spendingKey as HexString,
684
684
  viewingKey: viewingKey as HexString,
685
685
  }
@@ -32,6 +32,7 @@ import type {
32
32
  StealthAddress,
33
33
  StealthAddressRecovery,
34
34
  HexString,
35
+ ChainId,
35
36
  } from '@sip-protocol/types'
36
37
  import { ValidationError } from '../errors'
37
38
 
@@ -118,12 +119,11 @@ export class CosmosStealthService {
118
119
  const result = generateStealthMetaAddress('ethereum', label)
119
120
 
120
121
  // Override chain with actual Cosmos chain ID
121
- // Note: This is a workaround since the core types don't include Cosmos chains yet
122
122
  return {
123
123
  ...result,
124
124
  metaAddress: {
125
125
  ...result.metaAddress,
126
- chain: chain as any, // Will be updated in types package
126
+ chain: chain as ChainId,
127
127
  },
128
128
  }
129
129
  }
package/src/crypto.ts CHANGED
@@ -1,13 +1,20 @@
1
1
  /**
2
2
  * Cryptographic utilities for SIP Protocol
3
3
  *
4
- * For ZK proofs, use ProofProvider:
5
- * @see ./proofs/interface.ts for the proof provider interface
6
- * @see ./proofs/mock.ts for testing
7
- * @see ./proofs/noir.ts for production (Noir circuits)
4
+ * This module provides low-level cryptographic primitives including:
5
+ * - Hash functions (SHA-256)
6
+ * - Random number generation
7
+ * - Pedersen commitments (legacy wrappers)
8
8
  *
9
- * For Pedersen commitments, use the dedicated commitment module:
10
- * @see ./commitment.ts for secure Pedersen commitment implementation
9
+ * **Important:**
10
+ * - For ZK proofs, use {@link ProofProvider} interface (see ./proofs/)
11
+ * - For Pedersen commitments in new code, use ./commitment.ts directly
12
+ * - This module maintains legacy functions for backward compatibility
13
+ *
14
+ * @module crypto
15
+ * @see {@link ProofProvider} for zero-knowledge proof generation
16
+ * @see ./commitment.ts for modern Pedersen commitment API
17
+ * @see ./stealth.ts for stealth address cryptography
11
18
  */
12
19
 
13
20
  import { sha256 } from '@noble/hashes/sha256'
@@ -70,7 +77,18 @@ export function verifyCommitment(
70
77
  }
71
78
 
72
79
  /**
73
- * Generate a random intent ID
80
+ * Generate a unique intent identifier
81
+ *
82
+ * Creates a cryptographically random intent ID with the `sip-` prefix.
83
+ * IDs are globally unique with negligible collision probability (128-bit randomness).
84
+ *
85
+ * @returns Intent ID string in format: `sip-<32 hex chars>`
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * const intentId = generateIntentId()
90
+ * console.log(intentId) // "sip-a1b2c3d4e5f67890a1b2c3d4e5f67890"
91
+ * ```
74
92
  */
75
93
  export function generateIntentId(): string {
76
94
  const bytes = randomBytes(16)
@@ -78,7 +96,36 @@ export function generateIntentId(): string {
78
96
  }
79
97
 
80
98
  /**
81
- * Hash data using SHA256
99
+ * Compute SHA-256 hash of data
100
+ *
101
+ * General-purpose cryptographic hash function used throughout SIP protocol
102
+ * for commitment derivation, data integrity, and key derivation.
103
+ *
104
+ * **Use cases:**
105
+ * - Hash transaction data for commitments
106
+ * - Derive deterministic IDs from inputs
107
+ * - Verify data integrity
108
+ *
109
+ * @param data - Input data as UTF-8 string or raw bytes
110
+ * @returns 32-byte hash as hex string with `0x` prefix
111
+ *
112
+ * @example Hash a string
113
+ * ```typescript
114
+ * const messageHash = hash('Hello, SIP Protocol!')
115
+ * console.log(messageHash) // "0xabc123..."
116
+ * ```
117
+ *
118
+ * @example Hash binary data
119
+ * ```typescript
120
+ * const dataBytes = new Uint8Array([1, 2, 3, 4])
121
+ * const dataHash = hash(dataBytes)
122
+ * ```
123
+ *
124
+ * @example Use in commitment scheme
125
+ * ```typescript
126
+ * const intentHash = hash(intent.intentId)
127
+ * const commitment = commit(amount, hexToBytes(intentHash))
128
+ * ```
82
129
  */
83
130
  export function hash(data: string | Uint8Array): Hash {
84
131
  const input = typeof data === 'string' ? new TextEncoder().encode(data) : data
@@ -86,7 +133,30 @@ export function hash(data: string | Uint8Array): Hash {
86
133
  }
87
134
 
88
135
  /**
89
- * Generate random bytes
136
+ * Generate cryptographically secure random bytes
137
+ *
138
+ * Uses the platform's secure random source (Web Crypto API in browsers,
139
+ * crypto.randomBytes in Node.js) to generate unpredictable random data.
140
+ *
141
+ * **Use cases:**
142
+ * - Generate private keys
143
+ * - Create nonces for encryption
144
+ * - Produce blinding factors for commitments
145
+ * - Generate ephemeral keypairs
146
+ *
147
+ * @param length - Number of random bytes to generate
148
+ * @returns Random bytes as hex string with `0x` prefix
149
+ *
150
+ * @example Generate a 32-byte private key
151
+ * ```typescript
152
+ * const privateKey = generateRandomBytes(32)
153
+ * console.log(privateKey) // "0xabc123...def" (64 hex chars)
154
+ * ```
155
+ *
156
+ * @example Generate a nonce
157
+ * ```typescript
158
+ * const nonce = generateRandomBytes(24) // For XChaCha20
159
+ * ```
90
160
  */
91
161
  export function generateRandomBytes(length: number): HexString {
92
162
  return `0x${bytesToHex(randomBytes(length))}` as HexString
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Governance module for SIP Protocol
3
+ *
4
+ * Provides private voting functionality for DAO governance
5
+ */
6
+
7
+ export {
8
+ PrivateVoting,
9
+ createPrivateVoting,
10
+ } from './private-vote'
11
+
12
+ export type {
13
+ EncryptedVote,
14
+ RevealedVote,
15
+ CastVoteParams,
16
+ EncryptedTally,
17
+ TallyResult,
18
+ DecryptionShare,
19
+ } from './private-vote'