@pacspace-io/sdk 0.9.0 → 0.15.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 (152) hide show
  1. package/README.md +53 -132
  2. package/dist/blinding-file.d.ts +13 -0
  3. package/dist/blinding-file.d.ts.map +1 -0
  4. package/dist/blinding-guard.d.ts +7 -0
  5. package/dist/blinding-guard.d.ts.map +1 -0
  6. package/dist/blinding.d.ts +32 -0
  7. package/dist/blinding.d.ts.map +1 -0
  8. package/dist/client.d.ts +28 -4
  9. package/dist/client.d.ts.map +1 -1
  10. package/dist/fingerprint.d.ts +26 -5
  11. package/dist/fingerprint.d.ts.map +1 -1
  12. package/dist/index.d.ts +35 -35
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +7366 -186
  15. package/dist/index.js.map +7 -1
  16. package/dist/inputs.txt +132 -0
  17. package/dist/records-crypto-libraries.json +42 -0
  18. package/dist/records-crypto-types/proof/hiding-commitment-v1.d.ts +19 -0
  19. package/dist/records-crypto-types/proof/jcs.d.ts +4 -0
  20. package/dist/records-crypto-types/proof/layout-document-v1.d.ts +72 -0
  21. package/dist/records-crypto-types/proof/ledger-head-v1.d.ts +22 -0
  22. package/dist/records-crypto-types/proof/merkle-v2.d.ts +5 -0
  23. package/dist/records-crypto-types/proof/payload-ref-v1.d.ts +17 -0
  24. package/dist/records-crypto-types/proof/seal-input.d.ts +2 -0
  25. package/dist/records-crypto-types/proof/semantic-receipt-v2.d.ts +89 -0
  26. package/dist/records-crypto-types/proof/semantic-receipt-v3.d.ts +20 -0
  27. package/dist/records-crypto-types/proof/slot-encoding-v1.d.ts +169 -0
  28. package/dist/records-crypto-types/records/flag-threads-v1.d.ts +53 -0
  29. package/dist/records-crypto-types/records/labels.d.ts +37 -0
  30. package/dist/records-crypto-types/records/reader-crypto-v1.d.ts +198 -0
  31. package/dist/records-crypto-types/records/reader-link-v1.d.ts +164 -0
  32. package/dist/records-crypto-types/records/shared-record-ack-v2.d.ts +72 -0
  33. package/dist/records-crypto-types/records/signed-acknowledgment-v1.d.ts +38 -0
  34. package/dist/records-crypto-types/records/signed-acknowledgment-v2.d.ts +12 -0
  35. package/dist/records-crypto-types/records/trail-index-v1.d.ts +89 -0
  36. package/dist/records-crypto-types/records/trail-rule.d.ts +54 -0
  37. package/dist/records-crypto-types/records-crypto/asymmetric/ack-flag-notes-v1.d.ts +57 -0
  38. package/dist/records-crypto-types/records-crypto/asymmetric/flag-notes-v1.d.ts +55 -0
  39. package/dist/records-crypto-types/records-crypto/asymmetric/index.d.ts +4 -0
  40. package/dist/records-crypto-types/records-crypto/asymmetric/reader-wraps-v1.d.ts +83 -0
  41. package/dist/records-crypto-types/records-crypto/asymmetric/records-asymmetric-v1.d.ts +201 -0
  42. package/dist/records-crypto-types/records-crypto/base64url.d.ts +3 -0
  43. package/dist/records-crypto-types/records-crypto/blinding-file.d.ts +16 -0
  44. package/dist/records-crypto-types/records-crypto/blinding-value.d.ts +10 -0
  45. package/dist/records-crypto-types/records-crypto/bundle-entry.d.ts +2 -0
  46. package/dist/records-crypto-types/records-crypto/disclosure-envelope-v1.d.ts +42 -0
  47. package/dist/records-crypto-types/records-crypto/held-file.d.ts +17 -0
  48. package/dist/records-crypto-types/records-crypto/hmac-node.d.ts +8 -0
  49. package/dist/records-crypto-types/records-crypto/hmac-web.d.ts +8 -0
  50. package/dist/records-crypto-types/records-crypto/index.d.ts +13 -0
  51. package/dist/records-crypto-types/records-crypto/platform-crypto.d.ts +9 -0
  52. package/dist/records-crypto-types/records-crypto/record-disclosure-v1.d.ts +171 -0
  53. package/dist/records-crypto-types/records-crypto/record-hash-v2.d.ts +49 -0
  54. package/dist/records-crypto-types/records-crypto/record-hash-v3.d.ts +36 -0
  55. package/dist/records-crypto-types/records-crypto/records-encryption-v1.d.ts +185 -0
  56. package/dist/records-crypto-types/records-crypto/wrap-shapes-v1.d.ts +23 -0
  57. package/dist/records-crypto.d.ts +1 -0
  58. package/dist/records-crypto.js +16105 -0
  59. package/dist/records-crypto.js.map +7 -0
  60. package/dist/records-encryption/base64url.d.ts +5 -0
  61. package/dist/records-encryption/base64url.d.ts.map +1 -0
  62. package/dist/records-encryption/encrypted-records.d.ts +338 -0
  63. package/dist/records-encryption/encrypted-records.d.ts.map +1 -0
  64. package/dist/records-encryption/index.d.ts +14 -0
  65. package/dist/records-encryption/index.d.ts.map +1 -0
  66. package/dist/records-encryption/keys.d.ts +40 -0
  67. package/dist/records-encryption/keys.d.ts.map +1 -0
  68. package/dist/records-encryption/loader.d.ts +15 -0
  69. package/dist/records-encryption/loader.d.ts.map +1 -0
  70. package/dist/records-encryption/pin-store-file.d.ts +8 -0
  71. package/dist/records-encryption/pin-store-file.d.ts.map +1 -0
  72. package/dist/records-encryption/pin-store.d.ts +17 -0
  73. package/dist/records-encryption/pin-store.d.ts.map +1 -0
  74. package/dist/records-encryption/transport.d.ts +23 -0
  75. package/dist/records-encryption/transport.d.ts.map +1 -0
  76. package/dist/records-encryption/words.d.ts +40 -0
  77. package/dist/records-encryption/words.d.ts.map +1 -0
  78. package/dist/records-encryption/workspace-secret.d.ts +9 -0
  79. package/dist/records-encryption/workspace-secret.d.ts.map +1 -0
  80. package/dist/resources/records.d.ts +112 -2
  81. package/dist/resources/records.d.ts.map +1 -1
  82. package/dist/types/common.d.ts +0 -8
  83. package/dist/types/common.d.ts.map +1 -1
  84. package/dist/types/config.d.ts +7 -5
  85. package/dist/types/config.d.ts.map +1 -1
  86. package/dist/types/records-encryption.d.ts +136 -0
  87. package/dist/types/records-encryption.d.ts.map +1 -0
  88. package/dist/types/records.d.ts +171 -20
  89. package/dist/types/records.d.ts.map +1 -1
  90. package/dist/types/verify.d.ts +84 -0
  91. package/dist/types/verify.d.ts.map +1 -0
  92. package/dist/webhooks/index.d.ts +1 -1
  93. package/dist/webhooks/index.d.ts.map +1 -1
  94. package/dist/webhooks/index.js +229 -5
  95. package/dist/webhooks/index.js.map +7 -1
  96. package/dist/webhooks/types.d.ts +15 -7
  97. package/dist/webhooks/types.d.ts.map +1 -1
  98. package/dist/workspace-secret-file.d.ts +18 -0
  99. package/dist/workspace-secret-file.d.ts.map +1 -0
  100. package/package.json +16 -13
  101. package/dist/client.js +0 -553
  102. package/dist/client.js.map +0 -1
  103. package/dist/errors/index.js +0 -223
  104. package/dist/errors/index.js.map +0 -1
  105. package/dist/fingerprint.js +0 -132
  106. package/dist/fingerprint.js.map +0 -1
  107. package/dist/resources/balance.d.ts +0 -384
  108. package/dist/resources/balance.d.ts.map +0 -1
  109. package/dist/resources/balance.js +0 -1120
  110. package/dist/resources/balance.js.map +0 -1
  111. package/dist/resources/customers.d.ts +0 -33
  112. package/dist/resources/customers.d.ts.map +0 -1
  113. package/dist/resources/customers.js +0 -26
  114. package/dist/resources/customers.js.map +0 -1
  115. package/dist/resources/internal/batch-transport.d.ts +0 -65
  116. package/dist/resources/internal/batch-transport.d.ts.map +0 -1
  117. package/dist/resources/internal/batch-transport.js +0 -42
  118. package/dist/resources/internal/batch-transport.js.map +0 -1
  119. package/dist/resources/receipts.d.ts +0 -46
  120. package/dist/resources/receipts.d.ts.map +0 -1
  121. package/dist/resources/receipts.js +0 -133
  122. package/dist/resources/receipts.js.map +0 -1
  123. package/dist/resources/records.js +0 -232
  124. package/dist/resources/records.js.map +0 -1
  125. package/dist/resources/submission.d.ts +0 -79
  126. package/dist/resources/submission.d.ts.map +0 -1
  127. package/dist/resources/submission.js +0 -398
  128. package/dist/resources/submission.js.map +0 -1
  129. package/dist/types/balance.d.ts +0 -966
  130. package/dist/types/balance.d.ts.map +0 -1
  131. package/dist/types/balance.js +0 -3
  132. package/dist/types/balance.js.map +0 -1
  133. package/dist/types/common.js +0 -3
  134. package/dist/types/common.js.map +0 -1
  135. package/dist/types/config.js +0 -3
  136. package/dist/types/config.js.map +0 -1
  137. package/dist/types/records.js +0 -5
  138. package/dist/types/records.js.map +0 -1
  139. package/dist/types/submission.d.ts +0 -125
  140. package/dist/types/submission.d.ts.map +0 -1
  141. package/dist/types/submission.js +0 -3
  142. package/dist/types/submission.js.map +0 -1
  143. package/dist/utils/polling.d.ts +0 -32
  144. package/dist/utils/polling.d.ts.map +0 -1
  145. package/dist/utils/polling.js +0 -52
  146. package/dist/utils/polling.js.map +0 -1
  147. package/dist/utils/retry.js +0 -21
  148. package/dist/utils/retry.js.map +0 -1
  149. package/dist/webhooks/types.js +0 -3
  150. package/dist/webhooks/types.js.map +0 -1
  151. package/dist/webhooks/verify.js +0 -191
  152. package/dist/webhooks/verify.js.map +0 -1
