@parity/product-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/dist/address/index.d.ts +8 -0
- package/dist/address/index.js +3 -0
- package/dist/address/index.js.map +1 -0
- package/dist/bulletin/index.d.ts +1 -0
- package/dist/bulletin/index.js +3 -0
- package/dist/bulletin/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-NVGSGXGH.js +177 -0
- package/dist/chunk-NVGSGXGH.js.map +1 -0
- package/dist/chunk-XSKBA5SR.js +8 -0
- package/dist/chunk-XSKBA5SR.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 +9 -0
- package/dist/core/index.js +13 -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/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 +186 -0
- package/dist/identity/index.js +109 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +177 -0
- package/dist/react/index.js +213 -0
- package/dist/react/index.js.map +1 -0
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +3 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/types-CZQDzQ53.d.ts +142 -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 +105 -0
- package/src/address/index.ts +6 -0
- package/src/bulletin/index.ts +6 -0
- package/src/chain/index.ts +6 -0
- package/src/contracts/index.ts +6 -0
- package/src/core/createApp.ts +284 -0
- package/src/core/index.ts +10 -0
- package/src/core/logger.ts +13 -0
- package/src/core/types.ts +155 -0
- package/src/crypto/index.ts +6 -0
- package/src/host/index.ts +6 -0
- package/src/identity/dotns.ts +96 -0
- package/src/identity/index.ts +34 -0
- package/src/identity/product-account.ts +158 -0
- package/src/identity/types.ts +75 -0
- package/src/index.ts +49 -0
- package/src/react/context.ts +33 -0
- package/src/react/index.ts +41 -0
- package/src/react/provider.tsx +76 -0
- package/src/react/useChain.ts +33 -0
- package/src/react/useStorage.ts +125 -0
- package/src/react/useWallet.ts +138 -0
- package/src/storage/index.ts +6 -0
- package/src/wallet/index.ts +9 -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,8 @@
|
|
|
1
|
+
export * from '@parity/product-sdk-address';
|
|
2
|
+
import '@parity/product-sdk-bulletin';
|
|
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-storage';
|
|
8
|
+
import '@parity/product-sdk-signer';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/address/index.ts"],"sourcesContent":["/**\n * @parity/product-sdk/address\n *\n * Re-exports from @parity/product-sdk-address.\n */\nexport * from \"@parity/product-sdk-address\";\n"],"mappings":";AAKA,cAAc;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@parity/product-sdk-bulletin';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/bulletin/index.ts"],"sourcesContent":["/**\n * @parity/product-sdk/bulletin\n *\n * Re-exports from @parity/product-sdk-bulletin.\n */\nexport * from \"@parity/product-sdk-bulletin\";\n"],"mappings":";AAKA,cAAc;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@parity/product-sdk-chain-client';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/chain/index.ts"],"sourcesContent":["/**\n * @parity/product-sdk/chain\n *\n * Re-exports from @parity/product-sdk-chain-client.\n */\nexport * from \"@parity/product-sdk-chain-client\";\n"],"mappings":";AAKA,cAAc;","names":[]}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// src/core/createApp.ts
|
|
2
|
+
import { configure, createLogger } from "@parity/product-sdk-logger";
|
|
3
|
+
import { createKvStore } from "@parity/product-sdk-storage";
|
|
4
|
+
import { SignerManager } from "@parity/product-sdk-signer";
|
|
5
|
+
import { BulletinClient, computeCid } from "@parity/product-sdk-bulletin";
|
|
6
|
+
import {
|
|
7
|
+
createChainClient,
|
|
8
|
+
getClient,
|
|
9
|
+
isConnected,
|
|
10
|
+
destroyAll
|
|
11
|
+
} from "@parity/product-sdk-chain-client";
|
|
12
|
+
var log = createLogger("app");
|
|
13
|
+
async function createApp(config) {
|
|
14
|
+
if (config.logLevel) {
|
|
15
|
+
configure({ level: config.logLevel });
|
|
16
|
+
}
|
|
17
|
+
log.info("Creating Product SDK app", { name: config.name });
|
|
18
|
+
const kvStore = await createKvStore({ prefix: config.name });
|
|
19
|
+
const signerManager = new SignerManager({
|
|
20
|
+
dappName: config.name
|
|
21
|
+
});
|
|
22
|
+
const bulletinEnabled = config.bulletin !== false;
|
|
23
|
+
const bulletinEnvironment = typeof config.bulletin === "object" ? config.bulletin.environment : "paseo";
|
|
24
|
+
const bulletinClient = bulletinEnabled ? await BulletinClient.create(bulletinEnvironment) : null;
|
|
25
|
+
if (bulletinEnabled) {
|
|
26
|
+
log.debug("Bulletin client initialized", { environment: bulletinEnvironment });
|
|
27
|
+
} else {
|
|
28
|
+
log.debug("Bulletin client disabled");
|
|
29
|
+
}
|
|
30
|
+
const storageApi = {
|
|
31
|
+
get: (key) => kvStore.get(key),
|
|
32
|
+
set: (key, value) => kvStore.set(key, value),
|
|
33
|
+
getJSON: (key) => kvStore.getJSON(key),
|
|
34
|
+
setJSON: (key, value) => kvStore.setJSON(key, value),
|
|
35
|
+
remove: (key) => kvStore.remove(key),
|
|
36
|
+
clear: async () => {
|
|
37
|
+
log.debug("clear() is not supported in container storage mode");
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const walletApi = createWalletApi(signerManager);
|
|
41
|
+
const chainApi = {
|
|
42
|
+
getClient(descriptor) {
|
|
43
|
+
log.debug("getClient called", { genesis: descriptor.genesis });
|
|
44
|
+
const client = getClient(descriptor);
|
|
45
|
+
return client.getTypedApi(descriptor);
|
|
46
|
+
},
|
|
47
|
+
getRawClient(descriptor) {
|
|
48
|
+
log.debug("getRawClient called", { genesis: descriptor.genesis });
|
|
49
|
+
return getClient(descriptor);
|
|
50
|
+
},
|
|
51
|
+
async connect(chains) {
|
|
52
|
+
log.debug("connect called", { chains: Object.keys(chains) });
|
|
53
|
+
const rpcs = Object.fromEntries(
|
|
54
|
+
Object.keys(chains).map((k) => [k, []])
|
|
55
|
+
);
|
|
56
|
+
return createChainClient({ chains, rpcs });
|
|
57
|
+
},
|
|
58
|
+
isConnected(descriptor) {
|
|
59
|
+
return isConnected(descriptor);
|
|
60
|
+
},
|
|
61
|
+
destroyAll() {
|
|
62
|
+
log.debug("destroyAll called");
|
|
63
|
+
destroyAll();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const bulletinApi = bulletinClient ? {
|
|
67
|
+
upload: async (data) => {
|
|
68
|
+
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
69
|
+
const result = await bulletinClient.upload(bytes);
|
|
70
|
+
return result.cid;
|
|
71
|
+
},
|
|
72
|
+
fetch: (cid) => bulletinClient.fetchBytes(cid),
|
|
73
|
+
computeCid: (data) => {
|
|
74
|
+
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
75
|
+
return computeCid(bytes);
|
|
76
|
+
}
|
|
77
|
+
} : null;
|
|
78
|
+
log.info("Product SDK app created", {
|
|
79
|
+
name: config.name,
|
|
80
|
+
bulletin: bulletinEnabled ? bulletinEnvironment : "disabled"
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
wallet: walletApi,
|
|
84
|
+
storage: storageApi,
|
|
85
|
+
chain: chainApi,
|
|
86
|
+
bulletin: bulletinApi,
|
|
87
|
+
getAppInfo: () => ({ ...config })
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function createWalletApi(signerManager) {
|
|
91
|
+
const accountChangeSubscribers = /* @__PURE__ */ new Set();
|
|
92
|
+
signerManager.subscribe((state) => {
|
|
93
|
+
const account = state.selectedAccount ? {
|
|
94
|
+
address: state.selectedAccount.address,
|
|
95
|
+
name: state.selectedAccount.name ?? void 0,
|
|
96
|
+
source: state.selectedAccount.source
|
|
97
|
+
} : null;
|
|
98
|
+
for (const callback of accountChangeSubscribers) {
|
|
99
|
+
try {
|
|
100
|
+
callback(account);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
log.warn("Account change callback threw", { error: e });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
async connect() {
|
|
108
|
+
const result = await signerManager.connect();
|
|
109
|
+
if (!result.ok) {
|
|
110
|
+
throw new Error(result.error.message);
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
accounts: result.value.map((a) => ({
|
|
114
|
+
address: a.address,
|
|
115
|
+
name: a.name ?? void 0,
|
|
116
|
+
source: a.source
|
|
117
|
+
}))
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
async disconnect() {
|
|
121
|
+
signerManager.disconnect();
|
|
122
|
+
},
|
|
123
|
+
getAccounts() {
|
|
124
|
+
return signerManager.getState().accounts.map((a) => ({
|
|
125
|
+
address: a.address,
|
|
126
|
+
name: a.name ?? void 0,
|
|
127
|
+
source: a.source
|
|
128
|
+
}));
|
|
129
|
+
},
|
|
130
|
+
getSelectedAccount() {
|
|
131
|
+
const selected = signerManager.getState().selectedAccount;
|
|
132
|
+
if (!selected) return null;
|
|
133
|
+
return {
|
|
134
|
+
address: selected.address,
|
|
135
|
+
name: selected.name ?? void 0,
|
|
136
|
+
source: selected.source
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
selectAccount(address) {
|
|
140
|
+
signerManager.selectAccount(address);
|
|
141
|
+
},
|
|
142
|
+
async signMessage(message) {
|
|
143
|
+
const bytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
144
|
+
const result = await signerManager.signRaw(bytes);
|
|
145
|
+
if (!result.ok) {
|
|
146
|
+
throw new Error(result.error.message);
|
|
147
|
+
}
|
|
148
|
+
return result.value;
|
|
149
|
+
},
|
|
150
|
+
onAccountChange(callback) {
|
|
151
|
+
accountChangeSubscribers.add(callback);
|
|
152
|
+
return () => accountChangeSubscribers.delete(callback);
|
|
153
|
+
},
|
|
154
|
+
getProductAccount() {
|
|
155
|
+
log.warn(
|
|
156
|
+
"getProductAccount() is deprecated - use SignerManager.getProductAccount() directly"
|
|
157
|
+
);
|
|
158
|
+
return null;
|
|
159
|
+
},
|
|
160
|
+
getAnonymousAlias() {
|
|
161
|
+
log.warn(
|
|
162
|
+
"getAnonymousAlias() is deprecated - use SignerManager.getProductAccountAlias() directly"
|
|
163
|
+
);
|
|
164
|
+
return null;
|
|
165
|
+
},
|
|
166
|
+
async createProof(_message) {
|
|
167
|
+
throw new Error(
|
|
168
|
+
"createProof() is not implemented in the App API. Use SignerManager.createRingVRFProof() directly."
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export {
|
|
175
|
+
createApp
|
|
176
|
+
};
|
|
177
|
+
//# sourceMappingURL=chunk-NVGSGXGH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/createApp.ts"],"sourcesContent":["/**\n * createApp - Main entry point for the Product SDK\n *\n * Creates an App instance with wallet, storage, chain, and bulletin APIs.\n */\n\nimport type { ChainDefinition } from \"polkadot-api\";\nimport type {\n App,\n AppConfig,\n WalletApi,\n StorageApi,\n ChainApi,\n BulletinApi,\n Account,\n} from \"./types.js\";\nimport { configure, createLogger } from \"@parity/product-sdk-logger\";\nimport { createKvStore } from \"@parity/product-sdk-storage\";\nimport { SignerManager } from \"@parity/product-sdk-signer\";\nimport { BulletinClient, computeCid } from \"@parity/product-sdk-bulletin\";\nimport {\n createChainClient,\n getClient,\n isConnected,\n destroyAll,\n} from \"@parity/product-sdk-chain-client\";\n\nconst log = createLogger(\"app\");\n\n/**\n * Create a new Product SDK app instance\n *\n * @param config - Application configuration\n * @returns App instance with all APIs\n *\n * @example\n * ```ts\n * import { createApp } from '@parity/product-sdk';\n *\n * // Default: bulletin enabled with paseo environment\n * const app = await createApp({\n * name: 'my-app',\n * logLevel: 'info',\n * });\n *\n * // Custom bulletin environment\n * const prodApp = await createApp({\n * name: 'my-app',\n * bulletin: { environment: 'polkadot' },\n * });\n *\n * // Disable bulletin entirely\n * const noBulletinApp = await createApp({\n * name: 'my-app',\n * bulletin: false,\n * });\n *\n * // Connect wallet\n * const { accounts } = await app.wallet.connect();\n *\n * // Use storage\n * await app.storage.set('key', 'value');\n *\n * // Use bulletin (check for null if it might be disabled)\n * if (app.bulletin) {\n * const cid = await app.bulletin.upload('hello world');\n * }\n * ```\n */\nexport async function createApp(config: AppConfig): Promise<App> {\n // Set log level if specified\n if (config.logLevel) {\n configure({ level: config.logLevel });\n }\n\n log.info(\"Creating Product SDK app\", { name: config.name });\n\n // Initialize storage (container-only - will throw if not in container)\n const kvStore = await createKvStore({ prefix: config.name });\n\n // Initialize signer manager\n const signerManager = new SignerManager({\n dappName: config.name,\n });\n\n // Initialize bulletin client (configurable, defaults to paseo)\n const bulletinEnabled = config.bulletin !== false;\n const bulletinEnvironment =\n typeof config.bulletin === \"object\" ? config.bulletin.environment : \"paseo\";\n const bulletinClient = bulletinEnabled\n ? await BulletinClient.create(bulletinEnvironment)\n : null;\n\n if (bulletinEnabled) {\n log.debug(\"Bulletin client initialized\", { environment: bulletinEnvironment });\n } else {\n log.debug(\"Bulletin client disabled\");\n }\n\n // Create storage API adapter\n const storageApi: StorageApi = {\n get: (key) => kvStore.get(key),\n set: (key, value) => kvStore.set(key, value),\n getJSON: <T>(key: string) => kvStore.getJSON<T>(key),\n setJSON: <T>(key: string, value: T) => kvStore.setJSON(key, value),\n remove: (key) => kvStore.remove(key),\n clear: async () => {\n // KvStore doesn't have clear - this is a no-op\n log.debug(\"clear() is not supported in container storage mode\");\n },\n };\n\n // Create wallet API adapter\n const walletApi = createWalletApi(signerManager);\n\n // Create chain API\n const chainApi: ChainApi = {\n getClient(descriptor) {\n log.debug(\"getClient called\", { genesis: descriptor.genesis });\n const client = getClient(descriptor);\n return client.getTypedApi(descriptor);\n },\n\n getRawClient(descriptor) {\n log.debug(\"getRawClient called\", { genesis: descriptor.genesis });\n return getClient(descriptor);\n },\n\n async connect<T extends Record<string, ChainDefinition>>(chains: T) {\n log.debug(\"connect called\", { chains: Object.keys(chains) });\n // Build empty rpcs object (required by API but unused - host routes connections)\n const rpcs = Object.fromEntries(\n Object.keys(chains).map((k) => [k, [] as readonly string[]]),\n ) as { [K in keyof T]: readonly string[] };\n return createChainClient({ chains, rpcs });\n },\n\n isConnected(descriptor) {\n return isConnected(descriptor);\n },\n\n destroyAll() {\n log.debug(\"destroyAll called\");\n destroyAll();\n },\n };\n\n // Create bulletin API adapter (null if disabled)\n const bulletinApi: BulletinApi | null = bulletinClient\n ? {\n upload: async (data) => {\n const bytes = typeof data === \"string\" ? new TextEncoder().encode(data) : data;\n const result = await bulletinClient.upload(bytes);\n return result.cid;\n },\n fetch: (cid) => bulletinClient.fetchBytes(cid),\n computeCid: (data) => {\n const bytes = typeof data === \"string\" ? new TextEncoder().encode(data) : data;\n return computeCid(bytes);\n },\n }\n : null;\n\n log.info(\"Product SDK app created\", {\n name: config.name,\n bulletin: bulletinEnabled ? bulletinEnvironment : \"disabled\",\n });\n\n return {\n wallet: walletApi,\n storage: storageApi,\n chain: chainApi,\n bulletin: bulletinApi,\n getAppInfo: () => ({ ...config }),\n };\n}\n\n/**\n * Create wallet API adapter using SignerManager from leaf package\n */\nfunction createWalletApi(signerManager: SignerManager): WalletApi {\n // Track account change subscribers\n const accountChangeSubscribers = new Set<(account: Account | null) => void>();\n\n // Subscribe to signer manager state changes\n signerManager.subscribe((state) => {\n const account = state.selectedAccount\n ? {\n address: state.selectedAccount.address,\n name: state.selectedAccount.name ?? undefined,\n source: state.selectedAccount.source,\n }\n : null;\n for (const callback of accountChangeSubscribers) {\n try {\n callback(account);\n } catch (e) {\n log.warn(\"Account change callback threw\", { error: e });\n }\n }\n });\n\n return {\n async connect(): Promise<{ accounts: Account[] }> {\n const result = await signerManager.connect();\n if (!result.ok) {\n throw new Error(result.error.message);\n }\n return {\n accounts: result.value.map((a) => ({\n address: a.address,\n name: a.name ?? undefined,\n source: a.source,\n })),\n };\n },\n\n async disconnect(): Promise<void> {\n signerManager.disconnect();\n },\n\n getAccounts(): Account[] {\n return signerManager.getState().accounts.map((a) => ({\n address: a.address,\n name: a.name ?? undefined,\n source: a.source,\n }));\n },\n\n getSelectedAccount(): Account | null {\n const selected = signerManager.getState().selectedAccount;\n if (!selected) return null;\n return {\n address: selected.address,\n name: selected.name ?? undefined,\n source: selected.source,\n };\n },\n\n selectAccount(address: string): void {\n signerManager.selectAccount(address);\n },\n\n async signMessage(message: string | Uint8Array): Promise<Uint8Array> {\n const bytes = typeof message === \"string\" ? new TextEncoder().encode(message) : message;\n const result = await signerManager.signRaw(bytes);\n if (!result.ok) {\n throw new Error(result.error.message);\n }\n return result.value;\n },\n\n onAccountChange(callback: (account: Account | null) => void): () => void {\n accountChangeSubscribers.add(callback);\n return () => accountChangeSubscribers.delete(callback);\n },\n\n getProductAccount(): Account | null {\n // Product accounts require async call - this sync API can't support it properly\n // Users should use SignerManager.getProductAccount() directly\n log.warn(\n \"getProductAccount() is deprecated - use SignerManager.getProductAccount() directly\",\n );\n return null;\n },\n\n getAnonymousAlias(): string | null {\n // Anonymous aliases require async call - this sync API can't support it properly\n // Users should use SignerManager.getProductAccountAlias() directly\n log.warn(\n \"getAnonymousAlias() is deprecated - use SignerManager.getProductAccountAlias() directly\",\n );\n return null;\n },\n\n async createProof(_message: Uint8Array): Promise<Uint8Array> {\n // Ring VRF proofs require SignerManager.createRingVRFProof() directly\n throw new Error(\n \"createProof() is not implemented in the App API. \" +\n \"Use SignerManager.createRingVRFProof() directly.\",\n );\n },\n };\n}\n"],"mappings":";AAgBA,SAAS,WAAW,oBAAoB;AACxC,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB,kBAAkB;AAC3C;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,IAAM,MAAM,aAAa,KAAK;AA0C9B,eAAsB,UAAU,QAAiC;AAE7D,MAAI,OAAO,UAAU;AACjB,cAAU,EAAE,OAAO,OAAO,SAAS,CAAC;AAAA,EACxC;AAEA,MAAI,KAAK,4BAA4B,EAAE,MAAM,OAAO,KAAK,CAAC;AAG1D,QAAM,UAAU,MAAM,cAAc,EAAE,QAAQ,OAAO,KAAK,CAAC;AAG3D,QAAM,gBAAgB,IAAI,cAAc;AAAA,IACpC,UAAU,OAAO;AAAA,EACrB,CAAC;AAGD,QAAM,kBAAkB,OAAO,aAAa;AAC5C,QAAM,sBACF,OAAO,OAAO,aAAa,WAAW,OAAO,SAAS,cAAc;AACxE,QAAM,iBAAiB,kBACjB,MAAM,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,MACJ;AACA,aAAO;AAAA,IACX;AAAA,IAEA,MAAM,YAAY,UAA2C;AAEzD,YAAM,IAAI;AAAA,QACN;AAAA,MAEJ;AAAA,IACJ;AAAA,EACJ;AACJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/logger.ts"],"sourcesContent":["/**\n * Logger module for @parity/product-sdk\n *\n * Re-exports from @parity/product-sdk-logger.\n */\nexport { configure, createLogger } from \"@parity/product-sdk-logger\";\nexport type {\n LogLevel,\n LogEntry,\n LogHandler,\n LoggerConfig,\n Logger,\n} from \"@parity/product-sdk-logger\";\n"],"mappings":";AAKA,SAAS,WAAW,oBAAoB;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@parity/product-sdk-contracts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/contracts/index.ts"],"sourcesContent":["/**\n * @parity/product-sdk/contracts\n *\n * Re-exports from @parity/product-sdk-contracts.\n */\nexport * from \"@parity/product-sdk-contracts\";\n"],"mappings":";AAKA,cAAc;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { createApp } from '../index.js';
|
|
2
|
+
export { LogEntry, LogHandler, LogLevel, Logger, LoggerConfig, configure, createLogger } from '@parity/product-sdk-logger';
|
|
3
|
+
export { a as Account, A as App, b as AppConfig, B as BulletinApi, c as BulletinConfig, C as ChainApi, S as StorageApi, W as WalletApi } from '../types-CZQDzQ53.js';
|
|
4
|
+
export { ChainClient } from '@parity/product-sdk-chain-client';
|
|
5
|
+
export { ChainDefinition, PolkadotClient, TypedApi } from 'polkadot-api';
|
|
6
|
+
import '@parity/product-sdk-host';
|
|
7
|
+
import '@parity/product-sdk-signer';
|
|
8
|
+
import '@parity/product-sdk-storage';
|
|
9
|
+
import '@parity/product-sdk-bulletin';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@parity/product-sdk-crypto';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/crypto/index.ts"],"sourcesContent":["/**\n * @parity/product-sdk/crypto\n *\n * Re-exports from @parity/product-sdk-crypto.\n */\nexport * from \"@parity/product-sdk-crypto\";\n"],"mappings":";AAKA,cAAc;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@parity/product-sdk-host';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/host/index.ts"],"sourcesContent":["/**\n * @parity/product-sdk/host\n *\n * Re-exports from @parity/product-sdk-host.\n */\nexport * from \"@parity/product-sdk-host\";\n"],"mappings":";AAKA,cAAc;","names":[]}
|