@canton-network/core-signing-store-wxt 1.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/LICENSE +202 -0
- package/README.md +33 -0
- package/dist/index.cjs +223 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +216 -0
- package/dist/index.js.map +1 -0
- package/dist/items.d.ts +34 -0
- package/dist/items.d.ts.map +1 -0
- package/dist/schemas.d.ts +10 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/store-wxt.d.ts +22 -0
- package/dist/store-wxt.d.ts.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
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 {yyyy} {name of copyright owner}
|
|
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.
|
|
202
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @canton-network/core-signing-store-wxt
|
|
2
|
+
|
|
3
|
+
A WxtStore is a browser-extension implementation of the `SigningDriverStore` interface from `@canton-network/core-signing-lib` backed by `@wxt-dev/storage`.
|
|
4
|
+
|
|
5
|
+
This store persists signing keys, signing transactions, and per driver configuration in the extension's local storage area.
|
|
6
|
+
|
|
7
|
+
The extension is single-user, so all data for a given record type is kept in a single flat array under one storage key rather than one storage imem per record plus separate lookup indexes.
|
|
8
|
+
|
|
9
|
+
| Data | Storage key | Shape |
|
|
10
|
+
| :------------------- | :----------------------------- | :------------------------- |
|
|
11
|
+
| Signing Keys | local:signingKeys | SigningKeyRecord[] |
|
|
12
|
+
| Signing Transactions | local:signingTransactions | SigningTransactionRecord[] |
|
|
13
|
+
| Driver config | local: signingDriverConfigItem | SigningDriverConfigRecord |
|
|
14
|
+
|
|
15
|
+
# Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { WxtStore } from '@canton-network/core-signing-store-wxt'
|
|
19
|
+
|
|
20
|
+
const userId = 'myUser'
|
|
21
|
+
const store = new WxtStore(userId)
|
|
22
|
+
await store.setSigningKey(userId, {
|
|
23
|
+
id: 'key1',
|
|
24
|
+
name: 'pkey1',
|
|
25
|
+
publicKey: '...',
|
|
26
|
+
privateKey: '...',
|
|
27
|
+
createdAt: new Date(),
|
|
28
|
+
updatedAt: new Date(),
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const key = await store.getSigningKeyByName(userId, 'pkey1')
|
|
32
|
+
const allKeys = await store.listSigningKeys(userId)
|
|
33
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _wxt_dev_storage = require("@wxt-dev/storage");
|
|
3
|
+
//#region src/schemas.ts
|
|
4
|
+
const fromSigningKey = (key, userId, encrypt) => {
|
|
5
|
+
return {
|
|
6
|
+
id: key.id,
|
|
7
|
+
userId,
|
|
8
|
+
name: key.name,
|
|
9
|
+
publicKey: key.publicKey,
|
|
10
|
+
privateKey: key.privateKey ? encrypt ? encrypt(key.privateKey) : key.privateKey : null,
|
|
11
|
+
metadata: key.metadata ? JSON.stringify(key.metadata) : null,
|
|
12
|
+
createdAt: key.createdAt.toISOString(),
|
|
13
|
+
updatedAt: key.updatedAt.toISOString()
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
const toSigningKey = (record, decrypt) => {
|
|
17
|
+
return {
|
|
18
|
+
id: record.id,
|
|
19
|
+
name: record.name,
|
|
20
|
+
publicKey: record.publicKey,
|
|
21
|
+
...record.privateKey ? { privateKey: decrypt ? decrypt(record.privateKey) : record.privateKey } : {},
|
|
22
|
+
createdAt: new Date(record.createdAt),
|
|
23
|
+
updatedAt: new Date(record.updatedAt),
|
|
24
|
+
...record.metadata ? { metadata: typeof record.metadata === "string" ? JSON.parse(record.metadata) : record.metadata } : {}
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const fromSigningTransaction = (transaction, userId) => {
|
|
28
|
+
return {
|
|
29
|
+
id: transaction.id,
|
|
30
|
+
userId,
|
|
31
|
+
hash: transaction.hash,
|
|
32
|
+
signature: transaction.signature || null,
|
|
33
|
+
publicKey: transaction.publicKey,
|
|
34
|
+
status: transaction.status,
|
|
35
|
+
metadata: transaction.metadata ? JSON.stringify(transaction.metadata) : null,
|
|
36
|
+
createdAt: transaction.createdAt.toISOString(),
|
|
37
|
+
updatedAt: transaction.updatedAt.toISOString(),
|
|
38
|
+
signedAt: transaction.signedAt?.toISOString() || null
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
const toSigningTransaction = (record) => {
|
|
42
|
+
return {
|
|
43
|
+
id: record.id,
|
|
44
|
+
hash: record.hash,
|
|
45
|
+
...record.signature ? { signature: record.signature } : {},
|
|
46
|
+
publicKey: record.publicKey,
|
|
47
|
+
status: record.status,
|
|
48
|
+
...record.metadata ? { metadata: typeof record.metadata === "string" ? JSON.parse(record.metadata) : record.metadata } : {},
|
|
49
|
+
createdAt: new Date(record.createdAt),
|
|
50
|
+
updatedAt: new Date(record.updatedAt),
|
|
51
|
+
...record.signedAt ? { signedAt: new Date(record.signedAt) } : {}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const fromSigningDriverConfig = (config, userId) => {
|
|
55
|
+
return {
|
|
56
|
+
userId,
|
|
57
|
+
driverId: config.driverId,
|
|
58
|
+
config: JSON.stringify(config.config)
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const toSigningDriverConfig = (record) => {
|
|
62
|
+
return {
|
|
63
|
+
driverId: record.driverId,
|
|
64
|
+
config: typeof record.config === "string" ? JSON.parse(record.config) : record.config
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/items.ts
|
|
69
|
+
const STORAGE_LOCATION = "local";
|
|
70
|
+
function item(key) {
|
|
71
|
+
return _wxt_dev_storage.storage.defineItem(`${STORAGE_LOCATION}:${key}`);
|
|
72
|
+
}
|
|
73
|
+
function items(key) {
|
|
74
|
+
return _wxt_dev_storage.storage.defineItem(`${STORAGE_LOCATION}:${key}`, { fallback: [] });
|
|
75
|
+
}
|
|
76
|
+
const signingKeysItem = () => items("signingKeys");
|
|
77
|
+
const signingTransactionsItem = () => items("signingTransactions");
|
|
78
|
+
const signingDriverConfigItem = (driverId) => item(`signingDriverConfigItem:${driverId}`);
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/store-wxt.ts
|
|
81
|
+
var WxtStore = class {
|
|
82
|
+
constructor(userId) {
|
|
83
|
+
this.userId = userId;
|
|
84
|
+
}
|
|
85
|
+
async getSigningKey(userId, keyId) {
|
|
86
|
+
const record = await signingKeysItem().getValue();
|
|
87
|
+
const signingKey = record ? record.find((r) => r.id === keyId) : void 0;
|
|
88
|
+
return signingKey ? toSigningKey(signingKey) : void 0;
|
|
89
|
+
}
|
|
90
|
+
async getSigningKeyByPublicKey(publicKey) {
|
|
91
|
+
return (await this.listSigningKeys(this.userId)).find((key) => key.publicKey === publicKey);
|
|
92
|
+
}
|
|
93
|
+
async getSigningKeyByName(userId, name) {
|
|
94
|
+
return (await this.listSigningKeys(this.userId)).find((key) => key.name === name);
|
|
95
|
+
}
|
|
96
|
+
async listSigningTransactionsByTxIdsAndPublicKeys(txIds, publicKeys) {
|
|
97
|
+
if (!txIds.length && !publicKeys.length) return [];
|
|
98
|
+
return (await this.listSigningTransactions(this.userId)).filter((record) => {
|
|
99
|
+
if (!record) return false;
|
|
100
|
+
const matchesTxId = txIds.length > 0 && txIds.includes(record.id);
|
|
101
|
+
const matchesPublicKey = publicKeys.length > 0 && publicKeys.includes(record.publicKey);
|
|
102
|
+
return matchesTxId || matchesPublicKey;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
async setSigningKey(userId, key) {
|
|
106
|
+
const item = signingKeysItem();
|
|
107
|
+
const keys = await item.getValue();
|
|
108
|
+
const idx = keys?.findIndex((k) => k.id === key.id);
|
|
109
|
+
const existing = idx >= 0 ? keys[idx] : void 0;
|
|
110
|
+
const serialized = fromSigningKey(key, userId);
|
|
111
|
+
const updated = {
|
|
112
|
+
...serialized,
|
|
113
|
+
createdAt: existing?.createdAt ?? serialized.createdAt,
|
|
114
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
115
|
+
};
|
|
116
|
+
const nextKeys = idx >= 0 ? keys.map((key, index) => index === idx ? updated : key) : [...keys, updated];
|
|
117
|
+
await item.setValue(nextKeys);
|
|
118
|
+
}
|
|
119
|
+
async deleteSigningKey(userId, keyId) {
|
|
120
|
+
const item = signingKeysItem();
|
|
121
|
+
const keys = await item.getValue();
|
|
122
|
+
const nextKeys = keys.filter((k) => k.id !== keyId);
|
|
123
|
+
if (nextKeys.length !== keys.length) await item.setValue(nextKeys);
|
|
124
|
+
}
|
|
125
|
+
async listSigningKeys(userId) {
|
|
126
|
+
return (await signingKeysItem().getValue()).map((x) => toSigningKey(x));
|
|
127
|
+
}
|
|
128
|
+
async getSigningTransaction(userId, txId) {
|
|
129
|
+
const records = await signingTransactionsItem().getValue();
|
|
130
|
+
const tx = records ? records.find((r) => r.id === txId) : void 0;
|
|
131
|
+
return tx ? toSigningTransaction(tx) : void 0;
|
|
132
|
+
}
|
|
133
|
+
async setSigningTransaction(userId, transaction) {
|
|
134
|
+
const item = signingTransactionsItem();
|
|
135
|
+
const txs = await item.getValue();
|
|
136
|
+
const idx = txs?.findIndex((k) => k.id === transaction.id);
|
|
137
|
+
const existing = idx >= 0 ? txs[idx] : void 0;
|
|
138
|
+
const serialized = fromSigningTransaction(transaction, userId);
|
|
139
|
+
const updated = {
|
|
140
|
+
...serialized,
|
|
141
|
+
createdAt: existing?.createdAt ?? serialized.createdAt,
|
|
142
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
143
|
+
};
|
|
144
|
+
const nextKeys = idx >= 0 ? txs.map((key, index) => index === idx ? updated : key) : [...txs, updated];
|
|
145
|
+
await item.setValue(nextKeys);
|
|
146
|
+
}
|
|
147
|
+
async updateSigningTransactionStatus(userId, txId, status) {
|
|
148
|
+
const signingTx = signingTransactionsItem();
|
|
149
|
+
const txs = await signingTx.getValue();
|
|
150
|
+
const idx = txs?.findIndex((tx) => tx.id === txId);
|
|
151
|
+
if (idx === -1) throw new Error(`No signing tx found for txId: ${txId}, userId: ${this.userId}`);
|
|
152
|
+
const updated = {
|
|
153
|
+
...txs[idx],
|
|
154
|
+
status,
|
|
155
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
156
|
+
};
|
|
157
|
+
const nextTxs = txs.map((t, i) => i === idx ? updated : t);
|
|
158
|
+
await signingTx.setValue(nextTxs);
|
|
159
|
+
}
|
|
160
|
+
async listSigningTransactions(userId, limit, before) {
|
|
161
|
+
const validTxs = (await signingTransactionsItem().getValue()).map((x) => toSigningTransaction(x)).sort((a, b) => a.createdAt.toISOString().localeCompare(b.createdAt.toISOString()));
|
|
162
|
+
let beforeDate = before;
|
|
163
|
+
if (before) {
|
|
164
|
+
if (!(!isNaN(Date.parse(before)) && before.includes("T"))) {
|
|
165
|
+
const targetTx = await this.getSigningTransaction(userId, before);
|
|
166
|
+
if (targetTx) beforeDate = targetTx.createdAt.toISOString();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const filteredTxs = beforeDate ? validTxs.filter((k) => k.createdAt.toISOString() < beforeDate) : validTxs;
|
|
170
|
+
return limit ? filteredTxs.slice(0, limit) : filteredTxs;
|
|
171
|
+
}
|
|
172
|
+
async getSigningDriverConfiguration(userId, driverId) {
|
|
173
|
+
const record = await signingDriverConfigItem(driverId).getValue();
|
|
174
|
+
return record ? toSigningDriverConfig(record) : void 0;
|
|
175
|
+
}
|
|
176
|
+
async setSigningDriverConfiguration(userId, config) {
|
|
177
|
+
const item = signingDriverConfigItem(config.driverId);
|
|
178
|
+
const existing = await item.getValue();
|
|
179
|
+
const serialized = fromSigningDriverConfig(config, userId);
|
|
180
|
+
if (existing && existing.config === serialized.config) return;
|
|
181
|
+
await item.setValue(serialized);
|
|
182
|
+
}
|
|
183
|
+
async setSigningKeys(userId, keys) {
|
|
184
|
+
const item = signingKeysItem();
|
|
185
|
+
const existingKeys = await item.getValue();
|
|
186
|
+
const keyMap = new Map(existingKeys.map((k) => [k.id, k]));
|
|
187
|
+
for (const key of keys) {
|
|
188
|
+
const existing = keyMap.get(key.id);
|
|
189
|
+
const serialized = fromSigningKey(key, this.userId);
|
|
190
|
+
keyMap.set(key.id, {
|
|
191
|
+
...serialized,
|
|
192
|
+
createdAt: existing?.createdAt ?? serialized.createdAt,
|
|
193
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
await item.setValue(Array.from(keyMap.values()));
|
|
197
|
+
}
|
|
198
|
+
async setSigningTransactions(userId, transactions) {
|
|
199
|
+
const item = signingTransactionsItem();
|
|
200
|
+
const existingKeys = await item.getValue();
|
|
201
|
+
const txMap = new Map(existingKeys.map((tx) => [tx.id, tx]));
|
|
202
|
+
for (const tx of transactions) {
|
|
203
|
+
const existing = txMap.get(tx.id);
|
|
204
|
+
const serialized = fromSigningTransaction(tx, this.userId);
|
|
205
|
+
txMap.set(tx.id, {
|
|
206
|
+
...serialized,
|
|
207
|
+
createdAt: existing?.createdAt ?? serialized.createdAt,
|
|
208
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
await item.setValue(Array.from(txMap.values()));
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
//#endregion
|
|
215
|
+
exports.WxtStore = WxtStore;
|
|
216
|
+
exports.fromSigningDriverConfig = fromSigningDriverConfig;
|
|
217
|
+
exports.fromSigningKey = fromSigningKey;
|
|
218
|
+
exports.fromSigningTransaction = fromSigningTransaction;
|
|
219
|
+
exports.toSigningDriverConfig = toSigningDriverConfig;
|
|
220
|
+
exports.toSigningKey = toSigningKey;
|
|
221
|
+
exports.toSigningTransaction = toSigningTransaction;
|
|
222
|
+
|
|
223
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["storage"],"sources":["../src/schemas.ts","../src/items.ts","../src/store-wxt.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n SigningDriverConfig,\n SigningDriverStatus,\n SigningKey,\n SigningTransaction,\n} from '@canton-network/core-signing-lib'\nimport { UserId } from '@canton-network/core-wallet-auth'\nimport {\n SigningKeyRecord,\n SigningTransactionRecord,\n SigningDriverConfigRecord,\n} from './items.js'\n\nexport const fromSigningKey = (\n key: SigningKey,\n userId: UserId,\n encrypt?: (data: string) => string\n): SigningKeyRecord => {\n return {\n id: key.id,\n userId: userId,\n name: key.name,\n publicKey: key.publicKey,\n privateKey: key.privateKey\n ? encrypt\n ? encrypt(key.privateKey)\n : key.privateKey\n : null,\n metadata: key.metadata ? JSON.stringify(key.metadata) : null,\n createdAt: key.createdAt.toISOString(),\n updatedAt: key.updatedAt.toISOString(),\n }\n}\n\nexport const toSigningKey = (\n record: SigningKeyRecord,\n decrypt?: (data: string) => string\n): SigningKey => {\n return {\n id: record.id,\n name: record.name,\n publicKey: record.publicKey,\n ...(record.privateKey\n ? {\n privateKey: decrypt\n ? decrypt(record.privateKey)\n : record.privateKey,\n }\n : {}),\n createdAt: new Date(record.createdAt),\n updatedAt: new Date(record.updatedAt),\n ...(record.metadata\n ? {\n metadata:\n typeof record.metadata === 'string'\n ? JSON.parse(record.metadata)\n : record.metadata,\n }\n : {}),\n }\n}\n\nexport const fromSigningTransaction = (\n transaction: SigningTransaction,\n userId: UserId\n): SigningTransactionRecord => {\n return {\n id: transaction.id,\n userId: userId,\n hash: transaction.hash,\n signature: transaction.signature || null,\n publicKey: transaction.publicKey,\n status: transaction.status,\n metadata: transaction.metadata\n ? JSON.stringify(transaction.metadata)\n : null,\n createdAt: transaction.createdAt.toISOString(),\n updatedAt: transaction.updatedAt.toISOString(),\n signedAt: transaction.signedAt?.toISOString() || null,\n }\n}\n\nexport const toSigningTransaction = (\n record: SigningTransactionRecord\n): SigningTransaction => {\n return {\n id: record.id,\n hash: record.hash,\n ...(record.signature ? { signature: record.signature } : {}),\n publicKey: record.publicKey,\n status: record.status as SigningDriverStatus,\n ...(record.metadata\n ? {\n metadata:\n typeof record.metadata === 'string'\n ? JSON.parse(record.metadata)\n : record.metadata,\n }\n : {}),\n createdAt: new Date(record.createdAt),\n updatedAt: new Date(record.updatedAt),\n ...(record.signedAt ? { signedAt: new Date(record.signedAt) } : {}),\n }\n}\n\nexport const fromSigningDriverConfig = (\n config: SigningDriverConfig,\n userId: UserId\n): SigningDriverConfigRecord => {\n return {\n userId: userId,\n driverId: config.driverId,\n config: JSON.stringify(config.config),\n }\n}\n\nexport const toSigningDriverConfig = (\n record: SigningDriverConfigRecord\n): SigningDriverConfig => {\n return {\n driverId: record.driverId,\n config:\n typeof record.config === 'string'\n ? JSON.parse(record.config)\n : record.config,\n }\n}\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { UserId } from '@canton-network/core-wallet-auth'\nimport { storage } from '@wxt-dev/storage'\n\nconst STORAGE_LOCATION = 'local'\n\nexport function item<T>(key: string) {\n return storage.defineItem<T>(`${STORAGE_LOCATION}:${key}`)\n}\n\nexport function items<T>(key: string) {\n return storage.defineItem<T[]>(`${STORAGE_LOCATION}:${key}`, {\n fallback: [],\n })\n}\n\nexport const signingKeysItem = () => items<SigningKeyRecord>('signingKeys')\n\nexport const signingTransactionsItem = () =>\n items<SigningTransactionRecord>('signingTransactions')\n\nexport const signingDriverConfigItem = (driverId: string) =>\n item<SigningDriverConfigRecord>(`signingDriverConfigItem:${driverId}`)\n\nexport interface SigningKeyRecord {\n id: string\n userId: UserId\n name: string\n publicKey: string\n privateKey: string | null\n metadata: string | null\n createdAt: string\n updatedAt: string\n}\n\nexport interface SigningTransactionRecord {\n id: string\n userId: UserId\n hash: string\n signature: string | null\n publicKey: string\n status: string\n metadata: string | null\n createdAt: string\n updatedAt: string\n signedAt: string | null\n}\n\nexport interface SigningDriverConfigRecord {\n userId: UserId\n driverId: string\n config: string\n}\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n SigningDriverConfig,\n SigningDriverStatus,\n SigningDriverStore,\n SigningKey,\n SigningTransaction,\n} from '@canton-network/core-signing-lib'\nimport { UserId } from '@canton-network/core-wallet-auth'\nimport {\n toSigningKey,\n fromSigningKey,\n toSigningTransaction,\n fromSigningTransaction,\n toSigningDriverConfig,\n fromSigningDriverConfig,\n} from './schemas.js'\nimport {\n signingKeysItem,\n SigningKeyRecord,\n signingTransactionsItem,\n SigningTransactionRecord,\n signingDriverConfigItem,\n} from './items.js'\n\n/* eslint-disable @typescript-eslint/no-unused-vars */\n// this is required because the extension is single user, but we need to satisfy the SigningDriverStore interface\n\nexport class WxtStore implements SigningDriverStore {\n constructor(private userId: UserId) {}\n\n async getSigningKey(\n userId: string,\n keyId: string\n ): Promise<SigningKey | undefined> {\n const record = await signingKeysItem().getValue()\n const signingKey = record\n ? record.find((r) => r.id === keyId)\n : undefined\n\n return signingKey ? toSigningKey(signingKey) : undefined\n }\n async getSigningKeyByPublicKey(\n publicKey: string\n ): Promise<SigningKey | undefined> {\n const keys = await this.listSigningKeys(this.userId)\n return keys.find((key) => key.publicKey === publicKey)\n }\n async getSigningKeyByName(\n userId: string,\n name: string\n ): Promise<SigningKey | undefined> {\n const keys = await this.listSigningKeys(this.userId)\n return keys.find((key) => key.name === name)\n }\n async listSigningTransactionsByTxIdsAndPublicKeys(\n txIds: string[],\n publicKeys: string[]\n ): Promise<SigningTransaction[]> {\n if (!txIds.length && !publicKeys.length) return []\n\n const records = await this.listSigningTransactions(this.userId)\n\n return records.filter((record) => {\n if (!record) return false\n\n const matchesTxId = txIds.length > 0 && txIds.includes(record.id)\n const matchesPublicKey =\n publicKeys.length > 0 && publicKeys.includes(record.publicKey)\n\n return matchesTxId || matchesPublicKey\n })\n }\n\n async setSigningKey(userId: string, key: SigningKey): Promise<void> {\n const item = signingKeysItem()\n const keys = await item.getValue()\n const idx = keys?.findIndex((k) => k.id === key.id)\n const existing = idx >= 0 ? keys[idx] : undefined\n\n const serialized = fromSigningKey(key, userId)\n\n const updated: SigningKeyRecord = {\n ...serialized,\n createdAt: existing?.createdAt ?? serialized.createdAt,\n updatedAt: new Date().toISOString(),\n }\n\n const nextKeys =\n idx >= 0\n ? keys.map((key, index) => (index === idx ? updated : key))\n : [...keys, updated]\n\n await item.setValue(nextKeys)\n }\n async deleteSigningKey(userId: string, keyId: string): Promise<void> {\n const item = signingKeysItem()\n const keys = await item.getValue()\n\n const nextKeys = keys.filter((k) => k.id !== keyId)\n if (nextKeys.length !== keys.length) {\n await item.setValue(nextKeys)\n }\n }\n\n async listSigningKeys(userId: string): Promise<SigningKey[]> {\n const keys = await signingKeysItem().getValue()\n return keys.map((x) => toSigningKey(x))\n }\n async getSigningTransaction(\n userId: string,\n txId: string\n ): Promise<SigningTransaction | undefined> {\n const records = await signingTransactionsItem().getValue()\n\n const tx = records ? records.find((r) => r.id === txId) : undefined\n return tx ? toSigningTransaction(tx) : undefined\n }\n\n async setSigningTransaction(\n userId: string,\n transaction: SigningTransaction\n ): Promise<void> {\n const item = signingTransactionsItem()\n const txs = await item.getValue()\n const idx = txs?.findIndex((k) => k.id === transaction.id)\n const existing = idx >= 0 ? txs[idx] : undefined\n const serialized = fromSigningTransaction(transaction, userId)\n\n const updated: SigningTransactionRecord = {\n ...serialized,\n createdAt: existing?.createdAt ?? serialized.createdAt,\n updatedAt: new Date().toISOString(),\n }\n\n const nextKeys =\n idx >= 0\n ? txs.map((key, index) => (index === idx ? updated : key))\n : [...txs, updated]\n\n await item.setValue(nextKeys)\n }\n\n async updateSigningTransactionStatus(\n userId: string,\n txId: string,\n status: SigningDriverStatus\n ): Promise<void> {\n const signingTx = signingTransactionsItem()\n const txs = await signingTx.getValue()\n const idx = txs?.findIndex((tx) => tx.id === txId)\n if (idx === -1) {\n throw new Error(\n `No signing tx found for txId: ${txId}, userId: ${this.userId}`\n )\n }\n\n const updated: SigningTransactionRecord = {\n ...txs[idx],\n status: status,\n updatedAt: new Date().toISOString(),\n }\n\n const nextTxs = txs.map((t, i) => (i === idx ? updated : t))\n await signingTx.setValue(nextTxs)\n }\n async listSigningTransactions(\n userId: string,\n limit?: number,\n before?: string\n ): Promise<SigningTransaction[]> {\n const txs = (await signingTransactionsItem().getValue()).map((x) =>\n toSigningTransaction(x)\n )\n const validTxs = txs.sort((a, b) =>\n a.createdAt.toISOString().localeCompare(b.createdAt.toISOString())\n )\n\n let beforeDate: string | undefined = before\n\n if (before) {\n const isIsoDate = !isNaN(Date.parse(before)) && before.includes('T')\n if (!isIsoDate) {\n const targetTx = await this.getSigningTransaction(\n userId,\n before\n )\n if (targetTx) {\n beforeDate = targetTx.createdAt.toISOString()\n }\n }\n }\n\n const filteredTxs = beforeDate\n ? validTxs.filter((k) => k.createdAt.toISOString() < beforeDate!)\n : validTxs\n\n return limit ? filteredTxs.slice(0, limit) : filteredTxs\n }\n\n async getSigningDriverConfiguration(\n userId: string,\n driverId: string\n ): Promise<SigningDriverConfig | undefined> {\n const record = await signingDriverConfigItem(driverId).getValue()\n return record ? toSigningDriverConfig(record) : undefined\n }\n async setSigningDriverConfiguration(\n userId: string,\n config: SigningDriverConfig\n ): Promise<void> {\n const item = signingDriverConfigItem(config.driverId)\n const existing = await item.getValue()\n const serialized = fromSigningDriverConfig(config, userId)\n\n if (existing && existing.config === serialized.config) return\n\n await item.setValue(serialized)\n }\n async setSigningKeys(userId: string, keys: SigningKey[]): Promise<void> {\n const item = signingKeysItem()\n const existingKeys = await item.getValue()\n const keyMap = new Map(existingKeys.map((k) => [k.id, k]))\n\n for (const key of keys) {\n const existing = keyMap.get(key.id)\n const serialized = fromSigningKey(key, this.userId)\n keyMap.set(key.id, {\n ...serialized,\n createdAt: existing?.createdAt ?? serialized.createdAt,\n updatedAt: new Date().toISOString(),\n })\n }\n\n await item.setValue(Array.from(keyMap.values()))\n }\n async setSigningTransactions(\n userId: string,\n transactions: SigningTransaction[]\n ): Promise<void> {\n const item = signingTransactionsItem()\n const existingKeys = await item.getValue()\n const txMap = new Map(existingKeys.map((tx) => [tx.id, tx]))\n\n for (const tx of transactions) {\n const existing = txMap.get(tx.id)\n const serialized = fromSigningTransaction(tx, this.userId)\n txMap.set(tx.id, {\n ...serialized,\n createdAt: existing?.createdAt ?? serialized.createdAt,\n updatedAt: new Date().toISOString(),\n })\n }\n\n await item.setValue(Array.from(txMap.values()))\n }\n}\n"],"mappings":";;;AAgBA,MAAa,kBACT,KACA,QACA,YACmB;CACnB,OAAO;EACH,IAAI,IAAI;EACA;EACR,MAAM,IAAI;EACV,WAAW,IAAI;EACf,YAAY,IAAI,aACV,UACI,QAAQ,IAAI,UAAU,IACtB,IAAI,aACR;EACN,UAAU,IAAI,WAAW,KAAK,UAAU,IAAI,QAAQ,IAAI;EACxD,WAAW,IAAI,UAAU,YAAY;EACrC,WAAW,IAAI,UAAU,YAAY;CACzC;AACJ;AAEA,MAAa,gBACT,QACA,YACa;CACb,OAAO;EACH,IAAI,OAAO;EACX,MAAM,OAAO;EACb,WAAW,OAAO;EAClB,GAAI,OAAO,aACL,EACI,YAAY,UACN,QAAQ,OAAO,UAAU,IACzB,OAAO,WACjB,IACA,CAAC;EACP,WAAW,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IAC7C,4BAAW,IAAI,KAAK,EAAA,CAAE,YAAY;GACtC,CAAC;EACL;EAEA,MAAM,KAAK,SAAS,MAAM,KAAK,MAAM,OAAO,CAAC,CAAC;CAClD;AACJ"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { storage } from "@wxt-dev/storage";
|
|
2
|
+
//#region src/schemas.ts
|
|
3
|
+
const fromSigningKey = (key, userId, encrypt) => {
|
|
4
|
+
return {
|
|
5
|
+
id: key.id,
|
|
6
|
+
userId,
|
|
7
|
+
name: key.name,
|
|
8
|
+
publicKey: key.publicKey,
|
|
9
|
+
privateKey: key.privateKey ? encrypt ? encrypt(key.privateKey) : key.privateKey : null,
|
|
10
|
+
metadata: key.metadata ? JSON.stringify(key.metadata) : null,
|
|
11
|
+
createdAt: key.createdAt.toISOString(),
|
|
12
|
+
updatedAt: key.updatedAt.toISOString()
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
const toSigningKey = (record, decrypt) => {
|
|
16
|
+
return {
|
|
17
|
+
id: record.id,
|
|
18
|
+
name: record.name,
|
|
19
|
+
publicKey: record.publicKey,
|
|
20
|
+
...record.privateKey ? { privateKey: decrypt ? decrypt(record.privateKey) : record.privateKey } : {},
|
|
21
|
+
createdAt: new Date(record.createdAt),
|
|
22
|
+
updatedAt: new Date(record.updatedAt),
|
|
23
|
+
...record.metadata ? { metadata: typeof record.metadata === "string" ? JSON.parse(record.metadata) : record.metadata } : {}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const fromSigningTransaction = (transaction, userId) => {
|
|
27
|
+
return {
|
|
28
|
+
id: transaction.id,
|
|
29
|
+
userId,
|
|
30
|
+
hash: transaction.hash,
|
|
31
|
+
signature: transaction.signature || null,
|
|
32
|
+
publicKey: transaction.publicKey,
|
|
33
|
+
status: transaction.status,
|
|
34
|
+
metadata: transaction.metadata ? JSON.stringify(transaction.metadata) : null,
|
|
35
|
+
createdAt: transaction.createdAt.toISOString(),
|
|
36
|
+
updatedAt: transaction.updatedAt.toISOString(),
|
|
37
|
+
signedAt: transaction.signedAt?.toISOString() || null
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
const toSigningTransaction = (record) => {
|
|
41
|
+
return {
|
|
42
|
+
id: record.id,
|
|
43
|
+
hash: record.hash,
|
|
44
|
+
...record.signature ? { signature: record.signature } : {},
|
|
45
|
+
publicKey: record.publicKey,
|
|
46
|
+
status: record.status,
|
|
47
|
+
...record.metadata ? { metadata: typeof record.metadata === "string" ? JSON.parse(record.metadata) : record.metadata } : {},
|
|
48
|
+
createdAt: new Date(record.createdAt),
|
|
49
|
+
updatedAt: new Date(record.updatedAt),
|
|
50
|
+
...record.signedAt ? { signedAt: new Date(record.signedAt) } : {}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
const fromSigningDriverConfig = (config, userId) => {
|
|
54
|
+
return {
|
|
55
|
+
userId,
|
|
56
|
+
driverId: config.driverId,
|
|
57
|
+
config: JSON.stringify(config.config)
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const toSigningDriverConfig = (record) => {
|
|
61
|
+
return {
|
|
62
|
+
driverId: record.driverId,
|
|
63
|
+
config: typeof record.config === "string" ? JSON.parse(record.config) : record.config
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/items.ts
|
|
68
|
+
const STORAGE_LOCATION = "local";
|
|
69
|
+
function item(key) {
|
|
70
|
+
return storage.defineItem(`${STORAGE_LOCATION}:${key}`);
|
|
71
|
+
}
|
|
72
|
+
function items(key) {
|
|
73
|
+
return storage.defineItem(`${STORAGE_LOCATION}:${key}`, { fallback: [] });
|
|
74
|
+
}
|
|
75
|
+
const signingKeysItem = () => items("signingKeys");
|
|
76
|
+
const signingTransactionsItem = () => items("signingTransactions");
|
|
77
|
+
const signingDriverConfigItem = (driverId) => item(`signingDriverConfigItem:${driverId}`);
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/store-wxt.ts
|
|
80
|
+
var WxtStore = class {
|
|
81
|
+
constructor(userId) {
|
|
82
|
+
this.userId = userId;
|
|
83
|
+
}
|
|
84
|
+
async getSigningKey(userId, keyId) {
|
|
85
|
+
const record = await signingKeysItem().getValue();
|
|
86
|
+
const signingKey = record ? record.find((r) => r.id === keyId) : void 0;
|
|
87
|
+
return signingKey ? toSigningKey(signingKey) : void 0;
|
|
88
|
+
}
|
|
89
|
+
async getSigningKeyByPublicKey(publicKey) {
|
|
90
|
+
return (await this.listSigningKeys(this.userId)).find((key) => key.publicKey === publicKey);
|
|
91
|
+
}
|
|
92
|
+
async getSigningKeyByName(userId, name) {
|
|
93
|
+
return (await this.listSigningKeys(this.userId)).find((key) => key.name === name);
|
|
94
|
+
}
|
|
95
|
+
async listSigningTransactionsByTxIdsAndPublicKeys(txIds, publicKeys) {
|
|
96
|
+
if (!txIds.length && !publicKeys.length) return [];
|
|
97
|
+
return (await this.listSigningTransactions(this.userId)).filter((record) => {
|
|
98
|
+
if (!record) return false;
|
|
99
|
+
const matchesTxId = txIds.length > 0 && txIds.includes(record.id);
|
|
100
|
+
const matchesPublicKey = publicKeys.length > 0 && publicKeys.includes(record.publicKey);
|
|
101
|
+
return matchesTxId || matchesPublicKey;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
async setSigningKey(userId, key) {
|
|
105
|
+
const item = signingKeysItem();
|
|
106
|
+
const keys = await item.getValue();
|
|
107
|
+
const idx = keys?.findIndex((k) => k.id === key.id);
|
|
108
|
+
const existing = idx >= 0 ? keys[idx] : void 0;
|
|
109
|
+
const serialized = fromSigningKey(key, userId);
|
|
110
|
+
const updated = {
|
|
111
|
+
...serialized,
|
|
112
|
+
createdAt: existing?.createdAt ?? serialized.createdAt,
|
|
113
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
114
|
+
};
|
|
115
|
+
const nextKeys = idx >= 0 ? keys.map((key, index) => index === idx ? updated : key) : [...keys, updated];
|
|
116
|
+
await item.setValue(nextKeys);
|
|
117
|
+
}
|
|
118
|
+
async deleteSigningKey(userId, keyId) {
|
|
119
|
+
const item = signingKeysItem();
|
|
120
|
+
const keys = await item.getValue();
|
|
121
|
+
const nextKeys = keys.filter((k) => k.id !== keyId);
|
|
122
|
+
if (nextKeys.length !== keys.length) await item.setValue(nextKeys);
|
|
123
|
+
}
|
|
124
|
+
async listSigningKeys(userId) {
|
|
125
|
+
return (await signingKeysItem().getValue()).map((x) => toSigningKey(x));
|
|
126
|
+
}
|
|
127
|
+
async getSigningTransaction(userId, txId) {
|
|
128
|
+
const records = await signingTransactionsItem().getValue();
|
|
129
|
+
const tx = records ? records.find((r) => r.id === txId) : void 0;
|
|
130
|
+
return tx ? toSigningTransaction(tx) : void 0;
|
|
131
|
+
}
|
|
132
|
+
async setSigningTransaction(userId, transaction) {
|
|
133
|
+
const item = signingTransactionsItem();
|
|
134
|
+
const txs = await item.getValue();
|
|
135
|
+
const idx = txs?.findIndex((k) => k.id === transaction.id);
|
|
136
|
+
const existing = idx >= 0 ? txs[idx] : void 0;
|
|
137
|
+
const serialized = fromSigningTransaction(transaction, userId);
|
|
138
|
+
const updated = {
|
|
139
|
+
...serialized,
|
|
140
|
+
createdAt: existing?.createdAt ?? serialized.createdAt,
|
|
141
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
142
|
+
};
|
|
143
|
+
const nextKeys = idx >= 0 ? txs.map((key, index) => index === idx ? updated : key) : [...txs, updated];
|
|
144
|
+
await item.setValue(nextKeys);
|
|
145
|
+
}
|
|
146
|
+
async updateSigningTransactionStatus(userId, txId, status) {
|
|
147
|
+
const signingTx = signingTransactionsItem();
|
|
148
|
+
const txs = await signingTx.getValue();
|
|
149
|
+
const idx = txs?.findIndex((tx) => tx.id === txId);
|
|
150
|
+
if (idx === -1) throw new Error(`No signing tx found for txId: ${txId}, userId: ${this.userId}`);
|
|
151
|
+
const updated = {
|
|
152
|
+
...txs[idx],
|
|
153
|
+
status,
|
|
154
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
155
|
+
};
|
|
156
|
+
const nextTxs = txs.map((t, i) => i === idx ? updated : t);
|
|
157
|
+
await signingTx.setValue(nextTxs);
|
|
158
|
+
}
|
|
159
|
+
async listSigningTransactions(userId, limit, before) {
|
|
160
|
+
const validTxs = (await signingTransactionsItem().getValue()).map((x) => toSigningTransaction(x)).sort((a, b) => a.createdAt.toISOString().localeCompare(b.createdAt.toISOString()));
|
|
161
|
+
let beforeDate = before;
|
|
162
|
+
if (before) {
|
|
163
|
+
if (!(!isNaN(Date.parse(before)) && before.includes("T"))) {
|
|
164
|
+
const targetTx = await this.getSigningTransaction(userId, before);
|
|
165
|
+
if (targetTx) beforeDate = targetTx.createdAt.toISOString();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const filteredTxs = beforeDate ? validTxs.filter((k) => k.createdAt.toISOString() < beforeDate) : validTxs;
|
|
169
|
+
return limit ? filteredTxs.slice(0, limit) : filteredTxs;
|
|
170
|
+
}
|
|
171
|
+
async getSigningDriverConfiguration(userId, driverId) {
|
|
172
|
+
const record = await signingDriverConfigItem(driverId).getValue();
|
|
173
|
+
return record ? toSigningDriverConfig(record) : void 0;
|
|
174
|
+
}
|
|
175
|
+
async setSigningDriverConfiguration(userId, config) {
|
|
176
|
+
const item = signingDriverConfigItem(config.driverId);
|
|
177
|
+
const existing = await item.getValue();
|
|
178
|
+
const serialized = fromSigningDriverConfig(config, userId);
|
|
179
|
+
if (existing && existing.config === serialized.config) return;
|
|
180
|
+
await item.setValue(serialized);
|
|
181
|
+
}
|
|
182
|
+
async setSigningKeys(userId, keys) {
|
|
183
|
+
const item = signingKeysItem();
|
|
184
|
+
const existingKeys = await item.getValue();
|
|
185
|
+
const keyMap = new Map(existingKeys.map((k) => [k.id, k]));
|
|
186
|
+
for (const key of keys) {
|
|
187
|
+
const existing = keyMap.get(key.id);
|
|
188
|
+
const serialized = fromSigningKey(key, this.userId);
|
|
189
|
+
keyMap.set(key.id, {
|
|
190
|
+
...serialized,
|
|
191
|
+
createdAt: existing?.createdAt ?? serialized.createdAt,
|
|
192
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
await item.setValue(Array.from(keyMap.values()));
|
|
196
|
+
}
|
|
197
|
+
async setSigningTransactions(userId, transactions) {
|
|
198
|
+
const item = signingTransactionsItem();
|
|
199
|
+
const existingKeys = await item.getValue();
|
|
200
|
+
const txMap = new Map(existingKeys.map((tx) => [tx.id, tx]));
|
|
201
|
+
for (const tx of transactions) {
|
|
202
|
+
const existing = txMap.get(tx.id);
|
|
203
|
+
const serialized = fromSigningTransaction(tx, this.userId);
|
|
204
|
+
txMap.set(tx.id, {
|
|
205
|
+
...serialized,
|
|
206
|
+
createdAt: existing?.createdAt ?? serialized.createdAt,
|
|
207
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
await item.setValue(Array.from(txMap.values()));
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
//#endregion
|
|
214
|
+
export { WxtStore, fromSigningDriverConfig, fromSigningKey, fromSigningTransaction, toSigningDriverConfig, toSigningKey, toSigningTransaction };
|
|
215
|
+
|
|
216
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/schemas.ts","../src/items.ts","../src/store-wxt.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n SigningDriverConfig,\n SigningDriverStatus,\n SigningKey,\n SigningTransaction,\n} from '@canton-network/core-signing-lib'\nimport { UserId } from '@canton-network/core-wallet-auth'\nimport {\n SigningKeyRecord,\n SigningTransactionRecord,\n SigningDriverConfigRecord,\n} from './items.js'\n\nexport const fromSigningKey = (\n key: SigningKey,\n userId: UserId,\n encrypt?: (data: string) => string\n): SigningKeyRecord => {\n return {\n id: key.id,\n userId: userId,\n name: key.name,\n publicKey: key.publicKey,\n privateKey: key.privateKey\n ? encrypt\n ? encrypt(key.privateKey)\n : key.privateKey\n : null,\n metadata: key.metadata ? JSON.stringify(key.metadata) : null,\n createdAt: key.createdAt.toISOString(),\n updatedAt: key.updatedAt.toISOString(),\n }\n}\n\nexport const toSigningKey = (\n record: SigningKeyRecord,\n decrypt?: (data: string) => string\n): SigningKey => {\n return {\n id: record.id,\n name: record.name,\n publicKey: record.publicKey,\n ...(record.privateKey\n ? {\n privateKey: decrypt\n ? decrypt(record.privateKey)\n : record.privateKey,\n }\n : {}),\n createdAt: new Date(record.createdAt),\n updatedAt: new Date(record.updatedAt),\n ...(record.metadata\n ? {\n metadata:\n typeof record.metadata === 'string'\n ? JSON.parse(record.metadata)\n : record.metadata,\n }\n : {}),\n }\n}\n\nexport const fromSigningTransaction = (\n transaction: SigningTransaction,\n userId: UserId\n): SigningTransactionRecord => {\n return {\n id: transaction.id,\n userId: userId,\n hash: transaction.hash,\n signature: transaction.signature || null,\n publicKey: transaction.publicKey,\n status: transaction.status,\n metadata: transaction.metadata\n ? JSON.stringify(transaction.metadata)\n : null,\n createdAt: transaction.createdAt.toISOString(),\n updatedAt: transaction.updatedAt.toISOString(),\n signedAt: transaction.signedAt?.toISOString() || null,\n }\n}\n\nexport const toSigningTransaction = (\n record: SigningTransactionRecord\n): SigningTransaction => {\n return {\n id: record.id,\n hash: record.hash,\n ...(record.signature ? { signature: record.signature } : {}),\n publicKey: record.publicKey,\n status: record.status as SigningDriverStatus,\n ...(record.metadata\n ? {\n metadata:\n typeof record.metadata === 'string'\n ? JSON.parse(record.metadata)\n : record.metadata,\n }\n : {}),\n createdAt: new Date(record.createdAt),\n updatedAt: new Date(record.updatedAt),\n ...(record.signedAt ? { signedAt: new Date(record.signedAt) } : {}),\n }\n}\n\nexport const fromSigningDriverConfig = (\n config: SigningDriverConfig,\n userId: UserId\n): SigningDriverConfigRecord => {\n return {\n userId: userId,\n driverId: config.driverId,\n config: JSON.stringify(config.config),\n }\n}\n\nexport const toSigningDriverConfig = (\n record: SigningDriverConfigRecord\n): SigningDriverConfig => {\n return {\n driverId: record.driverId,\n config:\n typeof record.config === 'string'\n ? JSON.parse(record.config)\n : record.config,\n }\n}\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { UserId } from '@canton-network/core-wallet-auth'\nimport { storage } from '@wxt-dev/storage'\n\nconst STORAGE_LOCATION = 'local'\n\nexport function item<T>(key: string) {\n return storage.defineItem<T>(`${STORAGE_LOCATION}:${key}`)\n}\n\nexport function items<T>(key: string) {\n return storage.defineItem<T[]>(`${STORAGE_LOCATION}:${key}`, {\n fallback: [],\n })\n}\n\nexport const signingKeysItem = () => items<SigningKeyRecord>('signingKeys')\n\nexport const signingTransactionsItem = () =>\n items<SigningTransactionRecord>('signingTransactions')\n\nexport const signingDriverConfigItem = (driverId: string) =>\n item<SigningDriverConfigRecord>(`signingDriverConfigItem:${driverId}`)\n\nexport interface SigningKeyRecord {\n id: string\n userId: UserId\n name: string\n publicKey: string\n privateKey: string | null\n metadata: string | null\n createdAt: string\n updatedAt: string\n}\n\nexport interface SigningTransactionRecord {\n id: string\n userId: UserId\n hash: string\n signature: string | null\n publicKey: string\n status: string\n metadata: string | null\n createdAt: string\n updatedAt: string\n signedAt: string | null\n}\n\nexport interface SigningDriverConfigRecord {\n userId: UserId\n driverId: string\n config: string\n}\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n SigningDriverConfig,\n SigningDriverStatus,\n SigningDriverStore,\n SigningKey,\n SigningTransaction,\n} from '@canton-network/core-signing-lib'\nimport { UserId } from '@canton-network/core-wallet-auth'\nimport {\n toSigningKey,\n fromSigningKey,\n toSigningTransaction,\n fromSigningTransaction,\n toSigningDriverConfig,\n fromSigningDriverConfig,\n} from './schemas.js'\nimport {\n signingKeysItem,\n SigningKeyRecord,\n signingTransactionsItem,\n SigningTransactionRecord,\n signingDriverConfigItem,\n} from './items.js'\n\n/* eslint-disable @typescript-eslint/no-unused-vars */\n// this is required because the extension is single user, but we need to satisfy the SigningDriverStore interface\n\nexport class WxtStore implements SigningDriverStore {\n constructor(private userId: UserId) {}\n\n async getSigningKey(\n userId: string,\n keyId: string\n ): Promise<SigningKey | undefined> {\n const record = await signingKeysItem().getValue()\n const signingKey = record\n ? record.find((r) => r.id === keyId)\n : undefined\n\n return signingKey ? toSigningKey(signingKey) : undefined\n }\n async getSigningKeyByPublicKey(\n publicKey: string\n ): Promise<SigningKey | undefined> {\n const keys = await this.listSigningKeys(this.userId)\n return keys.find((key) => key.publicKey === publicKey)\n }\n async getSigningKeyByName(\n userId: string,\n name: string\n ): Promise<SigningKey | undefined> {\n const keys = await this.listSigningKeys(this.userId)\n return keys.find((key) => key.name === name)\n }\n async listSigningTransactionsByTxIdsAndPublicKeys(\n txIds: string[],\n publicKeys: string[]\n ): Promise<SigningTransaction[]> {\n if (!txIds.length && !publicKeys.length) return []\n\n const records = await this.listSigningTransactions(this.userId)\n\n return records.filter((record) => {\n if (!record) return false\n\n const matchesTxId = txIds.length > 0 && txIds.includes(record.id)\n const matchesPublicKey =\n publicKeys.length > 0 && publicKeys.includes(record.publicKey)\n\n return matchesTxId || matchesPublicKey\n })\n }\n\n async setSigningKey(userId: string, key: SigningKey): Promise<void> {\n const item = signingKeysItem()\n const keys = await item.getValue()\n const idx = keys?.findIndex((k) => k.id === key.id)\n const existing = idx >= 0 ? keys[idx] : undefined\n\n const serialized = fromSigningKey(key, userId)\n\n const updated: SigningKeyRecord = {\n ...serialized,\n createdAt: existing?.createdAt ?? serialized.createdAt,\n updatedAt: new Date().toISOString(),\n }\n\n const nextKeys =\n idx >= 0\n ? keys.map((key, index) => (index === idx ? updated : key))\n : [...keys, updated]\n\n await item.setValue(nextKeys)\n }\n async deleteSigningKey(userId: string, keyId: string): Promise<void> {\n const item = signingKeysItem()\n const keys = await item.getValue()\n\n const nextKeys = keys.filter((k) => k.id !== keyId)\n if (nextKeys.length !== keys.length) {\n await item.setValue(nextKeys)\n }\n }\n\n async listSigningKeys(userId: string): Promise<SigningKey[]> {\n const keys = await signingKeysItem().getValue()\n return keys.map((x) => toSigningKey(x))\n }\n async getSigningTransaction(\n userId: string,\n txId: string\n ): Promise<SigningTransaction | undefined> {\n const records = await signingTransactionsItem().getValue()\n\n const tx = records ? records.find((r) => r.id === txId) : undefined\n return tx ? toSigningTransaction(tx) : undefined\n }\n\n async setSigningTransaction(\n userId: string,\n transaction: SigningTransaction\n ): Promise<void> {\n const item = signingTransactionsItem()\n const txs = await item.getValue()\n const idx = txs?.findIndex((k) => k.id === transaction.id)\n const existing = idx >= 0 ? txs[idx] : undefined\n const serialized = fromSigningTransaction(transaction, userId)\n\n const updated: SigningTransactionRecord = {\n ...serialized,\n createdAt: existing?.createdAt ?? serialized.createdAt,\n updatedAt: new Date().toISOString(),\n }\n\n const nextKeys =\n idx >= 0\n ? txs.map((key, index) => (index === idx ? updated : key))\n : [...txs, updated]\n\n await item.setValue(nextKeys)\n }\n\n async updateSigningTransactionStatus(\n userId: string,\n txId: string,\n status: SigningDriverStatus\n ): Promise<void> {\n const signingTx = signingTransactionsItem()\n const txs = await signingTx.getValue()\n const idx = txs?.findIndex((tx) => tx.id === txId)\n if (idx === -1) {\n throw new Error(\n `No signing tx found for txId: ${txId}, userId: ${this.userId}`\n )\n }\n\n const updated: SigningTransactionRecord = {\n ...txs[idx],\n status: status,\n updatedAt: new Date().toISOString(),\n }\n\n const nextTxs = txs.map((t, i) => (i === idx ? updated : t))\n await signingTx.setValue(nextTxs)\n }\n async listSigningTransactions(\n userId: string,\n limit?: number,\n before?: string\n ): Promise<SigningTransaction[]> {\n const txs = (await signingTransactionsItem().getValue()).map((x) =>\n toSigningTransaction(x)\n )\n const validTxs = txs.sort((a, b) =>\n a.createdAt.toISOString().localeCompare(b.createdAt.toISOString())\n )\n\n let beforeDate: string | undefined = before\n\n if (before) {\n const isIsoDate = !isNaN(Date.parse(before)) && before.includes('T')\n if (!isIsoDate) {\n const targetTx = await this.getSigningTransaction(\n userId,\n before\n )\n if (targetTx) {\n beforeDate = targetTx.createdAt.toISOString()\n }\n }\n }\n\n const filteredTxs = beforeDate\n ? validTxs.filter((k) => k.createdAt.toISOString() < beforeDate!)\n : validTxs\n\n return limit ? filteredTxs.slice(0, limit) : filteredTxs\n }\n\n async getSigningDriverConfiguration(\n userId: string,\n driverId: string\n ): Promise<SigningDriverConfig | undefined> {\n const record = await signingDriverConfigItem(driverId).getValue()\n return record ? toSigningDriverConfig(record) : undefined\n }\n async setSigningDriverConfiguration(\n userId: string,\n config: SigningDriverConfig\n ): Promise<void> {\n const item = signingDriverConfigItem(config.driverId)\n const existing = await item.getValue()\n const serialized = fromSigningDriverConfig(config, userId)\n\n if (existing && existing.config === serialized.config) return\n\n await item.setValue(serialized)\n }\n async setSigningKeys(userId: string, keys: SigningKey[]): Promise<void> {\n const item = signingKeysItem()\n const existingKeys = await item.getValue()\n const keyMap = new Map(existingKeys.map((k) => [k.id, k]))\n\n for (const key of keys) {\n const existing = keyMap.get(key.id)\n const serialized = fromSigningKey(key, this.userId)\n keyMap.set(key.id, {\n ...serialized,\n createdAt: existing?.createdAt ?? serialized.createdAt,\n updatedAt: new Date().toISOString(),\n })\n }\n\n await item.setValue(Array.from(keyMap.values()))\n }\n async setSigningTransactions(\n userId: string,\n transactions: SigningTransaction[]\n ): Promise<void> {\n const item = signingTransactionsItem()\n const existingKeys = await item.getValue()\n const txMap = new Map(existingKeys.map((tx) => [tx.id, tx]))\n\n for (const tx of transactions) {\n const existing = txMap.get(tx.id)\n const serialized = fromSigningTransaction(tx, this.userId)\n txMap.set(tx.id, {\n ...serialized,\n createdAt: existing?.createdAt ?? serialized.createdAt,\n updatedAt: new Date().toISOString(),\n })\n }\n\n await item.setValue(Array.from(txMap.values()))\n }\n}\n"],"mappings":";;AAgBA,MAAa,kBACT,KACA,QACA,YACmB;CACnB,OAAO;EACH,IAAI,IAAI;EACA;EACR,MAAM,IAAI;EACV,WAAW,IAAI;EACf,YAAY,IAAI,aACV,UACI,QAAQ,IAAI,UAAU,IACtB,IAAI,aACR;EACN,UAAU,IAAI,WAAW,KAAK,UAAU,IAAI,QAAQ,IAAI;EACxD,WAAW,IAAI,UAAU,YAAY;EACrC,WAAW,IAAI,UAAU,YAAY;CACzC;AACJ;AAEA,MAAa,gBACT,QACA,YACa;CACb,OAAO;EACH,IAAI,OAAO;EACX,MAAM,OAAO;EACb,WAAW,OAAO;EAClB,GAAI,OAAO,aACL,EACI,YAAY,UACN,QAAQ,OAAO,UAAU,IACzB,OAAO,WACjB,IACA,CAAC;EACP,WAAW,IAAI,KAAK,OAAO,SAAS;EACpC,WAAW,IAAI,KAAK,OAAO,SAAS;EACpC,GAAI,OAAO,WACL,EACI,UACI,OAAO,OAAO,aAAa,WACrB,KAAK,MAAM,OAAO,QAAQ,IAC1B,OAAO,SACrB,IACA,CAAC;CACX;AACJ;AAEA,MAAa,0BACT,aACA,WAC2B;CAC3B,OAAO;EACH,IAAI,YAAY;EACR;EACR,MAAM,YAAY;EAClB,WAAW,YAAY,aAAa;EACpC,WAAW,YAAY;EACvB,QAAQ,YAAY;EACpB,UAAU,YAAY,WAChB,KAAK,UAAU,YAAY,QAAQ,IACnC;EACN,WAAW,YAAY,UAAU,YAAY;EAC7C,WAAW,YAAY,UAAU,YAAY;EAC7C,UAAU,YAAY,UAAU,YAAY,KAAK;CACrD;AACJ;AAEA,MAAa,wBACT,WACqB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IAAI,CAAC,CAAC,CAAC;EAEzD,KAAK,MAAM,OAAO,MAAM;GACpB,MAAM,WAAW,OAAO,IAAI,IAAI,EAAE;GAClC,MAAM,aAAa,eAAe,KAAK,KAAK,MAAM;GAClD,OAAO,IAAI,IAAI,IAAI;IACf,GAAG;IACH,WAAW,UAAU,aAAa,WAAW;IAC7C,4BAAW,IAAI,KAAK,EAAA,CAAE,YAAY;GACtC,CAAC;EACL;EAEA,MAAM,KAAK,SAAS,MAAM,KAAK,OAAO,OAAO,CAAC,CAAC;CACnD;CACA,MAAM,uBACF,QACA,cACa;EACb,MAAM,OAAO,wBAAwB;EACrC,MAAM,eAAe,MAAM,KAAK,SAAS;EACzC,MAAM,QAAQ,IAAI,IAAI,aAAa,KAAK,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;EAE3D,KAAK,MAAM,MAAM,cAAc;GAC3B,MAAM,WAAW,MAAM,IAAI,GAAG,EAAE;GAChC,MAAM,aAAa,uBAAuB,IAAI,KAAK,MAAM;GACzD,MAAM,IAAI,GAAG,IAAI;IACb,GAAG;IACH,WAAW,UAAU,aAAa,WAAW;IAC7C,4BAAW,IAAI,KAAK,EAAA,CAAE,YAAY;GACtC,CAAC;EACL;EAEA,MAAM,KAAK,SAAS,MAAM,KAAK,MAAM,OAAO,CAAC,CAAC;CAClD;AACJ"}
|
package/dist/items.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { UserId } from '@canton-network/core-wallet-auth';
|
|
2
|
+
export declare function item<T>(key: string): import("@wxt-dev/storage").WxtStorageItem<T | null, {}>;
|
|
3
|
+
export declare function items<T>(key: string): import("@wxt-dev/storage").WxtStorageItem<T[], {}>;
|
|
4
|
+
export declare const signingKeysItem: () => import("@wxt-dev/storage").WxtStorageItem<SigningKeyRecord[], {}>;
|
|
5
|
+
export declare const signingTransactionsItem: () => import("@wxt-dev/storage").WxtStorageItem<SigningTransactionRecord[], {}>;
|
|
6
|
+
export declare const signingDriverConfigItem: (driverId: string) => import("@wxt-dev/storage").WxtStorageItem<SigningDriverConfigRecord | null, {}>;
|
|
7
|
+
export interface SigningKeyRecord {
|
|
8
|
+
id: string;
|
|
9
|
+
userId: UserId;
|
|
10
|
+
name: string;
|
|
11
|
+
publicKey: string;
|
|
12
|
+
privateKey: string | null;
|
|
13
|
+
metadata: string | null;
|
|
14
|
+
createdAt: string;
|
|
15
|
+
updatedAt: string;
|
|
16
|
+
}
|
|
17
|
+
export interface SigningTransactionRecord {
|
|
18
|
+
id: string;
|
|
19
|
+
userId: UserId;
|
|
20
|
+
hash: string;
|
|
21
|
+
signature: string | null;
|
|
22
|
+
publicKey: string;
|
|
23
|
+
status: string;
|
|
24
|
+
metadata: string | null;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
updatedAt: string;
|
|
27
|
+
signedAt: string | null;
|
|
28
|
+
}
|
|
29
|
+
export interface SigningDriverConfigRecord {
|
|
30
|
+
userId: UserId;
|
|
31
|
+
driverId: string;
|
|
32
|
+
config: string;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=items.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"items.d.ts","sourceRoot":"","sources":["../src/items.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AAKzD,wBAAgB,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,2DAElC;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,sDAInC;AAED,eAAO,MAAM,eAAe,yEAA+C,CAAA;AAE3E,eAAO,MAAM,uBAAuB,iFACsB,CAAA;AAE1D,eAAO,MAAM,uBAAuB,GAAI,UAAU,MAAM,oFACkB,CAAA;AAE1E,MAAM,WAAW,gBAAgB;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,wBAAwB;IACrC,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1B;AAED,MAAM,WAAW,yBAAyB;IACtC,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACjB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SigningDriverConfig, SigningKey, SigningTransaction } from '@canton-network/core-signing-lib';
|
|
2
|
+
import { UserId } from '@canton-network/core-wallet-auth';
|
|
3
|
+
import { SigningKeyRecord, SigningTransactionRecord, SigningDriverConfigRecord } from './items.js';
|
|
4
|
+
export declare const fromSigningKey: (key: SigningKey, userId: UserId, encrypt?: (data: string) => string) => SigningKeyRecord;
|
|
5
|
+
export declare const toSigningKey: (record: SigningKeyRecord, decrypt?: (data: string) => string) => SigningKey;
|
|
6
|
+
export declare const fromSigningTransaction: (transaction: SigningTransaction, userId: UserId) => SigningTransactionRecord;
|
|
7
|
+
export declare const toSigningTransaction: (record: SigningTransactionRecord) => SigningTransaction;
|
|
8
|
+
export declare const fromSigningDriverConfig: (config: SigningDriverConfig, userId: UserId) => SigningDriverConfigRecord;
|
|
9
|
+
export declare const toSigningDriverConfig: (record: SigningDriverConfigRecord) => SigningDriverConfig;
|
|
10
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,mBAAmB,EAEnB,UAAU,EACV,kBAAkB,EACrB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AACzD,OAAO,EACH,gBAAgB,EAChB,wBAAwB,EACxB,yBAAyB,EAC5B,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,cAAc,GACvB,KAAK,UAAU,EACf,QAAQ,MAAM,EACd,UAAU,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,KACnC,gBAeF,CAAA;AAED,eAAO,MAAM,YAAY,GACrB,QAAQ,gBAAgB,EACxB,UAAU,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,KACnC,UAuBF,CAAA;AAED,eAAO,MAAM,sBAAsB,GAC/B,aAAa,kBAAkB,EAC/B,QAAQ,MAAM,KACf,wBAeF,CAAA;AAED,eAAO,MAAM,oBAAoB,GAC7B,QAAQ,wBAAwB,KACjC,kBAmBF,CAAA;AAED,eAAO,MAAM,uBAAuB,GAChC,QAAQ,mBAAmB,EAC3B,QAAQ,MAAM,KACf,yBAMF,CAAA;AAED,eAAO,MAAM,qBAAqB,GAC9B,QAAQ,yBAAyB,KAClC,mBAQF,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SigningDriverConfig, SigningDriverStatus, SigningDriverStore, SigningKey, SigningTransaction } from '@canton-network/core-signing-lib';
|
|
2
|
+
import { UserId } from '@canton-network/core-wallet-auth';
|
|
3
|
+
export declare class WxtStore implements SigningDriverStore {
|
|
4
|
+
private userId;
|
|
5
|
+
constructor(userId: UserId);
|
|
6
|
+
getSigningKey(userId: string, keyId: string): Promise<SigningKey | undefined>;
|
|
7
|
+
getSigningKeyByPublicKey(publicKey: string): Promise<SigningKey | undefined>;
|
|
8
|
+
getSigningKeyByName(userId: string, name: string): Promise<SigningKey | undefined>;
|
|
9
|
+
listSigningTransactionsByTxIdsAndPublicKeys(txIds: string[], publicKeys: string[]): Promise<SigningTransaction[]>;
|
|
10
|
+
setSigningKey(userId: string, key: SigningKey): Promise<void>;
|
|
11
|
+
deleteSigningKey(userId: string, keyId: string): Promise<void>;
|
|
12
|
+
listSigningKeys(userId: string): Promise<SigningKey[]>;
|
|
13
|
+
getSigningTransaction(userId: string, txId: string): Promise<SigningTransaction | undefined>;
|
|
14
|
+
setSigningTransaction(userId: string, transaction: SigningTransaction): Promise<void>;
|
|
15
|
+
updateSigningTransactionStatus(userId: string, txId: string, status: SigningDriverStatus): Promise<void>;
|
|
16
|
+
listSigningTransactions(userId: string, limit?: number, before?: string): Promise<SigningTransaction[]>;
|
|
17
|
+
getSigningDriverConfiguration(userId: string, driverId: string): Promise<SigningDriverConfig | undefined>;
|
|
18
|
+
setSigningDriverConfiguration(userId: string, config: SigningDriverConfig): Promise<void>;
|
|
19
|
+
setSigningKeys(userId: string, keys: SigningKey[]): Promise<void>;
|
|
20
|
+
setSigningTransactions(userId: string, transactions: SigningTransaction[]): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=store-wxt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-wxt.d.ts","sourceRoot":"","sources":["../src/store-wxt.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,UAAU,EACV,kBAAkB,EACrB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AAoBzD,qBAAa,QAAS,YAAW,kBAAkB;IACnC,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAE5B,aAAa,CACf,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACd,OAAO,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,OAAO,CAAC,IAAI,CAAC;IASV,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBjE,sBAAsB,CACxB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,kBAAkB,EAAE,GACnC,OAAO,CAAC,IAAI,CAAC;CAiBnB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@canton-network/core-signing-store-wxt",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "WXT implementation of the Store API",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "Marc Juchli <marc.juchli@digitalasset.com>",
|
|
8
|
+
"main": "dist/index.cjs",
|
|
9
|
+
"module": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@wxt-dev/storage": "^1.2.9",
|
|
21
|
+
"wxt": "^0.21.4",
|
|
22
|
+
"@canton-network/core-ledger-client": "^1.11.0",
|
|
23
|
+
"@canton-network/core-rpc-errors": "^1.10.0",
|
|
24
|
+
"@canton-network/core-signing-lib": "^1.11.0",
|
|
25
|
+
"@canton-network/core-wallet-auth": "^1.11.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@swc/core": "^1.15.43",
|
|
29
|
+
"tsdown": "^0.22.9",
|
|
30
|
+
"tsx": "^4.23.0",
|
|
31
|
+
"typescript": "^5.9.3",
|
|
32
|
+
"vitest": "^4.1.10"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist/**"
|
|
36
|
+
],
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/canton-network/wallet.git",
|
|
43
|
+
"directory": "core/signing-store-sql"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/canton-network/wallet/tree/main/core/signing-store-sql#readme",
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/canton-network/wallet/issues"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsdown --onSuccess \"tsc\"",
|
|
51
|
+
"flatpack": "pnpm pack --pack-destination \"$FLATPACK_OUTDIR\"",
|
|
52
|
+
"clean": "tsc -b --clean; rm -rf dist",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"test:coverage": "vitest run --coverage"
|
|
55
|
+
}
|
|
56
|
+
}
|