@@ -1,223 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebhookVerificationError = exports.TimeoutError = exports.ScopeTooWideError = exports.InvalidScopeCombinationError = exports.ValidationError = exports.ServiceUnavailableError = exports.CadenceLimitError = exports.RateLimitError = exports.ContractNotDeployedError = exports.ReceiptNotReadyError = exports.ReceiptNotFoundError = exports.NotFoundError = exports.InsufficientCreditsError = exports.InvalidApiKeyError = exports.PacSpaceError = void 0;
4
- exports.mapApiError = mapApiError;
5
- /**
6
- * Base error class for all PacSpace SDK errors.
7
- * Extends native Error with structured API error data.
8
- */
9
- class PacSpaceError extends Error {
10
- constructor(message, statusCode, code, requestPath) {
11
- super(message);
12
- this.name = 'PacSpaceError';
13
- this.statusCode = statusCode;
14
- this.code = code;
15
- this.requestPath = requestPath;
16
- // Ensure instanceof works correctly in TS
17
- Object.setPrototypeOf(this, new.target.prototype);
18
- }
19
- }
20
- exports.PacSpaceError = PacSpaceError;
21
- /**
22
- * Thrown when the API key is missing, invalid, or disabled (HTTP 401).
23
- */
24
- class InvalidApiKeyError extends PacSpaceError {
25
- constructor(message = 'Invalid or missing API key', requestPath) {
26
- super(message, 401, 'INVALID_API_KEY', requestPath);
27
- this.name = 'InvalidApiKeyError';
28
- }
29
- }
30
- exports.InvalidApiKeyError = InvalidApiKeyError;
31
- /**
32
- * Thrown when the tenant has insufficient credits for the operation (HTTP 402).
33
- */
34
- class InsufficientCreditsError extends PacSpaceError {
35
- constructor(message = 'Insufficient credits for this operation', requestPath) {
36
- super(message, 402, 'INSUFFICIENT_CREDITS', requestPath);
37
- this.name = 'InsufficientCreditsError';
38
- }
39
- }
40
- exports.InsufficientCreditsError = InsufficientCreditsError;
41
- /**
42
- * Thrown when the requested resource is not found (HTTP 404).
43
- */
44
- class NotFoundError extends PacSpaceError {
45
- constructor(message = 'Resource not found', requestPath) {
46
- super(message, 404, 'NOT_FOUND', requestPath);
47
- this.name = 'NotFoundError';
48
- }
49
- }
50
- exports.NotFoundError = NotFoundError;
51
- /**
52
- * Thrown when a receipt cannot be found (HTTP 404).
53
- */
54
- class ReceiptNotFoundError extends PacSpaceError {
55
- constructor(message = 'Receipt not found', requestPath) {
56
- super(message, 404, 'RECEIPT_NOT_FOUND', requestPath);
57
- this.name = 'ReceiptNotFoundError';
58
- }
59
- }
60
- exports.ReceiptNotFoundError = ReceiptNotFoundError;
61
- /**
62
- * Thrown when a receipt exists but is not ready yet (HTTP 409).
63
- */
64
- class ReceiptNotReadyError extends PacSpaceError {
65
- constructor(message = 'Receipt is not ready yet', requestPath) {
66
- super(message, 409, 'RECEIPT_NOT_READY', requestPath);
67
- this.name = 'ReceiptNotReadyError';
68
- }
69
- }
70
- exports.ReceiptNotReadyError = ReceiptNotReadyError;
71
- /**
72
- * Thrown when no contract is deployed for the tenant (HTTP 412).
73
- */
74
- class ContractNotDeployedError extends PacSpaceError {
75
- constructor(message = 'No contract deployed. Provision an environment first.', requestPath) {
76
- super(message, 412, 'CONTRACT_NOT_DEPLOYED', requestPath);
77
- this.name = 'ContractNotDeployedError';
78
- }
79
- }
80
- exports.ContractNotDeployedError = ContractNotDeployedError;
81
- /**
82
- * Thrown when the API rate limit is exceeded (HTTP 429).
83
- */
84
- class RateLimitError extends PacSpaceError {
85
- constructor(message = 'Rate limit exceeded', retryAfter = null, requestPath) {
86
- super(message, 429, 'RATE_LIMITED', requestPath);
87
- this.name = 'RateLimitError';
88
- this.retryAfter = retryAfter;
89
- }
90
- }
91
- exports.RateLimitError = RateLimitError;
92
- /**
93
- * Thrown when a customer's submission cadence window has not elapsed (HTTP 429).
94
- * This error is terminal for the current request and should not be auto-retried.
95
- */
96
- class CadenceLimitError extends PacSpaceError {
97
- constructor(message = 'Submission cadence limit reached', retryAfterSeconds = null, customerId = null, requestPath) {
98
- super(message, 429, 'CADENCE_LIMIT', requestPath);
99
- this.name = 'CadenceLimitError';
100
- this.retryAfterMs =
101
- retryAfterSeconds && Number.isFinite(retryAfterSeconds)
102
- ? Math.max(0, Math.floor(retryAfterSeconds * 1000))
103
- : null;
104
- this.customerId = customerId;
105
- }
106
- }
107
- exports.CadenceLimitError = CadenceLimitError;
108
- /**
109
- * Thrown when the API is temporarily unavailable (HTTP 503).
110
- */
111
- class ServiceUnavailableError extends PacSpaceError {
112
- constructor(message = 'Service temporarily unavailable', retryAfter = null, requestPath) {
113
- super(message, 503, 'SERVICE_UNAVAILABLE', requestPath);
114
- this.name = 'ServiceUnavailableError';
115
- this.retryAfter = retryAfter;
116
- }
117
- }
118
- exports.ServiceUnavailableError = ServiceUnavailableError;
119
- /**
120
- * Thrown when the API returns a validation error (HTTP 400).
121
- */
122
- class ValidationError extends PacSpaceError {
123
- constructor(message = 'Invalid request data', requestPath) {
124
- super(message, 400, 'VALIDATION_ERROR', requestPath);
125
- this.name = 'ValidationError';
126
- }
127
- }
128
- exports.ValidationError = ValidationError;
129
- /**
130
- * Thrown when a request mixes mutually-exclusive scope fields (HTTP 400).
131
- */
132
- class InvalidScopeCombinationError extends PacSpaceError {
133
- constructor(message = 'Choose either a checkpoint or a time scope for this request.', requestPath) {
134
- super(message, 400, 'INVALID_SCOPE_COMBINATION', requestPath);
135
- this.name = 'InvalidScopeCombinationError';
136
- }
137
- }
138
- exports.InvalidScopeCombinationError = InvalidScopeCombinationError;
139
- /**
140
- * Thrown when the requested scope exceeds the maximum supported window (HTTP 400).
141
- */
142
- class ScopeTooWideError extends PacSpaceError {
143
- constructor(message = 'Scope window is too wide for a single request.', requestPath) {
144
- super(message, 400, 'SCOPE_TOO_WIDE', requestPath);
145
- this.name = 'ScopeTooWideError';
146
- }
147
- }
148
- exports.ScopeTooWideError = ScopeTooWideError;
149
- /**
150
- * Thrown when a polling operation exceeds the configured timeout.
151
- */
152
- class TimeoutError extends PacSpaceError {
153
- constructor(message = 'Operation timed out waiting for verification', requestPath) {
154
- super(message, 0, 'TIMEOUT', requestPath);
155
- this.name = 'TimeoutError';
156
- }
157
- }
158
- exports.TimeoutError = TimeoutError;
159
- /**
160
- * Thrown when the webhook signature is invalid.
161
- */
162
- class WebhookVerificationError extends PacSpaceError {
163
- constructor(message = 'Webhook signature verification failed') {
164
- super(message, 0, 'WEBHOOK_VERIFICATION_FAILED');
165
- this.name = 'WebhookVerificationError';
166
- }
167
- }
168
- exports.WebhookVerificationError = WebhookVerificationError;
169
- /**
170
- * Map an HTTP status code + API response to the appropriate typed error.
171
- * @internal
172
- */
173
- function mapApiError(statusCode, message, requestPath, headers, apiError) {
174
- const headerRetryAfter = headers?.get('retry-after');
175
- const parsedHeaderRetryAfter = headerRetryAfter
176
- ? Number.parseInt(headerRetryAfter, 10)
177
- : null;
178
- const retryAfterSeconds = apiError?.retryAfterSeconds ??
179
- (Number.isFinite(parsedHeaderRetryAfter)
180
- ? parsedHeaderRetryAfter
181
- : null);
182
- switch (statusCode) {
183
- case 400:
184
- if (apiError?.code === 'INVALID_SCOPE_COMBINATION') {
185
- return new InvalidScopeCombinationError(message, requestPath);
186
- }
187
- if (apiError?.code === 'SCOPE_TOO_WIDE') {
188
- return new ScopeTooWideError(message, requestPath);
189
- }
190
- if (apiError?.code) {
191
- return new PacSpaceError(message, statusCode, apiError.code, requestPath);
192
- }
193
- return new ValidationError(message, requestPath);
194
- case 401:
195
- return new InvalidApiKeyError(message, requestPath);
196
- case 402:
197
- return new InsufficientCreditsError(message, requestPath);
198
- case 404:
199
- if (apiError?.code === 'RECEIPT_NOT_FOUND') {
200
- return new ReceiptNotFoundError(message, requestPath);
201
- }
202
- return new NotFoundError(message, requestPath);
203
- case 409:
204
- if (apiError?.code === 'RECEIPT_NOT_READY') {
205
- return new ReceiptNotReadyError(message, requestPath);
206
- }
207
- return new PacSpaceError(message, statusCode, apiError?.code || 'CONFLICT', requestPath);
208
- case 412:
209
- return new ContractNotDeployedError(message, requestPath);
210
- case 429: {
211
- if (apiError?.code === 'CADENCE_LIMIT') {
212
- return new CadenceLimitError(message, retryAfterSeconds, apiError.customerId ?? null, requestPath);
213
- }
214
- return new RateLimitError(message, retryAfterSeconds, requestPath);
215
- }
216
- case 503: {
217
- return new ServiceUnavailableError(message, retryAfterSeconds, requestPath);
218
- }
219
- default:
220
- return new PacSpaceError(message, statusCode, apiError?.code || 'API_ERROR', requestPath);
221
- }
222
- }
223
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";;;AA4NA,kCA+EC;AA3SD;;;GAGG;AACH,MAAa,aAAc,SAAQ,KAAK;IAQtC,YACE,OAAe,EACf,UAAkB,EAClB,IAAY,EACZ,WAAoB;QAEpB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAE/B,0CAA0C;QAC1C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAvBD,sCAuBC;AAED;;GAEG;AACH,MAAa,kBAAmB,SAAQ,aAAa;IACnD,YAAY,OAAO,GAAG,4BAA4B,EAAE,WAAoB;QACtE,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,iBAAiB,EAAE,WAAW,CAAC,CAAC;QACpD,IAAI,CAA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;QACjD,KAAK,GAAG;YACN,IAAI,QAAQ,EAAE,IAAI,KAAK,mBAAmB,EAAE,CAAC;gBAC3C,OAAO,IAAI,oBAAoB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;YACxD,CAAC;YACD,OAAO,IAAI,aAAa,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,IAAI,UAAU,EAAE,WAAW,CAAC,CAAC;QAC3F,KAAK,GAAG;YACN,OAAO,IAAI,wBAAwB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAC5D,KAAK,GAAG,CAAC,CAAC,CAAC;YACT,IAAI,QAAQ,EAAE,IAAI,KAAK,eAAe,EAAE,CAAC;gBACvC,OAAO,IAAI,iBAAiB,CAC1B,OAAO,EACP,iBAAiB,EACjB,QAAQ,CAAC,UAAU,IAAI,IAAI,EAC3B,WAAW,CACZ,CAAC;YACJ,CAAC;YACD,OAAO,IAAI,cAAc,CACvB,OAAO,EACP,iBAAiB,EACjB,WAAW,CACZ,CAAC;QACJ,CAAC;QACD,KAAK,GAAG,CAAC,CAAC,CAAC;YACT,OAAO,IAAI,uBAAuB,CAChC,OAAO,EACP,iBAAiB,EACjB,WAAW,CACZ,CAAC;QACJ,CAAC;QACD;YACE,OAAO,IAAI,aAAa,CACtB,OAAO,EACP,UAAU,EACV,QAAQ,EAAE,IAAI,IAAI,WAAW,EAC7B,WAAW,CACZ,CAAC;IACN,CAAC;AACH,CAAC"}
@@ -1,132 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.fingerprint = fingerprint;
37
- const errors_1 = require("./errors");
38
- function isAsyncIterable(value) {
39
- return !!value && typeof value[Symbol.asyncIterator] === 'function';
40
- }
41
- function isIterable(value) {
42
- return (!!value &&
43
- typeof value[Symbol.iterator] === 'function' &&
44
- !(value instanceof Uint8Array));
45
- }
46
- async function* chunksOf(input) {
47
- if (input instanceof Uint8Array) {
48
- yield input;
49
- return;
50
- }
51
- if (typeof ArrayBuffer !== 'undefined' && input instanceof ArrayBuffer) {
52
- yield new Uint8Array(input);
53
- return;
54
- }
55
- if (typeof Blob !== 'undefined' && input instanceof Blob) {
56
- const buffer = await input.arrayBuffer();
57
- yield new Uint8Array(buffer);
58
- return;
59
- }
60
- if (typeof ReadableStream !== 'undefined' && input instanceof ReadableStream) {
61
- const reader = input.getReader();
62
- try {
63
- while (true) {
64
- const { done, value } = await reader.read();
65
- if (done)
66
- break;
67
- if (value)
68
- yield value;
69
- }
70
- }
71
- finally {
72
- reader.releaseLock();
73
- }
74
- return;
75
- }
76
- if (isAsyncIterable(input)) {
77
- for await (const chunk of input)
78
- yield chunk;
79
- return;
80
- }
81
- if (isIterable(input)) {
82
- for (const chunk of input)
83
- yield chunk;
84
- return;
85
- }
86
- throw new errors_1.PacSpaceError('fingerprint needs bytes or an iterable of bytes', 0, 'RECORD_CONTENT_INVALID');
87
- }
88
- /**
89
- * Fingerprint bytes where they live. PacSpace receives the digest and size,
90
- * never the file. Wraps the same sha-256 rule as `digestPayload`.
91
- */
92
- async function fingerprint(input, options) {
93
- const alg = options?.alg ?? 'sha-256';
94
- if (alg !== 'sha-256') {
95
- throw new errors_1.PacSpaceError('A fingerprint is made with sha-256.', 0, 'RECORD_PAYLOAD_ALG_UNSUPPORTED');
96
- }
97
- let byteLength = 0n;
98
- let nodeCrypto = null;
99
- const isNode = typeof process !== 'undefined' && !!process.versions?.node;
100
- if (isNode) {
101
- try {
102
- const specifier = 'node:crypto';
103
- nodeCrypto = await Promise.resolve(`${specifier}`).then(s => __importStar(require(s)));
104
- }
105
- catch {
106
- nodeCrypto = null;
107
- }
108
- }
109
- if (nodeCrypto && typeof nodeCrypto.createHash === 'function') {
110
- const hash = nodeCrypto.createHash('sha256');
111
- for await (const chunk of chunksOf(input)) {
112
- hash.update(chunk);
113
- byteLength += BigInt(chunk.length);
114
- }
115
- return { alg, digest: hash.digest('hex'), byteLength: byteLength.toString() };
116
- }
117
- const parts = [];
118
- for await (const chunk of chunksOf(input)) {
119
- parts.push(chunk);
120
- byteLength += BigInt(chunk.length);
121
- }
122
- const joined = new Uint8Array(Number(byteLength));
123
- let offset = 0;
124
- for (const part of parts) {
125
- joined.set(part, offset);
126
- offset += part.length;
127
- }
128
- const digest = await globalThis.crypto.subtle.digest('SHA-256', joined);
129
- const hex = Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, '0')).join('');
130
- return { alg, digest: hex, byteLength: byteLength.toString() };
131
- }
132
- //# sourceMappingURL=fingerprint.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fingerprint.js","sourceRoot":"","sources":["../src/fingerprint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;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