@parity/product-sdk 0.0.0-dev.312.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 +201 -0
- package/dist/address/index.d.ts +9 -0
- package/dist/address/index.js +3 -0
- package/dist/address/index.js.map +1 -0
- package/dist/chain/index.d.ts +1 -0
- package/dist/chain/index.js +3 -0
- package/dist/chain/index.js.map +1 -0
- package/dist/chunk-BRZNHTLQ.js +89 -0
- package/dist/chunk-BRZNHTLQ.js.map +1 -0
- package/dist/chunk-DHRCWMY5.js +240 -0
- package/dist/chunk-DHRCWMY5.js.map +1 -0
- package/dist/chunk-JVJ552RU.js +3 -0
- package/dist/chunk-JVJ552RU.js.map +1 -0
- package/dist/cloud-storage/index.d.ts +1 -0
- package/dist/cloud-storage/index.js +3 -0
- package/dist/cloud-storage/index.js.map +1 -0
- package/dist/contracts/index.d.ts +1 -0
- package/dist/contracts/index.js +3 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/core/index.d.ts +12 -0
- package/dist/core/index.js +5 -0
- package/dist/core/index.js.map +1 -0
- package/dist/crypto/index.d.ts +1 -0
- package/dist/crypto/index.js +3 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/dotns-bswWAmR2.d.ts +136 -0
- package/dist/host/index.d.ts +1 -0
- package/dist/host/index.js +3 -0
- package/dist/host/index.js.map +1 -0
- package/dist/identity/index.d.ts +491 -0
- package/dist/identity/index.js +691 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/individuality/index.d.ts +1 -0
- package/dist/individuality/index.js +3 -0
- package/dist/individuality/index.js.map +1 -0
- package/dist/local-storage/index.d.ts +1 -0
- package/dist/local-storage/index.js +3 -0
- package/dist/local-storage/index.js.map +1 -0
- package/dist/react/index.d.ts +181 -0
- package/dist/react/index.js +198 -0
- package/dist/react/index.js.map +1 -0
- package/dist/testing/index.d.ts +61 -0
- package/dist/testing/index.js +149 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/types-B5Zx4RNq.d.ts +211 -0
- package/dist/wallet/index.d.ts +1 -0
- package/dist/wallet/index.js +3 -0
- package/dist/wallet/index.js.map +1 -0
- package/package.json +118 -0
- package/src/address/index.ts +8 -0
- package/src/chain/index.ts +8 -0
- package/src/cloud-storage/index.ts +8 -0
- package/src/contracts/index.ts +8 -0
- package/src/core/createApp.ts +408 -0
- package/src/core/index.ts +12 -0
- package/src/core/logger.ts +15 -0
- package/src/core/types.ts +233 -0
- package/src/crypto/index.ts +8 -0
- package/src/host/index.ts +8 -0
- package/src/identity/dotns-abis.test.ts +43 -0
- package/src/identity/dotns-abis.ts +274 -0
- package/src/identity/dotns-errors.ts +34 -0
- package/src/identity/dotns-namehash.test.ts +155 -0
- package/src/identity/dotns-namehash.ts +149 -0
- package/src/identity/dotns-owner.test.ts +92 -0
- package/src/identity/dotns-registry.test.ts +1154 -0
- package/src/identity/dotns-registry.ts +870 -0
- package/src/identity/dotns.test.ts +128 -0
- package/src/identity/dotns.ts +221 -0
- package/src/identity/index.ts +61 -0
- package/src/identity/product-account.test.ts +130 -0
- package/src/identity/product-account.ts +115 -0
- package/src/identity/types.ts +87 -0
- package/src/index.ts +61 -0
- package/src/individuality/contract.test.ts +135 -0
- package/src/individuality/index.ts +8 -0
- package/src/local-storage/index.ts +8 -0
- package/src/react/context.ts +35 -0
- package/src/react/index.ts +43 -0
- package/src/react/provider.tsx +78 -0
- package/src/react/useChain.ts +35 -0
- package/src/react/useLocalStorage.ts +127 -0
- package/src/react/useWallet.ts +156 -0
- package/src/testing.ts +297 -0
- package/src/wallet/index.ts +11 -0
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 [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.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from '@parity/product-sdk-address';
|
|
2
|
+
import '@parity/product-sdk-cloud-storage';
|
|
3
|
+
import '@parity/product-sdk-chain-client';
|
|
4
|
+
import '@parity/product-sdk-contracts';
|
|
5
|
+
import '@parity/product-sdk-crypto';
|
|
6
|
+
import '@parity/product-sdk-host';
|
|
7
|
+
import '@parity/product-sdk-individuality';
|
|
8
|
+
import '@parity/product-sdk-local-storage';
|
|
9
|
+
import '@parity/product-sdk-signer';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@parity/product-sdk-chain-client';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { bytesToHex, hexToBytes, keccak256 } from '@parity/product-sdk-crypto';
|
|
2
|
+
import { accountIdBytes } from '@parity/product-sdk-address';
|
|
3
|
+
|
|
4
|
+
// src/identity/dotns-namehash.ts
|
|
5
|
+
var DOT_NODE = "0x3fce7d1364a893e213bc4212792b517ffc88f5b13b86c8ef9c8d390c3a1370ce";
|
|
6
|
+
var ZERO_NODE = `0x${"00".repeat(32)}`;
|
|
7
|
+
var utf8 = (s) => new TextEncoder().encode(s);
|
|
8
|
+
function nodeUnder(parent, label) {
|
|
9
|
+
const combined = new Uint8Array(64);
|
|
10
|
+
combined.set(parent, 0);
|
|
11
|
+
combined.set(keccak256(utf8(label)), 32);
|
|
12
|
+
return keccak256(combined);
|
|
13
|
+
}
|
|
14
|
+
function dotNsTld(suffix) {
|
|
15
|
+
const label = suffix.startsWith(".") ? suffix.slice(1) : suffix;
|
|
16
|
+
return {
|
|
17
|
+
suffix: `.${label}`,
|
|
18
|
+
node: `0x${bytesToHex(nodeUnder(hexToBytes(ZERO_NODE.slice(2)), label))}`
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function isConsistentDotNsTld(tld) {
|
|
22
|
+
const label = tld.suffix.startsWith(".") ? tld.suffix.slice(1) : tld.suffix;
|
|
23
|
+
if (label.length === 0 || label.includes(".")) return false;
|
|
24
|
+
if (tld.node.toLowerCase() === ZERO_NODE) return false;
|
|
25
|
+
return dotNsTld(label).node.toLowerCase() === tld.node.toLowerCase();
|
|
26
|
+
}
|
|
27
|
+
var DOT_TLD = { suffix: ".dot", node: DOT_NODE };
|
|
28
|
+
function stripSuffix(name, suffix) {
|
|
29
|
+
return name.endsWith(suffix) ? name.slice(0, -suffix.length) : name;
|
|
30
|
+
}
|
|
31
|
+
function namehash(name, tld) {
|
|
32
|
+
const trimmed = stripSuffix(name, tld.suffix);
|
|
33
|
+
const labels = trimmed === "" ? [] : trimmed.split(".");
|
|
34
|
+
let node = hexToBytes(tld.node.slice(2));
|
|
35
|
+
for (let i = labels.length - 1; i >= 0; i--) {
|
|
36
|
+
node = nodeUnder(node, labels[i]);
|
|
37
|
+
}
|
|
38
|
+
return `0x${bytesToHex(node)}`;
|
|
39
|
+
}
|
|
40
|
+
function isValidDotNsName(name, suffix) {
|
|
41
|
+
if (!name.endsWith(suffix)) return false;
|
|
42
|
+
return isValidLabel(stripSuffix(name, suffix));
|
|
43
|
+
}
|
|
44
|
+
function isValidLabel(label) {
|
|
45
|
+
if (label.length < 3 || label.length > 63) return false;
|
|
46
|
+
return /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(label);
|
|
47
|
+
}
|
|
48
|
+
function isResolvableDotNsName(name, suffix) {
|
|
49
|
+
if (!name.endsWith(suffix)) return false;
|
|
50
|
+
const labels = stripSuffix(name, suffix).split(".");
|
|
51
|
+
return labels.length > 0 && labels.every(isValidLabel);
|
|
52
|
+
}
|
|
53
|
+
function normalizeDotNsName(name, suffix) {
|
|
54
|
+
const folded = name.trim().normalize("NFC").toLowerCase();
|
|
55
|
+
const normalized = folded.endsWith(".") ? folded.slice(0, -1) : folded;
|
|
56
|
+
return normalized.includes(".") ? normalized : normalized + suffix;
|
|
57
|
+
}
|
|
58
|
+
async function resolvePeopleUsernameOwner(username, peopleApi) {
|
|
59
|
+
const owner = await peopleApi.query.Resources.UsernameOwnerOf.getValue(
|
|
60
|
+
new TextEncoder().encode(username)
|
|
61
|
+
);
|
|
62
|
+
return owner ?? null;
|
|
63
|
+
}
|
|
64
|
+
function assertHex(value) {
|
|
65
|
+
if (!/^0x[0-9a-fA-F]*$/.test(value)) {
|
|
66
|
+
throw new Error(`Expected 0x-prefixed hex string, got ${value}`);
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
function accountIdHexToBytes(accountId) {
|
|
71
|
+
const bytes = hexToBytes(assertHex(accountId).slice(2));
|
|
72
|
+
if (bytes.length !== 32) {
|
|
73
|
+
throw new Error(`Expected 32-byte AccountId, got ${bytes.length} bytes`);
|
|
74
|
+
}
|
|
75
|
+
return bytes;
|
|
76
|
+
}
|
|
77
|
+
function accountIdBytesToHex(bytes) {
|
|
78
|
+
if (bytes.length !== 32) {
|
|
79
|
+
throw new Error(`Expected 32-byte AccountId, got ${bytes.length} bytes`);
|
|
80
|
+
}
|
|
81
|
+
return `0x${bytesToHex(bytes)}`;
|
|
82
|
+
}
|
|
83
|
+
function accountIdToHex(address) {
|
|
84
|
+
return accountIdBytesToHex(accountIdBytes(address));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { DOT_NODE, DOT_TLD, accountIdBytesToHex, accountIdHexToBytes, accountIdToHex, dotNsTld, isConsistentDotNsTld, isResolvableDotNsName, isValidDotNsName, namehash, normalizeDotNsName, resolvePeopleUsernameOwner, stripSuffix };
|
|
88
|
+
//# sourceMappingURL=chunk-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EAAG;AACjC,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,qCAAA,EAAwC,KAAK,CAAA,CAAE,CAAA;AAAA,EACnE;AACA,EAAA,OAAO,KAAA;AACX;AAEO,SAAS,oBAAoB,SAAA,EAAsC;AACtE,EAAA,MAAM,QAAQA,UAAAA,CAAW,SAAA,CAAU,SAAS,CAAA,CAAE,KAAA,CAAM,CAAC,CAAC,CAAA;AACtD,EAAA,IAAI,KAAA,CAAM,WAAW,EAAA,EAAI;AACrB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,gCAAA,EAAmC,KAAA,CAAM,MAAM,CAAA,MAAA,CAAQ,CAAA;AAAA,EAC3E;AACA,EAAA,OAAO,KAAA;AACX;AAGO,SAAS,oBAAoB,KAAA,EAAkC;AAClE,EAAA,IAAI,KAAA,CAAM,WAAW,EAAA,EAAI;AACrB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,gCAAA,EAAmC,KAAA,CAAM,MAAM,CAAA,MAAA,CAAQ,CAAA;AAAA,EAC3E;AACA,EAAA,OAAO,CAAA,EAAA,EAAKC,UAAAA,CAAW,KAAK,CAAC,CAAA,CAAA;AACjC;AAQO,SAAS,eAAe,OAAA,EAAgC;AAC3D,EAAA,OAAO,mBAAA,CAAoB,cAAA,CAAe,OAAO,CAAC,CAAA;AACtD","file":"chunk-BRZNHTLQ.js","sourcesContent":["// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * DotNS namehash.\n *\n * ENS-style recursive hashing, but rooted at the network's TLD node rather than\n * the empty root — matching `DotnsRegistry` (`contracts/registry/DotnsRegistry.sol`\n * `_namehash`) and `LabelUtils.namehashUnder`.\n *\n * labelhash(l) = keccak256(utf8(l))\n * node(parent, l) = keccak256(parent ‖ labelhash(l))\n * node(\"alice.paseo\") = node(tldNode, \"alice\")\n * node(\"bob.alice.paseo\") = node(node(tldNode, \"alice\"), \"bob\")\n *\n * The root is **per network**, not a constant. `DotnsProtocolRegistry.initialize`\n * fixes it once from a deploy-time label — `.dot` on Paseo Asset Hub Previewnet,\n * `.paseo` on Next V2 — and publishes it as `tld()` / `tldNode()`. Hashing under\n * the wrong root yields a node the chain has never written to, so every lookup\n * reports \"unregistered\" with no error anywhere. That is why {@link namehash}\n * takes the root rather than assuming one; `resolveTld` in `./dotns-registry.js`\n * is what asks the chain for it.\n */\nimport { bytesToHex, hexToBytes, keccak256 } from \"@parity/product-sdk-crypto\";\n\n/**\n * A network's DotNS top-level domain: the suffix names are spelled with, and\n * the node every one of its names hashes onto.\n *\n * The two must agree — `node` is `namehash(0, labelhash(label))` of `suffix`'s\n * label — so build one with {@link dotNsTld} rather than by hand, and check an\n * externally supplied pair with {@link isConsistentDotNsTld}. A `.paseo` suffix\n * carrying the `.dot` node is exactly the defect this type exists to prevent.\n */\nexport interface DotNsTld {\n /** Suffix including the leading dot, as `protocolRegistry.tld()` returns it. */\n suffix: string;\n /** Namehash of the TLD label, as `protocolRegistry.tldNode()` returns it. */\n node: `0x${string}`;\n}\n\n/** The `.dot` TLD node. Mirrors the `DotnsConstants.DOT_NODE` the contracts removed in `b4096968`. */\nexport const DOT_NODE = \"0x3fce7d1364a893e213bc4212792b517ffc88f5b13b86c8ef9c8d390c3a1370ce\";\n\nconst ZERO_NODE = `0x${\"00\".repeat(32)}`;\n\nconst utf8 = (s: string): Uint8Array => new TextEncoder().encode(s);\n\n/** `keccak256(parent ‖ labelhash(label))`, the one hash step every node is built from. */\nfunction nodeUnder(parent: Uint8Array, label: string): Uint8Array {\n const combined = new Uint8Array(64);\n combined.set(parent, 0);\n combined.set(keccak256(utf8(label)), 32);\n return keccak256(combined);\n}\n\n/**\n * Build a {@link DotNsTld} from a TLD suffix, deriving the node the same way the\n * contract does.\n *\n * Mirrors `DotnsProtocolRegistry.initialize`, which sets\n * `_tldNode = namehashUnder(bytes32(0), labelhash(tldLabel))`. Because the node\n * is a pure function of the label, a client only ever needs the suffix — reading\n * `tldNode()` is a cross-check, never the source.\n *\n * Accepts `\".paseo\"` or `\"paseo\"`: `tld()` returns the dotted form while\n * `initialize` and the deploy pipeline speak the bare label.\n */\nexport function dotNsTld(suffix: string): DotNsTld {\n const label = suffix.startsWith(\".\") ? suffix.slice(1) : suffix;\n return {\n suffix: `.${label}`,\n node: `0x${bytesToHex(nodeUnder(hexToBytes(ZERO_NODE.slice(2)), label))}`,\n };\n}\n\n/**\n * Whether a {@link DotNsTld} could have come from a real deployment.\n *\n * Three ways a pair fails, all of which produce silently wrong nodes rather\n * than errors if they reach {@link namehash}:\n *\n * - the node is not the derivation of the suffix (a caller mixing `.paseo`\n * with `DOT_NODE`);\n * - the suffix is empty, or the node is zero — what a pre-`b4096968` registry\n * proxy reports after an upgrade with no reinitializer, since `_tld` and\n * `_tldNode` are then still at their defaults and *both getters succeed*;\n * - the suffix is not a single label, which `initialize` rejects outright.\n *\n * Returns a boolean rather than a `Result` to keep this module free of the\n * error type; callers with an error channel (`resolveTld`) map `false` to an\n * `err` carrying the offending value.\n */\nexport function isConsistentDotNsTld(tld: DotNsTld): boolean {\n const label = tld.suffix.startsWith(\".\") ? tld.suffix.slice(1) : tld.suffix;\n if (label.length === 0 || label.includes(\".\")) return false;\n if (tld.node.toLowerCase() === ZERO_NODE) return false;\n return dotNsTld(label).node.toLowerCase() === tld.node.toLowerCase();\n}\n\n/** The `.dot` TLD, for a deployment that uses it. Not a default: pass it explicitly. */\nexport const DOT_TLD: DotNsTld = { suffix: \".dot\", node: DOT_NODE };\n\n/**\n * Drop `suffix` from the end of `name`, leaving the labels beneath it.\n *\n * Strips by the suffix's own length, which is the whole point: the same logic\n * written as `slice(0, -4)` turns `alice.paseo` into `alice.pa`, and every\n * lookup for that name then asks about a subname nobody registered. A name that\n * does not carry the suffix is returned unchanged, so a foreign suffix stays\n * visible to whatever validates next.\n *\n * Lives here rather than in `./dotns.js` so the one copy is reachable from this\n * module without pulling its heavier imports in.\n */\nexport function stripSuffix(name: string, suffix: string): string {\n return name.endsWith(suffix) ? name.slice(0, -suffix.length) : name;\n}\n\n/**\n * Compute the DotNS node hash for a name like `\"alice.paseo\"` or\n * `\"bob.alice.paseo\"`, rooted at `tld`.\n *\n * The trailing suffix is the TLD (folded into `tld.node`); remaining labels are\n * hashed most-significant-last, so `bob.alice.paseo` layers `bob` on top of\n * `alice` on top of the TLD. Input is used as-is — normalize with\n * `normalizeDotNsName` first if needed.\n *\n * `tld` is required rather than defaulted, because a default that is correct on\n * one deployment is the defect this module was fixed for. It is also not\n * validated here: a name whose suffix belongs to another deployment hashes to a\n * node under `tld` instead of being refused, since this function returns a hash\n * and has nowhere to report a complaint. The entry points in\n * `./dotns-registry.js` do that check, where there is an error channel.\n *\n * @returns the 32-byte node as a `0x`-prefixed hex string.\n */\nexport function namehash(name: string, tld: DotNsTld): `0x${string}` {\n const trimmed = stripSuffix(name, tld.suffix);\n // \"\" → the bare TLD node; otherwise split into labels.\n const labels = trimmed === \"\" ? [] : trimmed.split(\".\");\n // Layer from the TLD outward: labels are given left-most-first\n // (bob.alice), but must be applied right-to-left onto the parent.\n // Annotated: hexToBytes yields ArrayBufferLike, keccak256 yields ArrayBuffer.\n let node: Uint8Array = hexToBytes(tld.node.slice(2));\n for (let i = labels.length - 1; i >= 0; i--) {\n node = nodeUnder(node, labels[i]);\n }\n return `0x${bytesToHex(node)}`;\n}\n","// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * DotNS (Polkadot Name Service) utilities\n *\n * Name validation and normalization. Every helper here takes the deployment's\n * TLD suffix rather than assuming `.dot`: the TLD is fixed per network when the\n * contracts initialise, so the same string is a valid name on one deployment\n * and meaningless on another. `resolveTld` in `./dotns-registry.js` is what\n * asks the chain which suffix is in play.\n */\n\nimport { accountIdBytes } from \"@parity/product-sdk-address\";\nimport { bytesToHex, hexToBytes } from \"@parity/product-sdk-crypto\";\nimport { stripSuffix } from \"./dotns-namehash.js\";\nimport type {\n ChainDefinition,\n PalletsTypedef,\n PlainDescriptor,\n RuntimeDescriptor,\n SS58String,\n StorageDescriptor,\n TxDescriptor,\n} from \"polkadot-api\";\n\ntype AnyDescriptorEntry<T> = Record<string, Record<string, T>>;\n\ntype PeopleUsernameStorage = {\n Resources: {\n UsernameOwnerOf: StorageDescriptor<[Uint8Array], SS58String, true, never>;\n };\n};\n\ntype PeopleUsernamePallets = PalletsTypedef<\n PeopleUsernameStorage,\n AnyDescriptorEntry<TxDescriptor<any>>,\n AnyDescriptorEntry<PlainDescriptor<any>>,\n AnyDescriptorEntry<PlainDescriptor<any>>,\n AnyDescriptorEntry<PlainDescriptor<any>>,\n AnyDescriptorEntry<RuntimeDescriptor<any, any>>\n>;\n\n/**\n * Descriptor narrowed to \"any chain that exposes `Resources.UsernameOwnerOf`\".\n *\n * Used as the input to `signMessageWithDotNsIdentity` so the SDK doesn't pin\n * a specific People-chain genesis — anything with the right storage shape\n * (paseo-individuality today, future People Lite, etc.) is accepted.\n */\nexport type PeopleUsernameChain = ChainDefinition & {\n descriptors: Promise<unknown> & {\n pallets: PeopleUsernamePallets;\n };\n};\n\n/**\n * Minimal typed-api shape required to resolve a username on a People chain.\n *\n * This is a narrow structural type — anything with the right\n * `query.Resources.UsernameOwnerOf.getValue` shape works, including a real\n * `TypedApi<PeopleUsernameChain>` slice of a `ChainClient` or a hand-rolled\n * test double.\n */\nexport type PeopleUsernameQueryApi = {\n query: {\n Resources: {\n UsernameOwnerOf: {\n getValue: (key: Uint8Array) => Promise<SS58String | undefined>;\n };\n };\n };\n};\n\n/**\n * Whether `name` is a single registrable label under `suffix`.\n *\n * `suffix` is the deployment's own TLD, including its leading dot, as\n * `resolveTld` reports it — `\".dot\"` on Paseo Asset Hub Previewnet, `\".paseo\"`\n * on Next V2. It is required rather than defaulted, because a name is only\n * valid *relative to a deployment*: `alice.dot` is registrable on one network\n * and meaningless on the other, and a default would silently pick one.\n *\n * @param name - Name to validate, already normalized by {@link normalizeDotNsName}\n * @param suffix - The deployment's TLD suffix, e.g. `\".paseo\"`\n */\nexport function isValidDotNsName(name: string, suffix: string): boolean {\n if (!name.endsWith(suffix)) return false;\n return isValidLabel(stripSuffix(name, suffix));\n}\n\n/**\n * One canonical DNS label, matching the on-chain rule.\n *\n * `StringUtils.isSingleLabel` allows lowercase ASCII, digits and non-edge\n * hyphens up to 63 characters, and the registrar additionally requires 3.\n */\nfunction isValidLabel(label: string): boolean {\n if (label.length < 3 || label.length > 63) return false;\n return /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(label);\n}\n\n/**\n * Whether a name can be resolved: one or more valid labels under `suffix`.\n *\n * Broader than {@link isValidDotNsName} on purpose. The registrar only mints\n * single labels, so registration keeps the stricter rule, but the registry\n * supports subnodes and `namehash` hashes them, so `bob.alice.paseo` is\n * resolvable even though it is not registrable.\n *\n * @param name - Name to check, already normalized by {@link normalizeDotNsName}\n * @param suffix - The deployment's TLD suffix, e.g. `\".paseo\"`\n */\nexport function isResolvableDotNsName(name: string, suffix: string): boolean {\n if (!name.endsWith(suffix)) return false;\n const labels = stripSuffix(name, suffix).split(\".\");\n return labels.length > 0 && labels.every(isValidLabel);\n}\n\n/**\n * Normalize a DotNS name for the deployment identified by `suffix`.\n *\n * Case-folds, applies NFC, trims surrounding whitespace, and drops a single\n * trailing root dot, so `Alice.PASEO.` keys the same as `alice.paseo`. This\n * mirrors `normalize_host` in truapi-server, which is what turns a URL into a\n * dotNS identifier — a name arriving from navigation has to key identically\n * here or the two layers disagree about the same input.\n *\n * The NFC step is defensive only: {@link isValidLabel} and the on-chain\n * `StringUtils.isSingleLabel` both allow lowercase ASCII alone, so no name that\n * survives validation can differ between its composed and decomposed spellings.\n * It costs nothing and it keeps this function honest if the label rule ever\n * widens.\n *\n * **The suffix is appended only when `name` contains no dot at all.** A bare\n * label is the friendly path and gets the deployment's suffix; anything already\n * carrying a dot is left exactly as written, so a name from another deployment\n * survives to be refused by validation rather than being buried under our own\n * suffix. Appending on `!endsWith(suffix)` instead would turn `alice.dot` into\n * `alice.dot.paseo`, which is a well-formed subname and would resolve silently\n * to a node nobody owns.\n *\n * The cost of that rule: a bare multi-label name such as `bob.alice` is no\n * longer completed to `bob.alice.paseo`. Distinguishing it from `alice.dot`\n * would require a hardcoded list of every network's TLD, and there are already\n * more TLDs deployed than any such list contains.\n *\n * @param name - Name to normalize\n * @param suffix - The deployment's TLD suffix, e.g. `\".paseo\"`\n */\nexport function normalizeDotNsName(name: string, suffix: string): string {\n const folded = name.trim().normalize(\"NFC\").toLowerCase();\n const normalized = folded.endsWith(\".\") ? folded.slice(0, -1) : folded;\n return normalized.includes(\".\") ? normalized : normalized + suffix;\n}\n\n// `resolveDotNs` / `reverseDotNs` / `isDotNsAvailable` now live in\n// `./dotns-registry.ts` (real `Result`-returning registry calls), replacing the\n// throwing skeletons that used to sit here. See that module + the design doc.\n\n/**\n * Resolve a People / People Lite username to its owning account.\n *\n * Queries `Resources.UsernameOwnerOf` on the caller-supplied typed-api fragment.\n * The returned value is the SS58 address the storage yields, or `null` when no\n * owner is registered for that username.\n *\n * Returns SS58 rather than hex because that is both the form the storage yields\n * and the form `Resources.Consumers` is keyed by, so reading an account's\n * usernames from this result needs no conversion. Callers that want the raw\n * 32-byte key use `accountIdBytes` from `@parity/product-sdk-address`, and\n * {@link accountIdToHex} for the hex form.\n *\n * The `username` is UTF-8 encoded as-is — no normalization is applied. Pass\n * the exact byte string the chain stores (typically with the `.dot` suffix).\n *\n * @internal Exposed for unit testing. Consumers should use\n * `wallet.signMessageWithDotNsIdentity` instead, which orchestrates the\n * chain-connection lifecycle.\n */\nexport async function resolvePeopleUsernameOwner(\n username: string,\n peopleApi: PeopleUsernameQueryApi,\n): Promise<SS58String | null> {\n const owner = await peopleApi.query.Resources.UsernameOwnerOf.getValue(\n new TextEncoder().encode(username),\n );\n return owner ?? null;\n}\n\nfunction assertHex(value: string): `0x${string}` {\n if (!/^0x[0-9a-fA-F]*$/.test(value)) {\n throw new Error(`Expected 0x-prefixed hex string, got ${value}`);\n }\n return value as `0x${string}`;\n}\n\nexport function accountIdHexToBytes(accountId: `0x${string}`): Uint8Array {\n const bytes = hexToBytes(assertHex(accountId).slice(2));\n if (bytes.length !== 32) {\n throw new Error(`Expected 32-byte AccountId, got ${bytes.length} bytes`);\n }\n return bytes;\n}\n\n/** Throws on any input that is not exactly 32 bytes, rather than padding it. */\nexport function accountIdBytesToHex(bytes: Uint8Array): `0x${string}` {\n if (bytes.length !== 32) {\n throw new Error(`Expected 32-byte AccountId, got ${bytes.length} bytes`);\n }\n return `0x${bytesToHex(bytes)}`;\n}\n\n/**\n * The inverse of {@link accountIdHexToBytes}.\n *\n * No in-repo caller: this is the migration path for consumers, after\n * `resolvePeopleUsernameOwner` changed from hex to SS58. Not dead code.\n */\nexport function accountIdToHex(address: string): `0x${string}` {\n return accountIdBytesToHex(accountIdBytes(address));\n}\n"]}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { resolvePeopleUsernameOwner, accountIdBytesToHex } from './chunk-BRZNHTLQ.js';
|
|
2
|
+
import { createLogger, configure } from '@parity/product-sdk-logger';
|
|
3
|
+
import { createLocalKvStore } from '@parity/product-sdk-local-storage';
|
|
4
|
+
import { SignerManager } from '@parity/product-sdk-signer';
|
|
5
|
+
import { CloudStorageClient, createLazySigner, calculateCid, ProductCloudStorageError } from '@parity/product-sdk-cloud-storage';
|
|
6
|
+
import { err, ok } from '@parity/result';
|
|
7
|
+
import { isConnected, getClient, createChainClient, destroyAll } from '@parity/product-sdk-chain-client';
|
|
8
|
+
import { accountIdBytes } from '@parity/product-sdk-address';
|
|
9
|
+
import { getAccountsProvider } from '@parity/product-sdk-host';
|
|
10
|
+
|
|
11
|
+
var log = createLogger("app");
|
|
12
|
+
async function createApp(config) {
|
|
13
|
+
if (config.logLevel) {
|
|
14
|
+
configure({ level: config.logLevel });
|
|
15
|
+
}
|
|
16
|
+
log.info("Creating Product SDK app", { name: config.name });
|
|
17
|
+
const localKvStore = await createLocalKvStore({ prefix: config.name });
|
|
18
|
+
const signerManager = new SignerManager({
|
|
19
|
+
dappName: config.name
|
|
20
|
+
});
|
|
21
|
+
const cloudStorageEnabled = config.cloudStorage !== false;
|
|
22
|
+
const cloudStorageEnvironment = typeof config.cloudStorage === "object" ? config.cloudStorage.environment : "paseo";
|
|
23
|
+
const cloudStorageClient = cloudStorageEnabled ? await CloudStorageClient.create({
|
|
24
|
+
environment: cloudStorageEnvironment,
|
|
25
|
+
signer: createLazySigner(() => signerManager.getSigner())
|
|
26
|
+
}) : null;
|
|
27
|
+
if (cloudStorageEnabled) {
|
|
28
|
+
log.debug("Cloud Storage client (Bulletin) initialized", {
|
|
29
|
+
environment: cloudStorageEnvironment
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
log.debug("Cloud Storage client disabled");
|
|
33
|
+
}
|
|
34
|
+
const localStorageApi = {
|
|
35
|
+
get: (key) => localKvStore.get(key),
|
|
36
|
+
set: (key, value) => localKvStore.set(key, value),
|
|
37
|
+
getJSON: (key) => localKvStore.getJSON(key),
|
|
38
|
+
setJSON: (key, value) => localKvStore.setJSON(key, value),
|
|
39
|
+
remove: (key) => localKvStore.remove(key),
|
|
40
|
+
clear: async () => {
|
|
41
|
+
log.debug("clear() is not supported in container storage mode");
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const walletApi = createWalletApi(signerManager);
|
|
45
|
+
const chainApi = {
|
|
46
|
+
getClient(descriptor) {
|
|
47
|
+
log.debug("getClient called", { genesis: descriptor.genesis });
|
|
48
|
+
const client = getClient(descriptor);
|
|
49
|
+
return client.getTypedApi(descriptor);
|
|
50
|
+
},
|
|
51
|
+
getRawClient(descriptor) {
|
|
52
|
+
log.debug("getRawClient called", { genesis: descriptor.genesis });
|
|
53
|
+
return getClient(descriptor);
|
|
54
|
+
},
|
|
55
|
+
async connect(chains) {
|
|
56
|
+
log.debug("connect called", { chains: Object.keys(chains) });
|
|
57
|
+
return createChainClient({ chains });
|
|
58
|
+
},
|
|
59
|
+
isConnected(descriptor) {
|
|
60
|
+
return isConnected(descriptor);
|
|
61
|
+
},
|
|
62
|
+
destroyAll() {
|
|
63
|
+
log.debug("destroyAll called");
|
|
64
|
+
destroyAll();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const cloudStorageApi = cloudStorageClient ? {
|
|
68
|
+
upload: async (data) => {
|
|
69
|
+
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
70
|
+
try {
|
|
71
|
+
const uploaded = await cloudStorageClient.store(bytes).withManifest(true).send();
|
|
72
|
+
if (!uploaded.cid) {
|
|
73
|
+
return err(
|
|
74
|
+
new ProductCloudStorageError(
|
|
75
|
+
"Cloud storage upload returned no CID despite .withManifest(true). Upstream contract may have shifted \u2014 file an issue."
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return ok(uploaded.cid.toString());
|
|
80
|
+
} catch (cause) {
|
|
81
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
82
|
+
return err(new ProductCloudStorageError(message, { cause }));
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
fetch: (cid) => cloudStorageClient.fetchBytes(cid),
|
|
86
|
+
computeCid: async (data) => {
|
|
87
|
+
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
88
|
+
const cid = await calculateCid(bytes);
|
|
89
|
+
return cid.toString();
|
|
90
|
+
}
|
|
91
|
+
} : null;
|
|
92
|
+
log.info("Product SDK app created", {
|
|
93
|
+
name: config.name,
|
|
94
|
+
cloudStorage: cloudStorageEnabled ? cloudStorageEnvironment : "disabled"
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
wallet: walletApi,
|
|
98
|
+
localStorage: localStorageApi,
|
|
99
|
+
chain: chainApi,
|
|
100
|
+
cloudStorage: cloudStorageApi,
|
|
101
|
+
getAppInfo: () => ({ ...config })
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function createWalletApi(signerManager) {
|
|
105
|
+
const accountChangeSubscribers = /* @__PURE__ */ new Set();
|
|
106
|
+
signerManager.subscribe((state) => {
|
|
107
|
+
const account = state.selectedAccount ? {
|
|
108
|
+
address: state.selectedAccount.address,
|
|
109
|
+
name: state.selectedAccount.name ?? void 0,
|
|
110
|
+
source: state.selectedAccount.source
|
|
111
|
+
} : null;
|
|
112
|
+
for (const callback of accountChangeSubscribers) {
|
|
113
|
+
try {
|
|
114
|
+
callback(account);
|
|
115
|
+
} catch (e) {
|
|
116
|
+
log.warn("Account change callback threw", { error: e });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
return {
|
|
121
|
+
async connect() {
|
|
122
|
+
const result = await signerManager.connect();
|
|
123
|
+
if (!result.ok) {
|
|
124
|
+
throw new Error(result.error.message);
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
accounts: result.value.map((a) => ({
|
|
128
|
+
address: a.address,
|
|
129
|
+
name: a.name ?? void 0,
|
|
130
|
+
source: a.source
|
|
131
|
+
}))
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
async disconnect() {
|
|
135
|
+
signerManager.disconnect();
|
|
136
|
+
},
|
|
137
|
+
getAccounts() {
|
|
138
|
+
return signerManager.getState().accounts.map((a) => ({
|
|
139
|
+
address: a.address,
|
|
140
|
+
name: a.name ?? void 0,
|
|
141
|
+
source: a.source
|
|
142
|
+
}));
|
|
143
|
+
},
|
|
144
|
+
getSelectedAccount() {
|
|
145
|
+
const selected = signerManager.getState().selectedAccount;
|
|
146
|
+
if (!selected) return null;
|
|
147
|
+
return {
|
|
148
|
+
address: selected.address,
|
|
149
|
+
name: selected.name ?? void 0,
|
|
150
|
+
source: selected.source
|
|
151
|
+
};
|
|
152
|
+
},
|
|
153
|
+
selectAccount(address) {
|
|
154
|
+
signerManager.selectAccount(address);
|
|
155
|
+
},
|
|
156
|
+
async signMessage(message) {
|
|
157
|
+
const bytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
158
|
+
const result = await signerManager.signRaw(bytes);
|
|
159
|
+
if (!result.ok) {
|
|
160
|
+
throw new Error(result.error.message);
|
|
161
|
+
}
|
|
162
|
+
return result.value;
|
|
163
|
+
},
|
|
164
|
+
async signMessageWithDotNsIdentity(args) {
|
|
165
|
+
const message = typeof args.message === "string" ? new TextEncoder().encode(args.message) : args.message;
|
|
166
|
+
const accountsProvider = await getHostAccountsProvider();
|
|
167
|
+
const username = args.username ?? await getPrimaryUsername(accountsProvider);
|
|
168
|
+
const peopleClient = isConnected(args.peopleChain) ? getClient(args.peopleChain) : await createChainClient({ chains: { people: args.peopleChain } }).then(
|
|
169
|
+
(c) => c.raw.people
|
|
170
|
+
);
|
|
171
|
+
const peopleApi = peopleClient.getTypedApi(
|
|
172
|
+
args.peopleChain
|
|
173
|
+
);
|
|
174
|
+
const owner = await resolvePeopleUsernameOwner(username, peopleApi);
|
|
175
|
+
if (!owner) {
|
|
176
|
+
throw new Error(`No account owns DotNS username "${username}"`);
|
|
177
|
+
}
|
|
178
|
+
const publicKey = accountIdBytes(owner);
|
|
179
|
+
const accountId = accountIdBytesToHex(publicKey);
|
|
180
|
+
const signer = accountsProvider.getLegacyAccountSigner({ publicKey, name: username });
|
|
181
|
+
try {
|
|
182
|
+
return {
|
|
183
|
+
username,
|
|
184
|
+
accountId,
|
|
185
|
+
signature: await signer.signBytes(message)
|
|
186
|
+
};
|
|
187
|
+
} catch (cause) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
`Failed to sign with DotNS username "${username}": ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
190
|
+
{ cause }
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
onAccountChange(callback) {
|
|
195
|
+
accountChangeSubscribers.add(callback);
|
|
196
|
+
return () => accountChangeSubscribers.delete(callback);
|
|
197
|
+
},
|
|
198
|
+
getProductAccount() {
|
|
199
|
+
log.warn(
|
|
200
|
+
"getProductAccount() is deprecated - use SignerManager.getProductAccount() directly"
|
|
201
|
+
);
|
|
202
|
+
return null;
|
|
203
|
+
},
|
|
204
|
+
getAnonymousAlias() {
|
|
205
|
+
log.warn(
|
|
206
|
+
"getAnonymousAlias() is deprecated - use SignerManager.getProductAccountAlias() directly"
|
|
207
|
+
);
|
|
208
|
+
return null;
|
|
209
|
+
},
|
|
210
|
+
async createProof(_message) {
|
|
211
|
+
throw new Error(
|
|
212
|
+
"createProof() is not implemented in the App API. Use SignerManager.createRingVRFProof() directly."
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
async function getHostAccountsProvider() {
|
|
218
|
+
const provider = await getAccountsProvider();
|
|
219
|
+
if (!provider) {
|
|
220
|
+
throw new Error("Host accounts provider is not available");
|
|
221
|
+
}
|
|
222
|
+
return provider;
|
|
223
|
+
}
|
|
224
|
+
async function getPrimaryUsername(accountsProvider) {
|
|
225
|
+
const result = await accountsProvider.getUserId().match(
|
|
226
|
+
(value) => value,
|
|
227
|
+
(err2) => {
|
|
228
|
+
throw err2;
|
|
229
|
+
}
|
|
230
|
+
);
|
|
231
|
+
const username = result.primaryUsername.trim();
|
|
232
|
+
if (!username) {
|
|
233
|
+
throw new Error("Host identity did not provide a primary DotNS username");
|
|
234
|
+
}
|
|
235
|
+
return username;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export { createApp };
|
|
239
|
+
//# sourceMappingURL=chunk-DHRCWMY5.js.map
|
|
240
|
+
//# sourceMappingURL=chunk-DHRCWMY5.js.map
|