@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/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # @0xkey-io/api-key-stamper
2
+
3
+ ## 0.1.0
4
+
5
+ Initial release.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 0xkey
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ ---
2
+ title: "API Key Stamper"
3
+ ---
4
+
5
+ # @0xkey-io/api-key-stamper
6
+
7
+ [![npm](https://img.shields.io/npm/v/@0xkey-io/api-key-stamper?color=%234C48FF)](https://www.npmjs.com/package/@0xkey-io/api-key-stamper)
8
+
9
+ This package contains functions to stamp a ZeroXKey request. It is meant to be used with [`@0xkey-io/http`](https://www.npmjs.com/package/@0xkey-io/http)
10
+
11
+ Usage:
12
+
13
+ ```ts
14
+ import { ApiKeyStamper } from "@0xkey-io/api-key-stamper";
15
+ import { ZeroXKeyClient } from "@0xkey-io/http";
16
+
17
+ const stamper = new ApiKeyStamper({
18
+ apiPublicKey: "...",
19
+ apiPrivateKey: "...",
20
+ });
21
+
22
+ const httpClient = new ZeroXKeyClient(
23
+ { baseUrl: "https://api.0xkey.com" },
24
+ stamper,
25
+ );
26
+ ```
@@ -0,0 +1,29 @@
1
+ /// <reference lib="dom" />
2
+ export type Runtime = "browser" | "node" | "purejs";
3
+ export type TApiKeyStamperConfig = {
4
+ apiPublicKey: string;
5
+ apiPrivateKey: string;
6
+ runtimeOverride?: Runtime | undefined;
7
+ };
8
+ export declare enum SignatureFormat {
9
+ Der = "der",
10
+ Raw = "raw"
11
+ }
12
+ export declare const detectRuntime: () => Runtime;
13
+ export declare const signWithApiKey: (input: {
14
+ content: string;
15
+ publicKey: string;
16
+ privateKey: string;
17
+ }, runtimeOverride?: Runtime | undefined) => Promise<string>;
18
+ export declare class ApiKeyStamper {
19
+ apiPublicKey: string;
20
+ apiPrivateKey: string;
21
+ runtimeOverride?: Runtime | undefined;
22
+ constructor(config: TApiKeyStamperConfig);
23
+ stamp(payload: string): Promise<{
24
+ stampHeaderName: "X-Stamp";
25
+ stampHeaderValue: string;
26
+ }>;
27
+ sign(payload: string, format: SignatureFormat): Promise<string>;
28
+ }
29
+ //# sourceMappingURL=stamper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stamper.d.ts","sourceRoot":"","sources":["../../src/_kernel/stamper.ts"],"names":[],"mappings":";AAUA,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEpD,MAAM,MAAM,oBAAoB,GAAG;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACvC,CAAC;AAEF,oBAAY,eAAe;IACzB,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAaD,eAAO,MAAM,aAAa,QAAO,OAUhC,CAAC;AAEF,eAAO,MAAM,cAAc,UAClB;IACL,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,oBACiB,OAAO,GAAG,SAAS,KACpC,QAAQ,MAAM,CAahB,CAAC;AAEF,qBAAa,aAAa;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;gBAE1B,MAAM,EAAE,oBAAoB;IAMlC,KAAK,CAAC,OAAO,EAAE,MAAM;;;;IAsBrB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe;CA4BpD"}
@@ -0,0 +1,6 @@
1
+ export declare const STAMP_HEADER_API_KEY = "X-Stamp";
2
+ export declare function createStampResult<N extends string>(stampHeaderName: N, stampHeaderValue: string): {
3
+ stampHeaderName: N;
4
+ stampHeaderValue: string;
5
+ };
6
+ //# sourceMappingURL=stamping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stamping.d.ts","sourceRoot":"","sources":["../../src/_kernel/stamping.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,YAAY,CAAC;AAE9C,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,eAAe,EAAE,CAAC,EAClB,gBAAgB,EAAE,MAAM,GACvB;IAAE,eAAe,EAAE,CAAC,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAE,CAElD"}
@@ -0,0 +1,3 @@
1
+ export { ApiKeyStamper, SignatureFormat, detectRuntime, signWithApiKey, type Runtime, type TApiKeyStamperConfig, } from "./_kernel/stamper";
2
+ export { pointDecode } from "./tink/elliptic_curves";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,cAAc,EACd,KAAK,OAAO,EACZ,KAAK,oBAAoB,GAC1B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,371 @@
1
+ 'use strict';
2
+
3
+ var encoding = require('@0xkey-io/encoding');
4
+ var crypto$1 = require('@0xkey-io/crypto');
5
+
6
+ function createStampResult(stampHeaderName, stampHeaderValue) {
7
+ return { stampHeaderName, stampHeaderValue };
8
+ }
9
+
10
+ /// <reference lib="dom" />
11
+ const stampHeaderName = "X-Stamp";
12
+ exports.SignatureFormat = void 0;
13
+ (function (SignatureFormat) {
14
+ SignatureFormat["Der"] = "der";
15
+ SignatureFormat["Raw"] = "raw";
16
+ })(exports.SignatureFormat || (exports.SignatureFormat = {}));
17
+ const isCryptoEnabledBrowser = typeof window !== "undefined" &&
18
+ typeof window.document !== "undefined" &&
19
+ typeof crypto !== "undefined" &&
20
+ typeof crypto.subtle !== "undefined";
21
+ const isNode = typeof process !== "undefined" &&
22
+ process.versions != null &&
23
+ process.versions.node != null;
24
+ const detectRuntime = () => {
25
+ if (isCryptoEnabledBrowser) {
26
+ return "browser";
27
+ }
28
+ if (isNode) {
29
+ return "node";
30
+ }
31
+ return "purejs";
32
+ };
33
+ const signWithApiKey = async (input, runtimeOverride) => {
34
+ const runtime = runtimeOverride ?? detectRuntime();
35
+ switch (runtime) {
36
+ case "browser":
37
+ return (await Promise.resolve().then(function () { return require('./webcrypto-BM8R-Kt_.js'); })).signWithApiKey(input);
38
+ case "node":
39
+ return (await Promise.resolve().then(function () { return require('./nodecrypto-BEvYdLDk.js'); })).signWithApiKey(input);
40
+ case "purejs":
41
+ return (await Promise.resolve().then(function () { return require('./purejs-BG8ixYIu.js'); })).signWithApiKey(input);
42
+ default:
43
+ throw new Error(`Unsupported runtime: ${runtime}`);
44
+ }
45
+ };
46
+ class ApiKeyStamper {
47
+ constructor(config) {
48
+ this.apiPublicKey = config.apiPublicKey;
49
+ this.apiPrivateKey = config.apiPrivateKey;
50
+ this.runtimeOverride = config.runtimeOverride;
51
+ }
52
+ async stamp(payload) {
53
+ const signature = await signWithApiKey({
54
+ publicKey: this.apiPublicKey,
55
+ privateKey: this.apiPrivateKey,
56
+ content: payload,
57
+ }, this.runtimeOverride);
58
+ const stamp = {
59
+ publicKey: this.apiPublicKey,
60
+ scheme: "SIGNATURE_SCHEME_TK_API_P256",
61
+ signature,
62
+ };
63
+ return createStampResult(stampHeaderName, encoding.stringToBase64urlString(JSON.stringify(stamp)));
64
+ }
65
+ async sign(payload, format) {
66
+ switch (format) {
67
+ case exports.SignatureFormat.Raw: {
68
+ const derSignature = await signWithApiKey({
69
+ publicKey: this.apiPublicKey,
70
+ privateKey: this.apiPrivateKey,
71
+ content: payload,
72
+ }, this.runtimeOverride);
73
+ const raw = crypto$1.fromDerSignature(derSignature);
74
+ return encoding.uint8ArrayToHexString(raw);
75
+ }
76
+ case exports.SignatureFormat.Der: {
77
+ return signWithApiKey({
78
+ publicKey: this.apiPublicKey,
79
+ privateKey: this.apiPrivateKey,
80
+ content: payload,
81
+ }, this.runtimeOverride);
82
+ }
83
+ default:
84
+ throw new Error(`Unsupported signature format: ${format}`);
85
+ }
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Code modified from https://github.com/google/tink/blob/6f74b99a2bfe6677e3670799116a57268fd067fa/javascript/subtle/bytes.ts
91
+ *
92
+ * @license
93
+ * Copyright 2020 Google LLC
94
+ * SPDX-License-Identifier: Apache-2.0
95
+ */
96
+ /**
97
+ * Converts the hex string to a byte array.
98
+ *
99
+ * @param hex the input
100
+ * @return the byte array output
101
+ * @throws {!Error}
102
+ * @static
103
+ */
104
+ function fromHex(hex) {
105
+ if (hex.length % 2 != 0) {
106
+ throw new Error("Hex string length must be multiple of 2");
107
+ }
108
+ const arr = new Uint8Array(hex.length / 2);
109
+ for (let i = 0; i < hex.length; i += 2) {
110
+ arr[i / 2] = parseInt(hex.substring(i, i + 2), 16);
111
+ }
112
+ return arr;
113
+ }
114
+ /**
115
+ * Converts a byte array to hex.
116
+ *
117
+ * @param bytes the byte array input
118
+ * @return hex the output
119
+ * @static
120
+ */
121
+ function toHex(bytes) {
122
+ let result = "";
123
+ for (let i = 0; i < bytes.length; i++) {
124
+ const hexByte = bytes[i].toString(16);
125
+ result += hexByte.length > 1 ? hexByte : "0" + hexByte;
126
+ }
127
+ return result;
128
+ }
129
+ /**
130
+ * Base64 encode a byte array.
131
+ *
132
+ * @param bytes the byte array input
133
+ * @param opt_webSafe True indicates we should use the alternative
134
+ * alphabet, which does not require escaping for use in URLs.
135
+ * @return base64 output
136
+ * @static
137
+ */
138
+ function toBase64(bytes, opt_webSafe) {
139
+ const encoded = btoa(
140
+ /* padding */
141
+ toByteString(bytes)).replace(/=/g, "");
142
+ {
143
+ return encoded.replace(/\+/g, "-").replace(/\//g, "_");
144
+ }
145
+ }
146
+ /**
147
+ * Turns a byte array into the string given by the concatenation of the
148
+ * characters to which the numbers correspond. Each byte is corresponding to a
149
+ * character. Does not support multi-byte characters.
150
+ *
151
+ * @param bytes Array of numbers representing
152
+ * characters.
153
+ * @return Stringification of the array.
154
+ */
155
+ function toByteString(bytes) {
156
+ let str = "";
157
+ for (let i = 0; i < bytes.length; i += 1) {
158
+ str += String.fromCharCode(bytes[i]);
159
+ }
160
+ return str;
161
+ }
162
+
163
+ /**
164
+ * Code modified from https://github.com/google/tink/blob/6f74b99a2bfe6677e3670799116a57268fd067fa/javascript/subtle/elliptic_curves.ts
165
+ * - The implementation of integerToByteArray has been modified to augment the resulting byte array to a certain length.
166
+ * - The implementation of PointDecode has been modified to decode both compressed and uncompressed points by checking for correct format
167
+ * - Method isP256CurvePoint added to check whether an uncompressed point is valid
168
+ *
169
+ * @license
170
+ * Copyright 2020 Google LLC
171
+ * SPDX-License-Identifier: Apache-2.0
172
+ */
173
+ /**
174
+ * P-256 only
175
+ */
176
+ function getModulus() {
177
+ // https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf (Appendix D).
178
+ return BigInt("115792089210356248762697446949407573530086143415290314195533631308" +
179
+ "867097853951");
180
+ }
181
+ /**
182
+ * P-256 only
183
+ */
184
+ function getB() {
185
+ // https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf (Appendix D).
186
+ return BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b");
187
+ }
188
+ /** Converts byte array to bigint. */
189
+ function byteArrayToInteger(bytes) {
190
+ return BigInt("0x" + toHex(bytes));
191
+ }
192
+ /** Converts bigint to byte array. */
193
+ function integerToByteArray(i, length) {
194
+ const input = i.toString(16);
195
+ const numHexChars = length * 2;
196
+ let padding = "";
197
+ if (numHexChars < input.length) {
198
+ throw new Error(`cannot pack integer with ${input.length} hex chars into ${length} bytes`);
199
+ }
200
+ else {
201
+ padding = "0".repeat(numHexChars - input.length);
202
+ }
203
+ return fromHex(padding + input);
204
+ }
205
+ /** Returns true iff the ith bit (in lsb order) of n is set. */
206
+ function testBit(n, i) {
207
+ const m = BigInt(1) << BigInt(i);
208
+ return (n & m) !== BigInt(0);
209
+ }
210
+ /**
211
+ * Computes a modular exponent. Since JavaScript BigInt operations are not
212
+ * constant-time, information about the inputs could leak. Therefore, THIS
213
+ * METHOD SHOULD ONLY BE USED FOR POINT DECOMPRESSION.
214
+ *
215
+ * @param b base
216
+ * @param exp exponent
217
+ * @param p modulus
218
+ * @return b^exp modulo p
219
+ */
220
+ function modPow(b, exp, p) {
221
+ if (exp === BigInt(0)) {
222
+ return BigInt(1);
223
+ }
224
+ let result = b;
225
+ const exponentBitString = exp.toString(2);
226
+ for (let i = 1; i < exponentBitString.length; ++i) {
227
+ result = (result * result) % p;
228
+ if (exponentBitString[i] === "1") {
229
+ result = (result * b) % p;
230
+ }
231
+ }
232
+ return result;
233
+ }
234
+ /**
235
+ * Computes a square root modulo an odd prime. Since timing and exceptions can
236
+ * leak information about the inputs, THIS METHOD SHOULD ONLY BE USED FOR
237
+ * POINT DECOMPRESSION.
238
+ *
239
+ * @param x square
240
+ * @param p prime modulus
241
+ * @return square root of x modulo p
242
+ */
243
+ function modSqrt(x, p) {
244
+ if (p <= BigInt(0)) {
245
+ throw new Error("p must be positive");
246
+ }
247
+ const base = x % p;
248
+ // The currently supported NIST curves P-256, P-384, and P-521 all satisfy
249
+ // p % 4 == 3. However, although currently a no-op, the following check
250
+ // should be left in place in case other curves are supported in the future.
251
+ if (testBit(p, 0) && /* istanbul ignore next */ testBit(p, 1)) {
252
+ // Case p % 4 == 3 (applies to NIST curves P-256, P-384, and P-521)
253
+ // q = (p + 1) / 4
254
+ const q = (p + BigInt(1)) >> BigInt(2);
255
+ const squareRoot = modPow(base, q, p);
256
+ if ((squareRoot * squareRoot) % p !== base) {
257
+ throw new Error("could not find a modular square root");
258
+ }
259
+ return squareRoot;
260
+ }
261
+ // Skipping other elliptic curve types that require Cipolla's algorithm.
262
+ throw new Error("unsupported modulus value");
263
+ }
264
+ /**
265
+ * Computes the y-coordinate of a point on an elliptic curve given its
266
+ * x-coordinate. Since timing and exceptions can leak information about the
267
+ * inputs, THIS METHOD SHOULD ONLY BE USED FOR POINT DECOMPRESSION.
268
+ *
269
+ * P-256 only
270
+ *
271
+ * @param x x-coordinate
272
+ * @param lsb least significant bit of the y-coordinate
273
+ * @return y-coordinate
274
+ */
275
+ function getY(x, lsb) {
276
+ const p = getModulus();
277
+ const a = p - BigInt(3);
278
+ const b = getB();
279
+ const rhs = ((x * x + a) * x + b) % p;
280
+ let y = modSqrt(rhs, p);
281
+ if (lsb !== testBit(y, 0)) {
282
+ y = (p - y) % p;
283
+ }
284
+ return y;
285
+ }
286
+ /**
287
+ *
288
+ * Given x and y coordinates of a JWK, checks whether these are valid points on
289
+ * the P-256 elliptic curve.
290
+ *
291
+ * P-256 only
292
+ *
293
+ * @param x x-coordinate
294
+ * @param y y-coordinate
295
+ * @return boolean validity
296
+ */
297
+ function isP256CurvePoint(x, y) {
298
+ const p = getModulus();
299
+ const a = p - BigInt(3);
300
+ const b = getB();
301
+ const rhs = ((x * x + a) * x + b) % p;
302
+ const lhs = y ** BigInt(2) % p;
303
+ return lhs === rhs;
304
+ }
305
+ /**
306
+ * Decodes a public key in _compressed_ OR _uncompressed_ format.
307
+ * Augmented to ensure that the x and y components are padded to fit 32 bytes.
308
+ *
309
+ * P-256 only
310
+ */
311
+ function pointDecode(point) {
312
+ const fieldSize = fieldSizeInBytes();
313
+ const compressedLength = fieldSize + 1;
314
+ const uncompressedLength = 2 * fieldSize + 1;
315
+ if (point.length !== compressedLength &&
316
+ point.length !== uncompressedLength) {
317
+ throw new Error("Invalid length: point is not in compressed or uncompressed format");
318
+ }
319
+ // Decodes point if its length and first bit match the compressed format
320
+ if ((point[0] === 2 || point[0] === 3) && point.length == compressedLength) {
321
+ const lsb = point[0] === 3; // point[0] must be 2 (false) or 3 (true).
322
+ const x = byteArrayToInteger(point.subarray(1, point.length));
323
+ const p = getModulus();
324
+ if (x < BigInt(0) || x >= p) {
325
+ throw new Error("x is out of range");
326
+ }
327
+ const y = getY(x, lsb);
328
+ const result = {
329
+ kty: "EC",
330
+ crv: "P-256",
331
+ x: toBase64(integerToByteArray(x, 32)),
332
+ y: toBase64(integerToByteArray(y, 32)),
333
+ ext: true,
334
+ };
335
+ return result;
336
+ // Decodes point if its length and first bit match the uncompressed format
337
+ }
338
+ else if (point[0] === 4 && point.length == uncompressedLength) {
339
+ const x = byteArrayToInteger(point.subarray(1, fieldSize + 1));
340
+ const y = byteArrayToInteger(point.subarray(fieldSize + 1, 2 * fieldSize + 1));
341
+ const p = getModulus();
342
+ if (x < BigInt(0) ||
343
+ x >= p ||
344
+ y < BigInt(0) ||
345
+ y >= p ||
346
+ !isP256CurvePoint(x, y)) {
347
+ throw new Error("invalid uncompressed x and y coordinates");
348
+ }
349
+ const result = {
350
+ kty: "EC",
351
+ crv: "P-256",
352
+ x: toBase64(integerToByteArray(x, 32)),
353
+ y: toBase64(integerToByteArray(y, 32)),
354
+ ext: true,
355
+ };
356
+ return result;
357
+ }
358
+ throw new Error("invalid format");
359
+ }
360
+ /**
361
+ * P-256 only
362
+ */
363
+ function fieldSizeInBytes() {
364
+ return 32;
365
+ }
366
+
367
+ exports.ApiKeyStamper = ApiKeyStamper;
368
+ exports.detectRuntime = detectRuntime;
369
+ exports.pointDecode = pointDecode;
370
+ exports.signWithApiKey = signWithApiKey;
371
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/_kernel/stamping.ts","../src/_kernel/stamper.ts","../src/tink/bytes.ts","../src/tink/elliptic_curves.ts"],"sourcesContent":[null,null,null,null],"names":["SignatureFormat","stringToBase64urlString","fromDerSignature","uint8ArrayTo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