@0xkey-io/indexed-db-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.
- package/CHANGELOG.md +5 -0
- package/LICENSE +201 -0
- package/README.md +25 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +214 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +212 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +59 -0
package/CHANGELOG.md
ADDED
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,25 @@
|
|
|
1
|
+
# @0xkey-io/indexed-db-stamper
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@0xkey-io/indexed-db-stamper)
|
|
4
|
+
|
|
5
|
+
The `@0xkey-io/indexed-db-stamper` package enables secure request stamping using an unextractable P-256 keypair stored in the browser’s IndexedDB. It serves the same purpose as [`@0xkey-io/api-key-stamper`](../api-key-stamper/), allowing you to sign and approve requests to ZeroXKey’s API, but without exposing the private key. This is ideal for long-lived browser sessions in progressive web apps (PWAs), wallet extensions, or any context where the key must remain secure and persistent across reloads.
|
|
6
|
+
|
|
7
|
+
The IndexedDbStamper generates the private key using SubtleCrypto and stores it in a non-exportable format, ensuring that it cannot be extracted or exfiltrated by application code. The keypair is stored in IndexedDB so that it can be reused in subsequent sessions.
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
|
|
11
|
+
The `IndexedDbStamper` class implements the `TStamper` interface used by the `ZeroXKeyClient` in the [`@0xkey-io/http`](../http/) module. It encapsulates the logic necessary to sign activity requests and generates the appropriate HTTP headers for authentication.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { IndexedDbStamper } from "@0xkey-io/indexed-db-stamper";
|
|
15
|
+
|
|
16
|
+
// Initialize the stamper and generate or load the keypair
|
|
17
|
+
const stamper = new IndexedDbStamper();
|
|
18
|
+
await stamper.init();
|
|
19
|
+
|
|
20
|
+
// Once initialized, the stamper is ready to be passed into the ZeroXKeyClient.
|
|
21
|
+
const httpClient = new ZeroXKeyClient(
|
|
22
|
+
{ baseUrl: "https://api.0xkey.com" },
|
|
23
|
+
stamper,
|
|
24
|
+
);
|
|
25
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class IndexedDbStamper {
|
|
2
|
+
private publicKeyHex;
|
|
3
|
+
private privateKey;
|
|
4
|
+
constructor();
|
|
5
|
+
private openDb;
|
|
6
|
+
private storeKeyPair;
|
|
7
|
+
private getStoredKeys;
|
|
8
|
+
init(): Promise<void>;
|
|
9
|
+
resetKeyPair(externalKeyPair?: CryptoKeyPair): Promise<void>;
|
|
10
|
+
getPublicKey(): string | null;
|
|
11
|
+
sign(payload: string): Promise<string>;
|
|
12
|
+
stamp(payload: string): Promise<{
|
|
13
|
+
stampHeaderName: string;
|
|
14
|
+
stampHeaderValue: string;
|
|
15
|
+
}>;
|
|
16
|
+
clear(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkFA,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,UAAU,CAA0B;;YAQ9B,MAAM;YAcN,YAAY;YAqBZ,aAAa;IA0BrB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAWrB,YAAY,CAAC,eAAe,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAsClE,YAAY,IAAI,MAAM,GAAG,IAAI;IAIvB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAqBtC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QACpC,eAAe,EAAE,MAAM,CAAC;QACxB,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;IAmBI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAkB7B"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var encoding = require('@0xkey-io/encoding');
|
|
4
|
+
|
|
5
|
+
const DB_NAME = "ZeroXKeyStamperDB";
|
|
6
|
+
const DB_STORE = "KeyStore";
|
|
7
|
+
const DB_KEY = "0xkeyKeyPair";
|
|
8
|
+
const stampHeaderName = "X-Stamp";
|
|
9
|
+
/**
|
|
10
|
+
* `SubtleCrypto.sign(...)` outputs signature in IEEE P1363 format:
|
|
11
|
+
* - https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/sign#ecdsa
|
|
12
|
+
*
|
|
13
|
+
* ZeroXKey expects the signature encoding to be DER-encoded ASN.1.
|
|
14
|
+
*
|
|
15
|
+
* Code modified from https://github.com/google/tink/blob/6f74b99a2bfe6677e3670799116a57268fd067fa/javascript/subtle/elliptic_curves.ts#L114
|
|
16
|
+
*
|
|
17
|
+
* Transform an ECDSA signature in IEEE 1363 encoding to DER encoding.
|
|
18
|
+
*
|
|
19
|
+
* @param ieee the ECDSA signature in IEEE encoding
|
|
20
|
+
* @return ECDSA signature in DER encoding
|
|
21
|
+
*/
|
|
22
|
+
function convertEcdsaIeee1363ToDer(ieee) {
|
|
23
|
+
if (ieee.length % 2 != 0 || ieee.length == 0 || ieee.length > 132) {
|
|
24
|
+
throw new Error("Invalid IEEE P1363 signature encoding. Length: " + ieee.length);
|
|
25
|
+
}
|
|
26
|
+
const r = toUnsignedBigNum(ieee.subarray(0, ieee.length / 2));
|
|
27
|
+
const s = toUnsignedBigNum(ieee.subarray(ieee.length / 2, ieee.length));
|
|
28
|
+
let offset = 0;
|
|
29
|
+
const length = 1 + 1 + r.length + 1 + 1 + s.length;
|
|
30
|
+
let der;
|
|
31
|
+
if (length >= 128) {
|
|
32
|
+
der = new Uint8Array(length + 3);
|
|
33
|
+
der[offset++] = 48;
|
|
34
|
+
der[offset++] = 128 + 1;
|
|
35
|
+
der[offset++] = length;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
der = new Uint8Array(length + 2);
|
|
39
|
+
der[offset++] = 48;
|
|
40
|
+
der[offset++] = length;
|
|
41
|
+
}
|
|
42
|
+
der[offset++] = 2;
|
|
43
|
+
der[offset++] = r.length;
|
|
44
|
+
der.set(r, offset);
|
|
45
|
+
offset += r.length;
|
|
46
|
+
der[offset++] = 2;
|
|
47
|
+
der[offset++] = s.length;
|
|
48
|
+
der.set(s, offset);
|
|
49
|
+
return der;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Code modified from https://github.com/google/tink/blob/6f74b99a2bfe6677e3670799116a57268fd067fa/javascript/subtle/elliptic_curves.ts#L311
|
|
53
|
+
*
|
|
54
|
+
* Transform a big integer in big endian to minimal unsigned form which has
|
|
55
|
+
* no extra zero at the beginning except when the highest bit is set.
|
|
56
|
+
*/
|
|
57
|
+
function toUnsignedBigNum(bytes) {
|
|
58
|
+
// Remove zero prefixes.
|
|
59
|
+
let start = 0;
|
|
60
|
+
while (start < bytes.length && bytes[start] == 0) {
|
|
61
|
+
start++;
|
|
62
|
+
}
|
|
63
|
+
if (start == bytes.length) {
|
|
64
|
+
start = bytes.length - 1;
|
|
65
|
+
}
|
|
66
|
+
let extraZero = 0;
|
|
67
|
+
// If the 1st bit is not zero, add 1 zero byte.
|
|
68
|
+
if ((bytes[start] & 128) == 128) {
|
|
69
|
+
// Add extra zero.
|
|
70
|
+
extraZero = 1;
|
|
71
|
+
}
|
|
72
|
+
const res = new Uint8Array(bytes.length - start + extraZero);
|
|
73
|
+
res.set(bytes.subarray(start), extraZero);
|
|
74
|
+
return res;
|
|
75
|
+
}
|
|
76
|
+
class IndexedDbStamper {
|
|
77
|
+
constructor() {
|
|
78
|
+
this.publicKeyHex = null;
|
|
79
|
+
this.privateKey = null;
|
|
80
|
+
if (typeof window === "undefined") {
|
|
81
|
+
throw new Error("IndexedDB is only available in the browser");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async openDb() {
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
const request = indexedDB.open(DB_NAME, 1);
|
|
87
|
+
request.onupgradeneeded = (event) => {
|
|
88
|
+
const db = event.target.result;
|
|
89
|
+
db.createObjectStore(DB_STORE);
|
|
90
|
+
};
|
|
91
|
+
request.onsuccess = () => resolve(request.result);
|
|
92
|
+
request.onerror = () => reject(request.error);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async storeKeyPair(publicKey, privateKey) {
|
|
96
|
+
const db = await this.openDb();
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
const tx = db.transaction(DB_STORE, "readwrite");
|
|
99
|
+
const store = tx.objectStore(DB_STORE);
|
|
100
|
+
store.put(publicKey, `${DB_KEY}-pub`);
|
|
101
|
+
store.put(privateKey, `${DB_KEY}-priv`);
|
|
102
|
+
tx.oncomplete = () => {
|
|
103
|
+
db.close();
|
|
104
|
+
resolve();
|
|
105
|
+
};
|
|
106
|
+
tx.onerror = () => reject(tx.error);
|
|
107
|
+
tx.onabort = () => reject(tx.error);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
async getStoredKeys() {
|
|
111
|
+
const db = await this.openDb();
|
|
112
|
+
return new Promise((resolve, reject) => {
|
|
113
|
+
const tx = db.transaction(DB_STORE, "readonly");
|
|
114
|
+
const store = tx.objectStore(DB_STORE);
|
|
115
|
+
const getPub = store.get(`${DB_KEY}-pub`);
|
|
116
|
+
const getPriv = store.get(`${DB_KEY}-priv`);
|
|
117
|
+
let publicKey = null;
|
|
118
|
+
let privateKey = null;
|
|
119
|
+
getPub.onsuccess = () => (publicKey = getPub.result || null);
|
|
120
|
+
getPriv.onsuccess = () => (privateKey = getPriv.result || null);
|
|
121
|
+
tx.oncomplete = () => {
|
|
122
|
+
db.close();
|
|
123
|
+
resolve({ publicKey, privateKey });
|
|
124
|
+
};
|
|
125
|
+
tx.onerror = () => reject(tx.error);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
async init() {
|
|
129
|
+
const { publicKey, privateKey } = await this.getStoredKeys();
|
|
130
|
+
if (publicKey && privateKey) {
|
|
131
|
+
this.publicKeyHex = publicKey;
|
|
132
|
+
this.privateKey = privateKey;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
await this.resetKeyPair();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async resetKeyPair(externalKeyPair) {
|
|
139
|
+
let privateKey;
|
|
140
|
+
let publicKey;
|
|
141
|
+
if (externalKeyPair) {
|
|
142
|
+
// Sanity check — ensure privateKey is non-extractable
|
|
143
|
+
const extractable = externalKeyPair.privateKey.extractable;
|
|
144
|
+
if (extractable !== false) {
|
|
145
|
+
throw new Error("Provided privateKey must be non-extractable.");
|
|
146
|
+
}
|
|
147
|
+
privateKey = externalKeyPair.privateKey;
|
|
148
|
+
publicKey = externalKeyPair.publicKey;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const keyPair = await crypto.subtle.generateKey({
|
|
152
|
+
name: "ECDSA",
|
|
153
|
+
namedCurve: "P-256",
|
|
154
|
+
}, false, ["sign", "verify"]);
|
|
155
|
+
privateKey = keyPair.privateKey;
|
|
156
|
+
publicKey = keyPair.publicKey;
|
|
157
|
+
}
|
|
158
|
+
const rawPubKey = new Uint8Array(await crypto.subtle.exportKey("raw", publicKey));
|
|
159
|
+
const compressedPubKey = encoding.pointEncode(rawPubKey);
|
|
160
|
+
const compressedHex = encoding.uint8ArrayToHexString(compressedPubKey);
|
|
161
|
+
await this.storeKeyPair(compressedHex, privateKey);
|
|
162
|
+
this.publicKeyHex = compressedHex;
|
|
163
|
+
this.privateKey = privateKey;
|
|
164
|
+
}
|
|
165
|
+
getPublicKey() {
|
|
166
|
+
return this.publicKeyHex;
|
|
167
|
+
}
|
|
168
|
+
async sign(payload) {
|
|
169
|
+
if (!this.privateKey) {
|
|
170
|
+
throw new Error("Key not initialized. Call init() first.");
|
|
171
|
+
}
|
|
172
|
+
const encodedPayload = new TextEncoder().encode(payload);
|
|
173
|
+
const signatureIeee1363 = await crypto.subtle.sign({
|
|
174
|
+
name: "ECDSA",
|
|
175
|
+
hash: { name: "SHA-256" },
|
|
176
|
+
}, this.privateKey, encodedPayload);
|
|
177
|
+
const signatureDer = convertEcdsaIeee1363ToDer(new Uint8Array(signatureIeee1363));
|
|
178
|
+
return encoding.uint8ArrayToHexString(signatureDer);
|
|
179
|
+
}
|
|
180
|
+
async stamp(payload) {
|
|
181
|
+
if (!this.publicKeyHex || !this.privateKey) {
|
|
182
|
+
throw new Error("Key not initialized. Call init() first.");
|
|
183
|
+
}
|
|
184
|
+
const signature = await this.sign(payload);
|
|
185
|
+
const stamp = {
|
|
186
|
+
publicKey: this.publicKeyHex,
|
|
187
|
+
scheme: "SIGNATURE_SCHEME_TK_API_P256",
|
|
188
|
+
signature: signature,
|
|
189
|
+
};
|
|
190
|
+
return {
|
|
191
|
+
stampHeaderName: stampHeaderName,
|
|
192
|
+
stampHeaderValue: encoding.stringToBase64urlString(JSON.stringify(stamp)),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
async clear() {
|
|
196
|
+
const db = await this.openDb();
|
|
197
|
+
return new Promise((resolve, reject) => {
|
|
198
|
+
const tx = db.transaction(DB_STORE, "readwrite");
|
|
199
|
+
const store = tx.objectStore(DB_STORE);
|
|
200
|
+
store.delete(`${DB_KEY}-pub`);
|
|
201
|
+
store.delete(`${DB_KEY}-priv`);
|
|
202
|
+
tx.oncomplete = () => {
|
|
203
|
+
db.close();
|
|
204
|
+
this.publicKeyHex = null;
|
|
205
|
+
this.privateKey = null;
|
|
206
|
+
resolve();
|
|
207
|
+
};
|
|
208
|
+
tx.onerror = () => reject(tx.error);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
exports.IndexedDbStamper = IndexedDbStamper;
|
|
214
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":[null],"names":["pointEncode","uint8ArrayToHexString","stringToBase64urlString"],"mappings":";;;;AAMA,MAAM,OAAO,GAAG,mBAAmB;AACnC,MAAM,QAAQ,GAAG,UAAU;AAC3B,MAAM,MAAM,GAAG,cAAc;AAC7B,MAAM,eAAe,GAAG,SAAS;AAEjC;;;;;;;;;;;;AAYG;AACH,SAAS,yBAAyB,CAAC,IAAgB,EAAA;IACjD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE;QACjE,MAAM,IAAI,KAAK,CACb,iDAAiD,GAAG,IAAI,CAAC,MAAM,CAChE;IACH;AACA,IAAA,MAAM,CAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC7D,IAAA,MAAM,CAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACvE,IAAI,MAAM,GAAG,CAAC;AACd,IAAA,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,CA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ED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { pointEncode, uint8ArrayToHexString, stringToBase64urlString } from '@0xkey-io/encoding';
|
|
2
|
+
|
|
3
|
+
const DB_NAME = "ZeroXKeyStamperDB";
|
|
4
|
+
const DB_STORE = "KeyStore";
|
|
5
|
+
const DB_KEY = "0xkeyKeyPair";
|
|
6
|
+
const stampHeaderName = "X-Stamp";
|
|
7
|
+
/**
|
|
8
|
+
* `SubtleCrypto.sign(...)` outputs signature in IEEE P1363 format:
|
|
9
|
+
* - https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/sign#ecdsa
|
|
10
|
+
*
|
|
11
|
+
* ZeroXKey expects the signature encoding to be DER-encoded ASN.1.
|
|
12
|
+
*
|
|
13
|
+
* Code modified from https://github.com/google/tink/blob/6f74b99a2bfe6677e3670799116a57268fd067fa/javascript/subtle/elliptic_curves.ts#L114
|
|
14
|
+
*
|
|
15
|
+
* Transform an ECDSA signature in IEEE 1363 encoding to DER encoding.
|
|
16
|
+
*
|
|
17
|
+
* @param ieee the ECDSA signature in IEEE encoding
|
|
18
|
+
* @return ECDSA signature in DER encoding
|
|
19
|
+
*/
|
|
20
|
+
function convertEcdsaIeee1363ToDer(ieee) {
|
|
21
|
+
if (ieee.length % 2 != 0 || ieee.length == 0 || ieee.length > 132) {
|
|
22
|
+
throw new Error("Invalid IEEE P1363 signature encoding. Length: " + ieee.length);
|
|
23
|
+
}
|
|
24
|
+
const r = toUnsignedBigNum(ieee.subarray(0, ieee.length / 2));
|
|
25
|
+
const s = toUnsignedBigNum(ieee.subarray(ieee.length / 2, ieee.length));
|
|
26
|
+
let offset = 0;
|
|
27
|
+
const length = 1 + 1 + r.length + 1 + 1 + s.length;
|
|
28
|
+
let der;
|
|
29
|
+
if (length >= 128) {
|
|
30
|
+
der = new Uint8Array(length + 3);
|
|
31
|
+
der[offset++] = 48;
|
|
32
|
+
der[offset++] = 128 + 1;
|
|
33
|
+
der[offset++] = length;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
der = new Uint8Array(length + 2);
|
|
37
|
+
der[offset++] = 48;
|
|
38
|
+
der[offset++] = length;
|
|
39
|
+
}
|
|
40
|
+
der[offset++] = 2;
|
|
41
|
+
der[offset++] = r.length;
|
|
42
|
+
der.set(r, offset);
|
|
43
|
+
offset += r.length;
|
|
44
|
+
der[offset++] = 2;
|
|
45
|
+
der[offset++] = s.length;
|
|
46
|
+
der.set(s, offset);
|
|
47
|
+
return der;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Code modified from https://github.com/google/tink/blob/6f74b99a2bfe6677e3670799116a57268fd067fa/javascript/subtle/elliptic_curves.ts#L311
|
|
51
|
+
*
|
|
52
|
+
* Transform a big integer in big endian to minimal unsigned form which has
|
|
53
|
+
* no extra zero at the beginning except when the highest bit is set.
|
|
54
|
+
*/
|
|
55
|
+
function toUnsignedBigNum(bytes) {
|
|
56
|
+
// Remove zero prefixes.
|
|
57
|
+
let start = 0;
|
|
58
|
+
while (start < bytes.length && bytes[start] == 0) {
|
|
59
|
+
start++;
|
|
60
|
+
}
|
|
61
|
+
if (start == bytes.length) {
|
|
62
|
+
start = bytes.length - 1;
|
|
63
|
+
}
|
|
64
|
+
let extraZero = 0;
|
|
65
|
+
// If the 1st bit is not zero, add 1 zero byte.
|
|
66
|
+
if ((bytes[start] & 128) == 128) {
|
|
67
|
+
// Add extra zero.
|
|
68
|
+
extraZero = 1;
|
|
69
|
+
}
|
|
70
|
+
const res = new Uint8Array(bytes.length - start + extraZero);
|
|
71
|
+
res.set(bytes.subarray(start), extraZero);
|
|
72
|
+
return res;
|
|
73
|
+
}
|
|
74
|
+
class IndexedDbStamper {
|
|
75
|
+
constructor() {
|
|
76
|
+
this.publicKeyHex = null;
|
|
77
|
+
this.privateKey = null;
|
|
78
|
+
if (typeof window === "undefined") {
|
|
79
|
+
throw new Error("IndexedDB is only available in the browser");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async openDb() {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
const request = indexedDB.open(DB_NAME, 1);
|
|
85
|
+
request.onupgradeneeded = (event) => {
|
|
86
|
+
const db = event.target.result;
|
|
87
|
+
db.createObjectStore(DB_STORE);
|
|
88
|
+
};
|
|
89
|
+
request.onsuccess = () => resolve(request.result);
|
|
90
|
+
request.onerror = () => reject(request.error);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async storeKeyPair(publicKey, privateKey) {
|
|
94
|
+
const db = await this.openDb();
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
const tx = db.transaction(DB_STORE, "readwrite");
|
|
97
|
+
const store = tx.objectStore(DB_STORE);
|
|
98
|
+
store.put(publicKey, `${DB_KEY}-pub`);
|
|
99
|
+
store.put(privateKey, `${DB_KEY}-priv`);
|
|
100
|
+
tx.oncomplete = () => {
|
|
101
|
+
db.close();
|
|
102
|
+
resolve();
|
|
103
|
+
};
|
|
104
|
+
tx.onerror = () => reject(tx.error);
|
|
105
|
+
tx.onabort = () => reject(tx.error);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
async getStoredKeys() {
|
|
109
|
+
const db = await this.openDb();
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
111
|
+
const tx = db.transaction(DB_STORE, "readonly");
|
|
112
|
+
const store = tx.objectStore(DB_STORE);
|
|
113
|
+
const getPub = store.get(`${DB_KEY}-pub`);
|
|
114
|
+
const getPriv = store.get(`${DB_KEY}-priv`);
|
|
115
|
+
let publicKey = null;
|
|
116
|
+
let privateKey = null;
|
|
117
|
+
getPub.onsuccess = () => (publicKey = getPub.result || null);
|
|
118
|
+
getPriv.onsuccess = () => (privateKey = getPriv.result || null);
|
|
119
|
+
tx.oncomplete = () => {
|
|
120
|
+
db.close();
|
|
121
|
+
resolve({ publicKey, privateKey });
|
|
122
|
+
};
|
|
123
|
+
tx.onerror = () => reject(tx.error);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async init() {
|
|
127
|
+
const { publicKey, privateKey } = await this.getStoredKeys();
|
|
128
|
+
if (publicKey && privateKey) {
|
|
129
|
+
this.publicKeyHex = publicKey;
|
|
130
|
+
this.privateKey = privateKey;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
await this.resetKeyPair();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async resetKeyPair(externalKeyPair) {
|
|
137
|
+
let privateKey;
|
|
138
|
+
let publicKey;
|
|
139
|
+
if (externalKeyPair) {
|
|
140
|
+
// Sanity check — ensure privateKey is non-extractable
|
|
141
|
+
const extractable = externalKeyPair.privateKey.extractable;
|
|
142
|
+
if (extractable !== false) {
|
|
143
|
+
throw new Error("Provided privateKey must be non-extractable.");
|
|
144
|
+
}
|
|
145
|
+
privateKey = externalKeyPair.privateKey;
|
|
146
|
+
publicKey = externalKeyPair.publicKey;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
const keyPair = await crypto.subtle.generateKey({
|
|
150
|
+
name: "ECDSA",
|
|
151
|
+
namedCurve: "P-256",
|
|
152
|
+
}, false, ["sign", "verify"]);
|
|
153
|
+
privateKey = keyPair.privateKey;
|
|
154
|
+
publicKey = keyPair.publicKey;
|
|
155
|
+
}
|
|
156
|
+
const rawPubKey = new Uint8Array(await crypto.subtle.exportKey("raw", publicKey));
|
|
157
|
+
const compressedPubKey = pointEncode(rawPubKey);
|
|
158
|
+
const compressedHex = uint8ArrayToHexString(compressedPubKey);
|
|
159
|
+
await this.storeKeyPair(compressedHex, privateKey);
|
|
160
|
+
this.publicKeyHex = compressedHex;
|
|
161
|
+
this.privateKey = privateKey;
|
|
162
|
+
}
|
|
163
|
+
getPublicKey() {
|
|
164
|
+
return this.publicKeyHex;
|
|
165
|
+
}
|
|
166
|
+
async sign(payload) {
|
|
167
|
+
if (!this.privateKey) {
|
|
168
|
+
throw new Error("Key not initialized. Call init() first.");
|
|
169
|
+
}
|
|
170
|
+
const encodedPayload = new TextEncoder().encode(payload);
|
|
171
|
+
const signatureIeee1363 = await crypto.subtle.sign({
|
|
172
|
+
name: "ECDSA",
|
|
173
|
+
hash: { name: "SHA-256" },
|
|
174
|
+
}, this.privateKey, encodedPayload);
|
|
175
|
+
const signatureDer = convertEcdsaIeee1363ToDer(new Uint8Array(signatureIeee1363));
|
|
176
|
+
return uint8ArrayToHexString(signatureDer);
|
|
177
|
+
}
|
|
178
|
+
async stamp(payload) {
|
|
179
|
+
if (!this.publicKeyHex || !this.privateKey) {
|
|
180
|
+
throw new Error("Key not initialized. Call init() first.");
|
|
181
|
+
}
|
|
182
|
+
const signature = await this.sign(payload);
|
|
183
|
+
const stamp = {
|
|
184
|
+
publicKey: this.publicKeyHex,
|
|
185
|
+
scheme: "SIGNATURE_SCHEME_TK_API_P256",
|
|
186
|
+
signature: signature,
|
|
187
|
+
};
|
|
188
|
+
return {
|
|
189
|
+
stampHeaderName: stampHeaderName,
|
|
190
|
+
stampHeaderValue: stringToBase64urlString(JSON.stringify(stamp)),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
async clear() {
|
|
194
|
+
const db = await this.openDb();
|
|
195
|
+
return new Promise((resolve, reject) => {
|
|
196
|
+
const tx = db.transaction(DB_STORE, "readwrite");
|
|
197
|
+
const store = tx.objectStore(DB_STORE);
|
|
198
|
+
store.delete(`${DB_KEY}-pub`);
|
|
199
|
+
store.delete(`${DB_KEY}-priv`);
|
|
200
|
+
tx.oncomplete = () => {
|
|
201
|
+
db.close();
|
|
202
|
+
this.publicKeyHex = null;
|
|
203
|
+
this.privateKey = null;
|
|
204
|
+
resolve();
|
|
205
|
+
};
|
|
206
|
+
tx.onerror = () => reject(tx.error);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export { IndexedDbStamper };
|
|
212
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/index.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IAAA,MAAM,KAAK,GAAA;AACT,QAAA,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE;QAC9B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;YACrC,MAAM,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC;YAChD,MAAM,KAAK,GAAG,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC;AAEtC,YAAA,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAA,IAAA,CAAM,CAAC;AAC7B,YAAA,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAA,KAAA,CAAO,CAAC;AAE9B,YAAA,EAAE,CAAC,UAAU,GAAG,MAAK;gBACnB,EAAE,CAAC,KAAK,EAAE;AACV,gBAAA,IAAI,CAAC,YAAY,GAAG,IAAI;AACxB,gBAAA,IAAI,CAAC,UAAU,GAAG,IAAI;AACtB,gBAAA,OAAO,EAAE;AACX,YAAA,CAAC;AACD,YAAA,EAAE,CAAC,OAAO,GAAG,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC;AACrC,QAAA,CAAC,CAAC;IACJ;AACD;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@0xkey-io/indexed-db-stamper",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"description": "IndexedDB-based stamper for @0xkey-io/http",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"0xkey",
|
|
19
|
+
"http",
|
|
20
|
+
"stamper"
|
|
21
|
+
],
|
|
22
|
+
"author": {
|
|
23
|
+
"name": "0xkey",
|
|
24
|
+
"url": "https://0xkey.com/"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/0xkey-io/sdk-js/tree/main/packages/indexed-db-stamper",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/0xkey-io/sdk-js/issues"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/0xkey-io/sdk-js.git",
|
|
33
|
+
"directory": "packages/indexed-db-stamper"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist/",
|
|
37
|
+
"CHANGELOG.md"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18.0.0"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@0xkey-io/api-key-stamper": "0.1.0",
|
|
47
|
+
"@0xkey-io/encoding": "0.1.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/jest": "^29.5.3",
|
|
51
|
+
"jest": "^29.7.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "rollup -c",
|
|
55
|
+
"clean": "rimraf ./dist ./.cache",
|
|
56
|
+
"test": "jest",
|
|
57
|
+
"typecheck": "tsc -p tsconfig.typecheck.json"
|
|
58
|
+
}
|
|
59
|
+
}
|