@0xkey-io/api-key-stamper 0.1.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +201 -0
  3. package/README.md +26 -0
  4. package/dist/_kernel/stamper.d.ts +29 -0
  5. package/dist/_kernel/stamper.d.ts.map +1 -0
  6. package/dist/_kernel/stamping.d.ts +6 -0
  7. package/dist/_kernel/stamping.d.ts.map +1 -0
  8. package/dist/index.d.ts +3 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +371 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/index.mjs +366 -0
  13. package/dist/index.mjs.map +1 -0
  14. package/dist/nodecrypto-BEvYdLDk.js +46 -0
  15. package/dist/nodecrypto-BEvYdLDk.js.map +1 -0
  16. package/dist/nodecrypto-CWFu007J.js +25 -0
  17. package/dist/nodecrypto-CWFu007J.js.map +1 -0
  18. package/dist/nodecrypto.d.ts +6 -0
  19. package/dist/nodecrypto.d.ts.map +1 -0
  20. package/dist/purejs-BG8ixYIu.js +20 -0
  21. package/dist/purejs-BG8ixYIu.js.map +1 -0
  22. package/dist/purejs-XGKef2yb.js +18 -0
  23. package/dist/purejs-XGKef2yb.js.map +1 -0
  24. package/dist/purejs.d.ts +6 -0
  25. package/dist/purejs.d.ts.map +1 -0
  26. package/dist/tink/bytes.d.ts +45 -0
  27. package/dist/tink/bytes.d.ts.map +1 -0
  28. package/dist/tink/elliptic_curves.d.ts +18 -0
  29. package/dist/tink/elliptic_curves.d.ts.map +1 -0
  30. package/dist/utils-65MgUjOA.js +30 -0
  31. package/dist/utils-65MgUjOA.js.map +1 -0
  32. package/dist/utils-U6G_myeu.js +28 -0
  33. package/dist/utils-U6G_myeu.js.map +1 -0
  34. package/dist/utils.d.ts +14 -0
  35. package/dist/utils.d.ts.map +1 -0
  36. package/dist/webcrypto-BM8R-Kt_.js +115 -0
  37. package/dist/webcrypto-BM8R-Kt_.js.map +1 -0
  38. package/dist/webcrypto-BdGOYdbN.js +113 -0
  39. package/dist/webcrypto-BdGOYdbN.js.map +1 -0
  40. package/dist/webcrypto.d.ts +7 -0
  41. package/dist/webcrypto.d.ts.map +1 -0
  42. package/package.json +62 -0
