@sip-protocol/sdk 0.2.1 → 0.2.3

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.
@@ -0,0 +1,223 @@
1
+ // src/errors.ts
2
+ var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
3
+ ErrorCode2["UNKNOWN"] = "SIP_1000";
4
+ ErrorCode2["INTERNAL"] = "SIP_1001";
5
+ ErrorCode2["NOT_IMPLEMENTED"] = "SIP_1002";
6
+ ErrorCode2["VALIDATION_FAILED"] = "SIP_2000";
7
+ ErrorCode2["INVALID_INPUT"] = "SIP_2001";
8
+ ErrorCode2["INVALID_CHAIN"] = "SIP_2002";
9
+ ErrorCode2["INVALID_PRIVACY_LEVEL"] = "SIP_2003";
10
+ ErrorCode2["INVALID_AMOUNT"] = "SIP_2004";
11
+ ErrorCode2["INVALID_HEX"] = "SIP_2005";
12
+ ErrorCode2["INVALID_KEY"] = "SIP_2006";
13
+ ErrorCode2["INVALID_ADDRESS"] = "SIP_2007";
14
+ ErrorCode2["MISSING_REQUIRED"] = "SIP_2008";
15
+ ErrorCode2["OUT_OF_RANGE"] = "SIP_2009";
16
+ ErrorCode2["CRYPTO_FAILED"] = "SIP_3000";
17
+ ErrorCode2["ENCRYPTION_FAILED"] = "SIP_3001";
18
+ ErrorCode2["DECRYPTION_FAILED"] = "SIP_3002";
19
+ ErrorCode2["KEY_DERIVATION_FAILED"] = "SIP_3003";
20
+ ErrorCode2["COMMITMENT_FAILED"] = "SIP_3004";
21
+ ErrorCode2["SIGNATURE_FAILED"] = "SIP_3005";
22
+ ErrorCode2["INVALID_CURVE_POINT"] = "SIP_3006";
23
+ ErrorCode2["INVALID_SCALAR"] = "SIP_3007";
24
+ ErrorCode2["PROOF_FAILED"] = "SIP_4000";
25
+ ErrorCode2["PROOF_GENERATION_FAILED"] = "SIP_4001";
26
+ ErrorCode2["PROOF_VERIFICATION_FAILED"] = "SIP_4002";
27
+ ErrorCode2["PROOF_NOT_IMPLEMENTED"] = "SIP_4003";
28
+ ErrorCode2["PROOF_PROVIDER_NOT_READY"] = "SIP_4004";
29
+ ErrorCode2["INVALID_PROOF_PARAMS"] = "SIP_4005";
30
+ ErrorCode2["INTENT_FAILED"] = "SIP_5000";
31
+ ErrorCode2["INTENT_EXPIRED"] = "SIP_5001";
32
+ ErrorCode2["INTENT_CANCELLED"] = "SIP_5002";
33
+ ErrorCode2["INTENT_NOT_FOUND"] = "SIP_5003";
34
+ ErrorCode2["INTENT_INVALID_STATE"] = "SIP_5004";
35
+ ErrorCode2["PROOFS_REQUIRED"] = "SIP_5005";
36
+ ErrorCode2["QUOTE_EXPIRED"] = "SIP_5006";
37
+ ErrorCode2["NETWORK_FAILED"] = "SIP_6000";
38
+ ErrorCode2["NETWORK_TIMEOUT"] = "SIP_6001";
39
+ ErrorCode2["NETWORK_UNAVAILABLE"] = "SIP_6002";
40
+ ErrorCode2["RPC_ERROR"] = "SIP_6003";
41
+ ErrorCode2["API_ERROR"] = "SIP_6004";
42
+ ErrorCode2["RATE_LIMITED"] = "SIP_6005";
43
+ ErrorCode2["WALLET_ERROR"] = "SIP_7000";
44
+ ErrorCode2["WALLET_NOT_CONNECTED"] = "SIP_7001";
45
+ ErrorCode2["WALLET_CONNECTION_FAILED"] = "SIP_7002";
46
+ ErrorCode2["WALLET_SIGNING_FAILED"] = "SIP_7003";
47
+ ErrorCode2["WALLET_TRANSACTION_FAILED"] = "SIP_7004";
48
+ return ErrorCode2;
49
+ })(ErrorCode || {});
50
+ var SIPError = class extends Error {
51
+ /** Machine-readable error code */
52
+ code;
53
+ /** Additional debugging context */
54
+ context;
55
+ /** Timestamp when error was created */
56
+ timestamp;
57
+ constructor(message, code = "SIP_1000" /* UNKNOWN */, options) {
58
+ super(message, { cause: options?.cause });
59
+ this.name = "SIPError";
60
+ this.code = code;
61
+ this.context = options?.context;
62
+ this.timestamp = /* @__PURE__ */ new Date();
63
+ if (Error.captureStackTrace) {
64
+ Error.captureStackTrace(this, this.constructor);
65
+ }
66
+ }
67
+ /**
68
+ * Serialize error for logging or transmission
69
+ */
70
+ toJSON() {
71
+ return {
72
+ name: this.name,
73
+ code: this.code,
74
+ message: this.message,
75
+ context: this.context,
76
+ cause: this.cause instanceof Error ? this.cause.message : void 0,
77
+ stack: this.stack,
78
+ timestamp: this.timestamp.toISOString()
79
+ };
80
+ }
81
+ /**
82
+ * Create a string representation for logging
83
+ */
84
+ toString() {
85
+ let result = `[${this.code}] ${this.name}: ${this.message}`;
86
+ if (this.cause instanceof Error) {
87
+ result += `
88
+ Caused by: ${this.cause.message}`;
89
+ }
90
+ return result;
91
+ }
92
+ };
93
+ var ValidationError = class extends SIPError {
94
+ /** The field that failed validation (if applicable) */
95
+ field;
96
+ constructor(message, field, context, code = "SIP_2000" /* VALIDATION_FAILED */) {
97
+ const fullMessage = field ? `Validation failed for '${field}': ${message}` : `Validation failed: ${message}`;
98
+ super(fullMessage, code, { context });
99
+ this.name = "ValidationError";
100
+ this.field = field;
101
+ }
102
+ toJSON() {
103
+ return {
104
+ ...super.toJSON(),
105
+ field: this.field
106
+ };
107
+ }
108
+ };
109
+ var CryptoError = class extends SIPError {
110
+ /** The cryptographic operation that failed */
111
+ operation;
112
+ constructor(message, code = "SIP_3000" /* CRYPTO_FAILED */, options) {
113
+ super(message, code, options);
114
+ this.name = "CryptoError";
115
+ this.operation = options?.operation;
116
+ }
117
+ };
118
+ var EncryptionNotImplementedError = class extends CryptoError {
119
+ /** The type of encryption operation */
120
+ operationType;
121
+ /** Reference to the specification document */
122
+ specReference;
123
+ constructor(operation, specReference) {
124
+ const message = `${operation.charAt(0).toUpperCase() + operation.slice(1)}ion is not implemented. Real authenticated encryption (ChaCha20-Poly1305) is required. See specification: ${specReference}`;
125
+ super(message, "SIP_1002" /* NOT_IMPLEMENTED */, {
126
+ context: { operation, specReference }
127
+ });
128
+ this.name = "EncryptionNotImplementedError";
129
+ this.operationType = operation;
130
+ this.specReference = specReference;
131
+ }
132
+ };
133
+ var ProofError = class extends SIPError {
134
+ /** The type of proof involved */
135
+ proofType;
136
+ constructor(message, code = "SIP_4000" /* PROOF_FAILED */, options) {
137
+ super(message, code, options);
138
+ this.name = "ProofError";
139
+ this.proofType = options?.proofType;
140
+ }
141
+ };
142
+ var ProofNotImplementedError = class extends ProofError {
143
+ /** Reference to the specification document */
144
+ specReference;
145
+ constructor(proofType, specReference) {
146
+ const message = `${proofType.charAt(0).toUpperCase() + proofType.slice(1)} proof generation is not implemented. Real ZK proofs are required for production use. See specification: ${specReference}`;
147
+ super(message, "SIP_4003" /* PROOF_NOT_IMPLEMENTED */, {
148
+ context: { specReference },
149
+ proofType
150
+ });
151
+ this.name = "ProofNotImplementedError";
152
+ this.specReference = specReference;
153
+ }
154
+ };
155
+ var IntentError = class extends SIPError {
156
+ /** The intent ID involved (if available) */
157
+ intentId;
158
+ constructor(message, code = "SIP_5000" /* INTENT_FAILED */, options) {
159
+ super(message, code, options);
160
+ this.name = "IntentError";
161
+ this.intentId = options?.intentId;
162
+ }
163
+ };
164
+ var NetworkError = class extends SIPError {
165
+ /** The endpoint that failed (if applicable) */
166
+ endpoint;
167
+ /** HTTP status code (if applicable) */
168
+ statusCode;
169
+ constructor(message, code = "SIP_6000" /* NETWORK_FAILED */, options) {
170
+ super(message, code, options);
171
+ this.name = "NetworkError";
172
+ this.endpoint = options?.endpoint;
173
+ this.statusCode = options?.statusCode;
174
+ }
175
+ };
176
+ function isSIPError(error) {
177
+ return error instanceof SIPError;
178
+ }
179
+ function hasErrorCode(error, code) {
180
+ return isSIPError(error) && error.code === code;
181
+ }
182
+ function wrapError(error, message, code = "SIP_1001" /* INTERNAL */, context) {
183
+ if (error instanceof SIPError) {
184
+ return error;
185
+ }
186
+ const cause = error instanceof Error ? error : new Error(String(error));
187
+ return new SIPError(message, code, { cause, context });
188
+ }
189
+ function getErrorMessage(error) {
190
+ if (error instanceof Error) {
191
+ return error.message;
192
+ }
193
+ return String(error);
194
+ }
195
+
196
+ // src/proofs/interface.ts
197
+ var ProofGenerationError = class extends Error {
198
+ proofType;
199
+ cause;
200
+ constructor(proofType, message, cause) {
201
+ super(`${proofType} proof generation failed: ${message}`);
202
+ this.name = "ProofGenerationError";
203
+ this.proofType = proofType;
204
+ this.cause = cause;
205
+ }
206
+ };
207
+
208
+ export {
209
+ ErrorCode,
210
+ SIPError,
211
+ ValidationError,
212
+ CryptoError,
213
+ EncryptionNotImplementedError,
214
+ ProofError,
215
+ ProofNotImplementedError,
216
+ IntentError,
217
+ NetworkError,
218
+ isSIPError,
219
+ hasErrorCode,
220
+ wrapError,
221
+ getErrorMessage,
222
+ ProofGenerationError
223
+ };