package/dist/index.mjs ADDED
@@ -0,0 +1,366 @@
1
+ import { stringToBase64urlString, uint8ArrayToHexString } from '@0xkey-io/encoding';
2
+ import { fromDerSignature } from '@0xkey-io/crypto';
3
+
4
+ function createStampResult(stampHeaderName, stampHeaderValue) {
5
+ return { stampHeaderName, stampHeaderValue };
6
+ }
7
+
8
+ /// <reference lib="dom" />
9
+ const stampHeaderName = "X-Stamp";
10
+ var SignatureFormat;
11
+ (function (SignatureFormat) {
12
+ SignatureFormat["Der"] = "der";
13
+ SignatureFormat["Raw"] = "raw";
14
+ })(SignatureFormat || (SignatureFormat = {}));
15
+ const isCryptoEnabledBrowser = typeof window !== "undefined" &&
16
+ typeof window.document !== "undefined" &&
17
+ typeof crypto !== "undefined" &&
18
+ typeof crypto.subtle !== "undefined";
19
+ const isNode = typeof process !== "undefined" &&
20
+ process.versions != null &&
21
+ process.versions.node != null;
22
+ const detectRuntime = () => {
23
+ if (isCryptoEnabledBrowser) {
24
+ return "browser";
25
+ }
26
+ if (isNode) {
27
+ return "node";
28
+ }
29
+ return "purejs";
30
+ };
31
+ const signWithApiKey = async (input, runtimeOverride) => {
32
+ const runtime = runtimeOverride ?? detectRuntime();
33
+ switch (runtime) {
34
+ case "browser":
35
+ return (await import('./webcrypto-BdGOYdbN.js')).signWithApiKey(input);
36
+ case "node":
37
+ return (await import('./nodecrypto-CWFu007J.js')).signWithApiKey(input);
38
+ case "purejs":
39
+ return (await import('./purejs-XGKef2yb.js')).signWithApiKey(input);
40
+ default:
41
+ throw new Error(`Unsupported runtime: ${runtime}`);
42
+ }
43
+ };
44
+ class ApiKeyStamper {
45
+ constructor(config) {
46
+ this.apiPublicKey = config.apiPublicKey;
47
+ this.apiPrivateKey = config.apiPrivateKey;
48
+ this.runtimeOverride = config.runtimeOverride;
49
+ }
50
+ async stamp(payload) {
51
+ const signature = await signWithApiKey({
52
+ publicKey: this.apiPublicKey,
53
+ privateKey: this.apiPrivateKey,
54
+ content: payload,
55
+ }, this.runtimeOverride);
56
+ const stamp = {
57
+ publicKey: this.apiPublicKey,
58
+ scheme: "SIGNATURE_SCHEME_TK_API_P256",
59
+ signature,
60
+ };
61
+ return createStampResult(stampHeaderName, stringToBase64urlString(JSON.stringify(stamp)));
62
+ }
63
+ async sign(payload, format) {
64
+ switch (format) {
65
+ case SignatureFormat.Raw: {
66
+ const derSignature = await signWithApiKey({
67
+ publicKey: this.apiPublicKey,
68
+ privateKey: this.apiPrivateKey,
69
+ content: payload,
70
+ }, this.runtimeOverride);
71
+ const raw = fromDerSignature(derSignature);
72
+ return uint8ArrayToHexString(raw);
73
+ }
74
+ case SignatureFormat.Der: {
75
+ return signWithApiKey({
76
+ publicKey: this.apiPublicKey,
77
+ privateKey: this.apiPrivateKey,
78
+ content: payload,
79
+ }, this.runtimeOverride);
80
+ }
81
+ default:
82
+ throw new Error(`Unsupported signature format: ${format}`);
83
+ }
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Code modified from https://github.com/google/tink/blob/6f74b99a2bfe6677e3670799116a57268fd067fa/javascript/subtle/bytes.ts
89
+ *
90
+ * @license
91
+ * Copyright 2020 Google LLC
92
+ * SPDX-License-Identifier: Apache-2.0
93
+ */
94
+ /**
95
+ * Converts the hex string to a byte array.
96
+ *
97
+ * @param hex the input
98
+ * @return the byte array output
99
+ * @throws {!Error}
100
+ * @static
101
+ */
102
+ function fromHex(hex) {
103
+ if (hex.length % 2 != 0) {
104
+ throw new Error("Hex string length must be multiple of 2");
105
+ }
106
+ const arr = new Uint8Array(hex.length / 2);
107
+ for (let i = 0; i < hex.length; i += 2) {
108
+ arr[i / 2] = parseInt(hex.substring(i, i + 2), 16);
109
+ }
110
+ return arr;
111
+ }
112
+ /**
113
+ * Converts a byte array to hex.
114
+ *
115
+ * @param bytes the byte array input
116
+ * @return hex the output
117
+ * @static
118
+ */
119
+ function toHex(bytes) {
120
+ let result = "";
121
+ for (let i = 0; i < bytes.length; i++) {
122
+ const hexByte = bytes[i].toString(16);
123
+ result += hexByte.length > 1 ? hexByte : "0" + hexByte;
124
+ }
125
+ return result;
126
+ }
127
+ /**
128
+ * Base64 encode a byte array.
129
+ *
130
+ * @param bytes the byte array input
131
+ * @param opt_webSafe True indicates we should use the alternative
132
+ * alphabet, which does not require escaping for use in URLs.
133
+ * @return base64 output
134
+ * @static
135
+ */
136
+ function toBase64(bytes, opt_webSafe) {
137
+ const encoded = btoa(
138
+ /* padding */
139
+ toByteString(bytes)).replace(/=/g, "");
140
+ {
141
+ return encoded.replace(/\+/g, "-").replace(/\//g, "_");
142
+ }
143
+ }
144
+ /**
145
+ * Turns a byte array into the string given by the concatenation of the
146
+ * characters to which the numbers correspond. Each byte is corresponding to a
147
+ * character. Does not support multi-byte characters.
148
+ *
149
+ * @param bytes Array of numbers representing
150
+ * characters.
151
+ * @return Stringification of the array.
152
+ */
153
+ function toByteString(bytes) {
154
+ let str = "";
155
+ for (let i = 0; i < bytes.length; i += 1) {
156
+ str += String.fromCharCode(bytes[i]);
157
+ }
158
+ return str;
159
+ }
160
+
161
+ /**
162
+ * Code modified from https://github.com/google/tink/blob/6f74b99a2bfe6677e3670799116a57268fd067fa/javascript/subtle/elliptic_curves.ts
163
+ * - The implementation of integerToByteArray has been modified to augment the resulting byte array to a certain length.
164
+ * - The implementation of PointDecode has been modified to decode both compressed and uncompressed points by checking for correct format
165
+ * - Method isP256CurvePoint added to check whether an uncompressed point is valid
166
+ *
167
+ * @license
168
+ * Copyright 2020 Google LLC
169
+ * SPDX-License-Identifier: Apache-2.0
170
+ */
171
+ /**
172
+ * P-256 only
173
+ */
174
+ function getModulus() {
175
+ // https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf (Appendix D).
176
+ return BigInt("115792089210356248762697446949407573530086143415290314195533631308" +
177
+ "867097853951");
178
+ }
179
+ /**
180
+ * P-256 only
181
+ */
182
+ function getB() {
183
+ // https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf (Appendix D).
184
+ return BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b");
185
+ }
186
+ /** Converts byte array to bigint. */
187
+ function byteArrayToInteger(bytes) {
188
+ return BigInt("0x" + toHex(bytes));
189
+ }
190
+ /** Converts bigint to byte array. */
191
+ function integerToByteArray(i, length) {
192
+ const input = i.toString(16);
193
+ const numHexChars = length * 2;
194
+ let padding = "";
195
+ if (numHexChars < input.length) {
196
+ throw new Error(`cannot pack integer with ${input.length} hex chars into ${length} bytes`);
197
+ }
198
+ else {
199
+ padding = "0".repeat(numHexChars - input.length);
200
+ }
201
+ return fromHex(padding + input);
202
+ }
203
+ /** Returns true iff the ith bit (in lsb order) of n is set. */
204
+ function testBit(n, i) {
205
+ const m = BigInt(1) << BigInt(i);
206
+ return (n & m) !== BigInt(0);
207
+ }
208
+ /**
209
+ * Computes a modular exponent. Since JavaScript BigInt operations are not
210
+ * constant-time, information about the inputs could leak. Therefore, THIS
211
+ * METHOD SHOULD ONLY BE USED FOR POINT DECOMPRESSION.
212
+ *
213
+ * @param b base
214
+ * @param exp exponent
215
+ * @param p modulus
216
+ * @return b^exp modulo p
217
+ */
218
+ function modPow(b, exp, p) {
219
+ if (exp === BigInt(0)) {
220
+ return BigInt(1);
221
+ }
222
+ let result = b;
223
+ const exponentBitString = exp.toString(2);
224
+ for (let i = 1; i < exponentBitString.length; ++i) {
225
+ result = (result * result) % p;
226
+ if (exponentBitString[i] === "1") {
227
+ result = (result * b) % p;
228
+ }
229
+ }
230
+ return result;
231
+ }
232
+ /**
233
+ * Computes a square root modulo an odd prime. Since timing and exceptions can
234
+ * leak information about the inputs, THIS METHOD SHOULD ONLY BE USED FOR
235
+ * POINT DECOMPRESSION.
236
+ *
237
+ * @param x square
238
+ * @param p prime modulus
239
+ * @return square root of x modulo p
240
+ */
241
+ function modSqrt(x, p) {
242
+ if (p <= BigInt(0)) {
243
+ throw new Error("p must be positive");
244
+ }
245
+ const base = x % p;
246
+ // The currently supported NIST curves P-256, P-384, and P-521 all satisfy
247
+ // p % 4 == 3. However, although currently a no-op, the following check
248
+ // should be left in place in case other curves are supported in the future.
249
+ if (testBit(p, 0) && /* istanbul ignore next */ testBit(p, 1)) {
250
+ // Case p % 4 == 3 (applies to NIST curves P-256, P-384, and P-521)
251
+ // q = (p + 1) / 4
252
+ const q = (p + BigInt(1)) >> BigInt(2);
253
+ const squareRoot = modPow(base, q, p);
254
+ if ((squareRoot * squareRoot) % p !== base) {
255
+ throw new Error("could not find a modular square root");
256
+ }
257
+ return squareRoot;
258
+ }
259
+ // Skipping other elliptic curve types that require Cipolla's algorithm.
260
+ throw new Error("unsupported modulus value");
261
+ }
262
+ /**
263
+ * Computes the y-coordinate of a point on an elliptic curve given its
264
+ * x-coordinate. Since timing and exceptions can leak information about the
265
+ * inputs, THIS METHOD SHOULD ONLY BE USED FOR POINT DECOMPRESSION.
266
+ *
267
+ * P-256 only
268
+ *
269
+ * @param x x-coordinate
270
+ * @param lsb least significant bit of the y-coordinate
271
+ * @return y-coordinate
272
+ */
273
+ function getY(x, lsb) {
274
+ const p = getModulus();
275
+ const a = p - BigInt(3);
276
+ const b = getB();
277
+ const rhs = ((x * x + a) * x + b) % p;
278
+ let y = modSqrt(rhs, p);
279
+ if (lsb !== testBit(y, 0)) {
280
+ y = (p - y) % p;
281
+ }
282
+ return y;
283
+ }
284
+ /**
285
+ *
286
+ * Given x and y coordinates of a JWK, checks whether these are valid points on
287
+ * the P-256 elliptic curve.
288
+ *
289
+ * P-256 only
290
+ *
291
+ * @param x x-coordinate
292
+ * @param y y-coordinate
293
+ * @return boolean validity
294
+ */
295
+ function isP256CurvePoint(x, y) {
296
+ const p = getModulus();
297
+ const a = p - BigInt(3);
298
+ const b = getB();
299
+ const rhs = ((x * x + a) * x + b) % p;
300
+ const lhs = y ** BigInt(2) % p;
301
+ return lhs === rhs;
302
+ }
303
+ /**
304
+ * Decodes a public key in _compressed_ OR _uncompressed_ format.
305
+ * Augmented to ensure that the x and y components are padded to fit 32 bytes.
306
+ *
307
+ * P-256 only
308
+ */
309
+ function pointDecode(point) {
310
+ const fieldSize = fieldSizeInBytes();
311
+ const compressedLength = fieldSize + 1;
312
+ const uncompressedLength = 2 * fieldSize + 1;
313
+ if (point.length !== compressedLength &&
314
+ point.length !== uncompressedLength) {
315
+ throw new Error("Invalid length: point is not in compressed or uncompressed format");
316
+ }
317
+ // Decodes point if its length and first bit match the compressed format
318
+ if ((point[0] === 2 || point[0] === 3) && point.length == compressedLength) {
319
+ const lsb = point[0] === 3; // point[0] must be 2 (false) or 3 (true).
320
+ const x = byteArrayToInteger(point.subarray(1, point.length));
321
+ const p = getModulus();
322
+ if (x < BigInt(0) || x >= p) {
323
+ throw new Error("x is out of range");
324
+ }
325
+ const y = getY(x, lsb);
326
+ const result = {
327
+ kty: "EC",
328
+ crv: "P-256",
329
+ x: toBase64(integerToByteArray(x, 32)),
330
+ y: toBase64(integerToByteArray(y, 32)),
331
+ ext: true,
332
+ };
333
+ return result;
334
+ // Decodes point if its length and first bit match the uncompressed format
335
+ }
336
+ else if (point[0] === 4 && point.length == uncompressedLength) {
337
+ const x = byteArrayToInteger(point.subarray(1, fieldSize + 1));
338
+ const y = byteArrayToInteger(point.subarray(fieldSize + 1, 2 * fieldSize + 1));
339
+ const p = getModulus();
340
+ if (x < BigInt(0) ||
341
+ x >= p ||
342
+ y < BigInt(0) ||
343
+ y >= p ||
344
+ !isP256CurvePoint(x, y)) {
345
+ throw new Error("invalid uncompressed x and y coordinates");
346
+ }
347
+ const result = {
348
+ kty: "EC",
349
+ crv: "P-256",
350
+ x: toBase64(integerToByteArray(x, 32)),
351
+ y: toBase64(integerToByteArray(y, 32)),
352
+ ext: true,
353
+ };
354
+ return result;
355
+ }
356
+ throw new Error("invalid format");
357
+ }
358
+ /**
359
+ * P-256 only
360
+ */
361
+ function fieldSizeInBytes() {
362
+ return 32;
363
+ }
364
+
365
+ export { ApiKeyStamper, SignatureFormat, detectRuntime, pointDecode, signWithApiKey };
366
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../src/_kernel/stamping.ts","../src/_kernel/stamper.ts","../src/tink/bytes.ts","../src/tink/elliptic_curves.ts"],"sourcesContent":[null,null,null,null],"names":["Bytes.toHex","Bytes.fromHex","Bytes.toBase64"],"mappings":";;;AAEM,SAAU,iBAAiB,CAC/B,eAAkB,EAClB,gBAAwB,EAAA;AAExB,IAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE;AAC9C;;ACPA;AAQA,MAAM,eAAe,GAAG,SAAS;IAUrB;AAAZ,CAAA,UAAY,eAAe,EAAA;AACzB,IAAA,eAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACX,IAAA,eAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACb,CAAC,EAHW,eAAe,KAAf,eAAe,GAAA,EAAA,CAAA,CAAA;AAK3B,MAAM,sBAAsB,GAC1B,OAAO,MAAM,KAAK,WAAW;AAC7B,IAAA,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW;IACtC,OAAO,MAAM,KAAK,WAAW;AAC7B,IAAA,OAAO,MAAM,CAAC,MAAM,KAAK,WAAW;AAEtC,MAAM,MAAM,GACV,OAAO,OAAO,KAAK,WAAW;IAC9B,OAAO,CAAC,QAAQ,IAAI,IAAI;AACxB,IAAA,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI;AAExB,MAAM,aAAa,GAAG,MAAc;IACzC,IAAI,sBAAsB,EAAE;AAC1B,QAAA,OAAO,SAAS;IAClB;IAEA,IAAI,MAAM,EAAE;AACV,QAAA,OAAO,MAAM;IACf;AAEA,IAAA,OAAO,QAAQ;AACjB;AAEO,MAAM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,IAAI,CAAC;AACN,YAAA,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,EACvB;AACA,YAAA,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC;QAC7D;AACA,QAAA,MAAM,MAAM,GAAe;AACzB,YAAA,GAAG,EAAE,IAAI;AACT,YAAA,GAAG,EAAE,OAAO;AACZ,YAAA,CAAC,EAAEA,QAAc,CAAC,kBAAkB,CAAC,CAAC,EAAE,EAAE,CAAqB,CAAC;AAChE,YAAA,CAAC,EAAEA,QAAc,CAAC,kBAAkB,CAAC,CAAC,EAAE,EAAE,CAAqB,CAAC;AAChE,YAAA,GAAG,EAAE,IAAI;SACV;AACD,QAAA,OAAO,MAAM;IACf;AACA,IAAA,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC;AACnC;AAEA;;AAEG;AACH,SAAS,gBAAgB,GAAA;AACvB,IAAA,OAAO,EAAE;AACX;;;;"}
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ var crypto = require('crypto');
4
+ var utils = require('./utils-65MgUjOA.js');
5
+ require('./index.js');
6
+ require('@0xkey-io/encoding');
7
+ require('@0xkey-io/crypto');
8
+
9
+ function _interopNamespaceDefault(e) {
10
+ var n = Object.create(null);
11
+ if (e) {
12
+ Object.keys(e).forEach(function (k) {
13
+ if (k !== 'default') {
14
+ var d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: function () { return e[k]; }
18
+ });
19
+ }
20
+ });
21
+ }
22
+ n.default = e;
23
+ return Object.freeze(n);
24
+ }
25
+
26
+ var crypto__namespace = /*#__PURE__*/_interopNamespaceDefault(crypto);
27
+
28
+ const signWithApiKey = async (input) => {
29
+ const { content, publicKey, privateKey } = input;
30
+ const privateKeyObject = crypto__namespace.createPrivateKey({
31
+ // @ts-expect-error -- the key can be a JWK object since Node v15.12.0
32
+ // https://nodejs.org/api/crypto.html#cryptocreateprivatekeykey
33
+ key: utils.convertZeroXKeyApiKeyToJwk({
34
+ uncompressedPrivateKeyHex: privateKey,
35
+ compressedPublicKeyHex: publicKey,
36
+ }),
37
+ format: "jwk",
38
+ });
39
+ const sign = crypto__namespace.createSign("SHA256");
40
+ sign.write(Buffer.from(content));
41
+ sign.end();
42
+ return sign.sign(privateKeyObject, "hex");
43
+ };
44
+
45
+ exports.signWithApiKey = signWithApiKey;
46
+ //# sourceMappingURL=nodecrypto-BEvYdLDk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodecrypto-BEvYdLDk.js","sources":["../src/nodecrypto.ts"],"sourcesContent":[null],"names":["crypto","convertZeroXKeyApiKeyToJwk"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;MAGa,cAAc,GAAG,OAAO,KAIpC,KAAqB;IACpB,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,KAAK;AAEhD,IAAA,MAAM,gBAAgB,GAAGA,iBAAM,CAAC,gBAAgB,CAAC;;;QAG/C,GAAG,EAAEC,gCAA0B,CAAC;AAC9B,YAAA,yBAAyB,EAAE,UAAU;AACrC,YAAA,sBAAsB,EAAE,SAAS;SAClC,CAAC;AACF,QAAA,MAAM,EAAE,KAAK;AACd,KAAA,CAAC;IAEF,MAAM,IAAI,GAAGD,iBAAM,CAAC,UAAU,CAAC,QAAQ,CAAC;IACxC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAChC,IAAI,CAAC,GAAG,EAAE;IAEV,OAAO,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,KAAK,CAAC;AAC3C;;;;"}
@@ -0,0 +1,25 @@
1
+ import * as crypto from 'crypto';
2
+ import { c as convertZeroXKeyApiKeyToJwk } from './utils-U6G_myeu.js';
3
+ import './index.mjs';
4
+ import '@0xkey-io/encoding';
5
+ import '@0xkey-io/crypto';
6
+
7
+ const signWithApiKey = async (input) => {
8
+ const { content, publicKey, privateKey } = input;
9
+ const privateKeyObject = crypto.createPrivateKey({
10
+ // @ts-expect-error -- the key can be a JWK object since Node v15.12.0
11
+ // https://nodejs.org/api/crypto.html#cryptocreateprivatekeykey
12
+ key: convertZeroXKeyApiKeyToJwk({
13
+ uncompressedPrivateKeyHex: privateKey,
14
+ compressedPublicKeyHex: publicKey,
15
+ }),
16
+ format: "jwk",
17
+ });
18
+ const sign = crypto.createSign("SHA256");
19
+ sign.write(Buffer.from(content));
20
+ sign.end();
21
+ return sign.sign(privateKeyObject, "hex");
22
+ };
23
+
24
+ export { signWithApiKey };
25
+ //# sourceMappingURL=nodecrypto-CWFu007J.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodecrypto-CWFu007J.js","sources":["../src/nodecrypto.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;MAGa,cAAc,GAAG,OAAO,KAIpC,KAAqB;IACpB,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,KAAK;AAEhD,IAAA,MAAM,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC;;;QAG/C,GAAG,EAAE,0BAA0B,CAAC;AAC9B,YAAA,yBAAyB,EAAE,UAAU;AACrC,YAAA,sBAAsB,EAAE,SAAS;SAClC,CAAC;AACF,QAAA,MAAM,EAAE,KAAK;AACd,KAAA,CAAC;IAEF,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC;IACxC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAChC,IAAI,CAAC,GAAG,EAAE;IAEV,OAAO,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,KAAK,CAAC;AAC3C;;;;"}
@@ -0,0 +1,6 @@
1
+ export declare const signWithApiKey: (input: {
2
+ content: string;
3
+ publicKey: string;
4
+ privateKey: string;
5
+ }) => Promise<string>;
6
+ //# sourceMappingURL=nodecrypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodecrypto.d.ts","sourceRoot":"","sources":["../src/nodecrypto.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,UAAiB;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,KAAG,QAAQ,MAAM,CAkBjB,CAAC"}
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ var p256 = require('@noble/curves/p256');
4
+ var sha256Uint8array = require('sha256-uint8array');
5
+ var encoding = require('@0xkey-io/encoding');
6
+
7
+ const signWithApiKey = async (input) => {
8
+ const publicKey = p256.p256.getPublicKey(input.privateKey, true);
9
+ // Public key in the usual 02 or 03 + 64 hex digits
10
+ const publicKeyString = encoding.uint8ArrayToHexString(publicKey);
11
+ if (publicKeyString != input.publicKey) {
12
+ throw new Error(`Bad API key. Expected to get public key ${input.publicKey}, got ${publicKeyString}`);
13
+ }
14
+ const hash = sha256Uint8array.createHash().update(input.content).digest();
15
+ const signature = p256.p256.sign(hash, input.privateKey);
16
+ return signature.toDERHex();
17
+ };
18
+
19
+ exports.signWithApiKey = signWithApiKey;
20
+ //# sourceMappingURL=purejs-BG8ixYIu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"purejs-BG8ixYIu.js","sources":["../src/purejs.ts"],"sourcesContent":[null],"names":["p256","uint8ArrayToHexString","createHash"],"mappings":";;;;;;MAIa,cAAc,GAAG,OAAO,KAIpC,KAAqB;AACpB,IAAA,MAAM,SAAS,GAAGA,SAAI,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC;;AAG3D,IAAA,MAAM,eAAe,GAAGC,8BAAqB,CAAC,SAAS,CAAC;AAExD,IAAA,IAAI,eAAe,IAAI,KAAK,CAAC,SAAS,EAAE;QACtC,MAAM,IAAI,KAAK,CACb,CAAA,wCAAA,EAA2C,KAAK,CAAC,SAAS,CAAA,MAAA,EAAS,eAAe,CAAA,CAAE,CACrF;IACH;AAEA,IAAA,MAAM,IAAI,GAAGC,2BAAU,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE;AACxD,IAAA,MAAM,SAAS,GAAGF,SAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC;AACnD,IAAA,OAAO,SAAS,CAAC,QAAQ,EAAE;AAC7B;;;;"}
@@ -0,0 +1,18 @@
1
+ import { p256 } from '@noble/curves/p256';
2
+ import { createHash } from 'sha256-uint8array';
3
+ import { uint8ArrayToHexString } from '@0xkey-io/encoding';
4
+
5
+ const signWithApiKey = async (input) => {
6
+ const publicKey = p256.getPublicKey(input.privateKey, true);
7
+ // Public key in the usual 02 or 03 + 64 hex digits
8
+ const publicKeyString = uint8ArrayToHexString(publicKey);
9
+ if (publicKeyString != input.publicKey) {
10
+ throw new Error(`Bad API key. Expected to get public key ${input.publicKey}, got ${publicKeyString}`);
11
+ }
12
+ const hash = createHash().update(input.content).digest();
13
+ const signature = p256.sign(hash, input.privateKey);
14
+ return signature.toDERHex();
15
+ };
16
+
17
+ export { signWithApiKey };
18
+ //# sourceMappingURL=purejs-XGKef2yb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"purejs-XGKef2yb.js","sources":["../src/purejs.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;MAIa,cAAc,GAAG,OAAO,KAIpC,KAAqB;AACpB,IAAA,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC;;AAG3D,IAAA,MAAM,eAAe,GAAG,qBAAqB,CAAC,SAAS,CAAC;AAExD,IAAA,IAAI,eAAe,IAAI,KAAK,CAAC,SAAS,EAAE;QACtC,MAAM,IAAI,KAAK,CACb,CAAA,wCAAA,EAA2C,KAAK,CAAC,SAAS,CAAA,MAAA,EAAS,eAAe,CAAA,CAAE,CACrF;IACH;AAEA,IAAA,MAAM,IAAI,GAAG,UAAU,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE;AACxD,IAAA,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC;AACnD,IAAA,OAAO,SAAS,CAAC,QAAQ,EAAE;AAC7B;;;;"}
@@ -0,0 +1,6 @@
1
+ export declare const signWithApiKey: (input: {
2
+ content: string;
3
+ publicKey: string;
4
+ privateKey: string;
5
+ }) => Promise<string>;
6
+ //# sourceMappingURL=purejs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"purejs.d.ts","sourceRoot":"","sources":["../src/purejs.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,UAAiB;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,KAAG,QAAQ,MAAM,CAejB,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Code modified from https://github.com/google/tink/blob/6f74b99a2bfe6677e3670799116a57268fd067fa/javascript/subtle/bytes.ts
3
+ *
4
+ * @license
5
+ * Copyright 2020 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ /**
9
+ * Converts the hex string to a byte array.
10
+ *
11
+ * @param hex the input
12
+ * @return the byte array output
13
+ * @throws {!Error}
14
+ * @static
15
+ */
16
+ export declare function fromHex(hex: string): Uint8Array;
17
+ /**
18
+ * Converts a byte array to hex.
19
+ *
20
+ * @param bytes the byte array input
21
+ * @return hex the output
22
+ * @static
23
+ */
24
+ export declare function toHex(bytes: Uint8Array): string;
25
+ /**
26
+ * Base64 encode a byte array.
27
+ *
28
+ * @param bytes the byte array input
29
+ * @param opt_webSafe True indicates we should use the alternative
30
+ * alphabet, which does not require escaping for use in URLs.
31
+ * @return base64 output
32
+ * @static
33
+ */
34
+ export declare function toBase64(bytes: Uint8Array, opt_webSafe?: boolean): string;
35
+ /**
36
+ * Turns a byte array into the string given by the concatenation of the
37
+ * characters to which the numbers correspond. Each byte is corresponding to a
38
+ * character. Does not support multi-byte characters.
39
+ *
40
+ * @param bytes Array of numbers representing
41
+ * characters.
42
+ * @return Stringification of the array.
43
+ */
44
+ export declare function toByteString(bytes: Uint8Array): string;
45
+ //# sourceMappingURL=bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../src/tink/bytes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAS/C;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAO/C;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,OAAO,GAAG,MAAM,CASzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAMtD"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Code modified from https://github.com/google/tink/blob/6f74b99a2bfe6677e3670799116a57268fd067fa/javascript/subtle/elliptic_curves.ts
3
+ * - The implementation of integerToByteArray has been modified to augment the resulting byte array to a certain length.
4
+ * - The implementation of PointDecode has been modified to decode both compressed and uncompressed points by checking for correct format
5
+ * - Method isP256CurvePoint added to check whether an uncompressed point is valid
6
+ *
7
+ * @license
8
+ * Copyright 2020 Google LLC
9
+ * SPDX-License-Identifier: Apache-2.0
10
+ */
11
+ /**
12
+ * Decodes a public key in _compressed_ OR _uncompressed_ format.
13
+ * Augmented to ensure that the x and y components are padded to fit 32 bytes.
14
+ *
15
+ * P-256 only
16
+ */
17
+ export declare function pointDecode(point: Uint8Array): JsonWebKey;
18
+ //# sourceMappingURL=elliptic_curves.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elliptic_curves.d.ts","sourceRoot":"","sources":["../../src/tink/elliptic_curves.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAsJH;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAuDzD"}
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ var index = require('./index.js');
4
+ var encoding = require('@0xkey-io/encoding');
5
+
6
+ /**
7
+ * Converts a ZeroXKey API key pair into a JSON Web Key (JWK) format.
8
+ * This function accepts P-256 API keys only.
9
+ *
10
+ * @param {Object} input - The ZeroXKey API key components.
11
+ * @param {string} input.uncompressedPrivateKeyHex - Hexadecimal-encoded uncompressed private key (32-byte scalar).
12
+ * @param {string} input.compressedPublicKeyHex - Hexadecimal-encoded compressed public key (33 bytes).
13
+ * @returns {JsonWebKey} A JSON Web Key object representing the EC P-256 key.
14
+ */
15
+ function convertZeroXKeyApiKeyToJwk(input) {
16
+ const { uncompressedPrivateKeyHex, compressedPublicKeyHex } = input;
17
+ let jwk;
18
+ try {
19
+ jwk = index.pointDecode(encoding.uint8ArrayFromHexString(compressedPublicKeyHex));
20
+ }
21
+ catch (e) {
22
+ throw new Error(`unable to load API key: invalid public key. Did you switch your public and private key by accident? Is your public key a valid, compressed P-256 public key?`);
23
+ }
24
+ // Ensure that d is sufficiently padded
25
+ jwk.d = encoding.hexStringToBase64url(uncompressedPrivateKeyHex, encoding.DEFAULT_JWK_MEMBER_BYTE_LENGTH);
26
+ return jwk;
27
+ }
28
+
29
+ exports.convertZeroXKeyApiKeyToJwk = convertZeroXKeyApiKeyToJwk;
30
+ //# sourceMappingURL=utils-65MgUjOA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils-65MgUjOA.js","sources":["../src/utils.ts"],"sourcesContent":[null],"names":["pointDecode","uint8ArrayFromHexString","hexStringToBase64url","DEFAULT_JWK_MEMBER_BYTE_LENGTH"],"mappings":";;;;;AAOA;;;;;;;;AAQG;AACG,SAAU,0BAA0B,CAAC,KAG1C,EAAA;AACC,IAAA,MAAM,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,GAAG,KAAK;AAEnE,IAAA,IAAI,GAAG;AACP,IAAA,IAAI;QACF,GAAG,GAAGA,iBAAW,CAACC,gCAAuB,CAAC,sBAAsB,CAAC,CAAC;IACpE;IAAE,OAAO,CAAC,EAAE;AACV,QAAA,MAAM,IAAI,KAAK,CACb,CAAA,4JAAA,CAA8J,CAC/J;IACH;;IAGA,GAAG,CAAC,CAAC,GAAGC,6BAAoB,CAC1B,yBAAyB,EACzBC,uCAA8B,CAC/B;AAED,IAAA,OAAO,GAAG;AACZ;;;;"}