@hashgraphonline/standards-sdk 0.1.137 → 0.1.138-feat-hcs-21-package-std.canary.4376298.35
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/dist/cjs/hcs-21/base-client.d.ts +33 -0
- package/dist/cjs/hcs-21/base-client.d.ts.map +1 -0
- package/dist/cjs/hcs-21/browser.d.ts +20 -0
- package/dist/cjs/hcs-21/browser.d.ts.map +1 -0
- package/dist/cjs/hcs-21/errors.d.ts +6 -0
- package/dist/cjs/hcs-21/errors.d.ts.map +1 -0
- package/dist/cjs/hcs-21/index.d.ts +7 -0
- package/dist/cjs/hcs-21/index.d.ts.map +1 -0
- package/dist/cjs/hcs-21/sdk.d.ts +48 -0
- package/dist/cjs/hcs-21/sdk.d.ts.map +1 -0
- package/dist/cjs/hcs-21/tx.d.ts +20 -0
- package/dist/cjs/hcs-21/tx.d.ts.map +1 -0
- package/dist/cjs/hcs-21/types.d.ts +89 -0
- package/dist/cjs/hcs-21/types.d.ts.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client.d.ts.map +1 -1
- package/dist/cjs/services/types.d.ts +1 -1
- package/dist/cjs/services/types.d.ts.map +1 -1
- package/dist/cjs/standards-sdk.cjs +2 -2
- package/dist/cjs/standards-sdk.cjs.map +1 -1
- package/dist/es/hcs-21/base-client.d.ts +33 -0
- package/dist/es/hcs-21/base-client.d.ts.map +1 -0
- package/dist/es/hcs-21/browser.d.ts +20 -0
- package/dist/es/hcs-21/browser.d.ts.map +1 -0
- package/dist/es/hcs-21/errors.d.ts +6 -0
- package/dist/es/hcs-21/errors.d.ts.map +1 -0
- package/dist/es/hcs-21/index.d.ts +7 -0
- package/dist/es/hcs-21/index.d.ts.map +1 -0
- package/dist/es/hcs-21/sdk.d.ts +48 -0
- package/dist/es/hcs-21/sdk.d.ts.map +1 -0
- package/dist/es/hcs-21/tx.d.ts +20 -0
- package/dist/es/hcs-21/tx.d.ts.map +1 -0
- package/dist/es/hcs-21/types.d.ts +89 -0
- package/dist/es/hcs-21/types.d.ts.map +1 -0
- package/dist/es/index.d.ts +1 -0
- package/dist/es/index.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client.d.ts.map +1 -1
- package/dist/es/services/types.d.ts +1 -1
- package/dist/es/services/types.d.ts.map +1 -1
- package/dist/es/standards-sdk.es.js +67 -48
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/es/standards-sdk.es10.js +2 -2
- package/dist/es/standards-sdk.es100.js +231 -28
- package/dist/es/standards-sdk.es100.js.map +1 -1
- package/dist/es/standards-sdk.es101.js +109 -18
- package/dist/es/standards-sdk.es101.js.map +1 -1
- package/dist/es/standards-sdk.es102.js +32 -158
- package/dist/es/standards-sdk.es102.js.map +1 -1
- package/dist/es/standards-sdk.es103.js +80 -204
- package/dist/es/standards-sdk.es103.js.map +1 -1
- package/dist/es/standards-sdk.es104.js +21 -780
- package/dist/es/standards-sdk.es104.js.map +1 -1
- package/dist/es/standards-sdk.es105.js +140 -11
- package/dist/es/standards-sdk.es105.js.map +1 -1
- package/dist/es/standards-sdk.es106.js +29 -567
- package/dist/es/standards-sdk.es106.js.map +1 -1
- package/dist/es/standards-sdk.es107.js +17 -597
- package/dist/es/standards-sdk.es107.js.map +1 -1
- package/dist/es/standards-sdk.es108.js +159 -12
- package/dist/es/standards-sdk.es108.js.map +1 -1
- package/dist/es/standards-sdk.es109.js +208 -2
- package/dist/es/standards-sdk.es109.js.map +1 -1
- package/dist/es/standards-sdk.es110.js +774 -67
- package/dist/es/standards-sdk.es110.js.map +1 -1
- package/dist/es/standards-sdk.es111.js +11 -37
- package/dist/es/standards-sdk.es111.js.map +1 -1
- package/dist/es/standards-sdk.es112.js +567 -2
- package/dist/es/standards-sdk.es112.js.map +1 -1
- package/dist/es/standards-sdk.es113.js +576 -197
- package/dist/es/standards-sdk.es113.js.map +1 -1
- package/dist/es/standards-sdk.es114.js +12 -1139
- package/dist/es/standards-sdk.es114.js.map +1 -1
- package/dist/es/standards-sdk.es115.js +2 -306
- package/dist/es/standards-sdk.es115.js.map +1 -1
- package/dist/es/standards-sdk.es116.js +79 -418
- package/dist/es/standards-sdk.es116.js.map +1 -1
- package/dist/es/standards-sdk.es117.js +35 -351
- package/dist/es/standards-sdk.es117.js.map +1 -1
- package/dist/es/standards-sdk.es118.js +2 -761
- package/dist/es/standards-sdk.es118.js.map +1 -1
- package/dist/es/standards-sdk.es119.js +204 -185
- package/dist/es/standards-sdk.es119.js.map +1 -1
- package/dist/es/standards-sdk.es12.js +1 -1
- package/dist/es/standards-sdk.es120.js +1055 -1482
- package/dist/es/standards-sdk.es120.js.map +1 -1
- package/dist/es/standards-sdk.es121.js +265 -2024
- package/dist/es/standards-sdk.es121.js.map +1 -1
- package/dist/es/standards-sdk.es122.js +420 -50
- package/dist/es/standards-sdk.es122.js.map +1 -1
- package/dist/es/standards-sdk.es123.js +350 -82
- package/dist/es/standards-sdk.es123.js.map +1 -1
- package/dist/es/standards-sdk.es124.js +741 -139
- package/dist/es/standards-sdk.es124.js.map +1 -1
- package/dist/es/standards-sdk.es125.js +204 -7
- package/dist/es/standards-sdk.es125.js.map +1 -1
- package/dist/es/standards-sdk.es126.js +1533 -52
- package/dist/es/standards-sdk.es126.js.map +1 -1
- package/dist/es/standards-sdk.es127.js +2077 -59
- package/dist/es/standards-sdk.es127.js.map +1 -1
- package/dist/es/standards-sdk.es128.js +52 -28
- package/dist/es/standards-sdk.es128.js.map +1 -1
- package/dist/es/standards-sdk.es129.js +80 -131
- package/dist/es/standards-sdk.es129.js.map +1 -1
- package/dist/es/standards-sdk.es13.js +1 -1
- package/dist/es/standards-sdk.es130.js +152 -35
- package/dist/es/standards-sdk.es130.js.map +1 -1
- package/dist/es/standards-sdk.es131.js +7 -17
- package/dist/es/standards-sdk.es131.js.map +1 -1
- package/dist/es/standards-sdk.es132.js +53 -12241
- package/dist/es/standards-sdk.es132.js.map +1 -1
- package/dist/es/standards-sdk.es133.js +65 -694
- package/dist/es/standards-sdk.es133.js.map +1 -1
- package/dist/es/standards-sdk.es134.js +28 -172
- package/dist/es/standards-sdk.es134.js.map +1 -1
- package/dist/es/standards-sdk.es135.js +115 -299
- package/dist/es/standards-sdk.es135.js.map +1 -1
- package/dist/es/standards-sdk.es136.js +36 -340
- package/dist/es/standards-sdk.es136.js.map +1 -1
- package/dist/es/standards-sdk.es137.js +694 -453
- package/dist/es/standards-sdk.es137.js.map +1 -1
- package/dist/es/standards-sdk.es138.js +12210 -267
- package/dist/es/standards-sdk.es138.js.map +1 -1
- package/dist/es/standards-sdk.es139.js +15 -74
- package/dist/es/standards-sdk.es139.js.map +1 -1
- package/dist/es/standards-sdk.es14.js +1 -1
- package/dist/es/standards-sdk.es141.js +1 -1
- package/dist/es/standards-sdk.es142.js +175 -0
- package/dist/es/standards-sdk.es142.js.map +1 -0
- package/dist/es/standards-sdk.es143.js +325 -0
- package/dist/es/standards-sdk.es143.js.map +1 -0
- package/dist/es/standards-sdk.es144.js +349 -0
- package/dist/es/standards-sdk.es144.js.map +1 -0
- package/dist/es/standards-sdk.es145.js +456 -0
- package/dist/es/standards-sdk.es145.js.map +1 -0
- package/dist/es/standards-sdk.es146.js +334 -0
- package/dist/es/standards-sdk.es146.js.map +1 -0
- package/dist/es/standards-sdk.es147.js +79 -0
- package/dist/es/standards-sdk.es147.js.map +1 -0
- package/dist/es/standards-sdk.es15.js +1 -1
- package/dist/es/standards-sdk.es16.js +1 -1
- package/dist/es/standards-sdk.es17.js +5 -5
- package/dist/es/standards-sdk.es19.js +12 -12
- package/dist/es/standards-sdk.es20.js +9 -9
- package/dist/es/standards-sdk.es21.js +1 -1
- package/dist/es/standards-sdk.es22.js +1 -1
- package/dist/es/standards-sdk.es23.js +1 -1
- package/dist/es/standards-sdk.es24.js +1 -1
- package/dist/es/standards-sdk.es25.js +1 -1
- package/dist/es/standards-sdk.es26.js +1 -1
- package/dist/es/standards-sdk.es27.js +1 -1
- package/dist/es/standards-sdk.es28.js +12 -12
- package/dist/es/standards-sdk.es3.js +2 -2
- package/dist/es/standards-sdk.es31.js +2 -2
- package/dist/es/standards-sdk.es32.js +4 -4
- package/dist/es/standards-sdk.es33.js +1 -1
- package/dist/es/standards-sdk.es36.js +6 -6
- package/dist/es/standards-sdk.es37.js +4 -4
- package/dist/es/standards-sdk.es38.js +2 -2
- package/dist/es/standards-sdk.es39.js +2 -2
- package/dist/es/standards-sdk.es40.js +1 -1
- package/dist/es/standards-sdk.es41.js +1 -1
- package/dist/es/standards-sdk.es42.js +2 -2
- package/dist/es/standards-sdk.es47.js +1 -1
- package/dist/es/standards-sdk.es5.js +2 -2
- package/dist/es/standards-sdk.es52.js +1 -1
- package/dist/es/standards-sdk.es54.js +1 -1
- package/dist/es/standards-sdk.es57.js +1 -1
- package/dist/es/standards-sdk.es6.js +2 -2
- package/dist/es/standards-sdk.es61.js +7 -7
- package/dist/es/standards-sdk.es65.js +2 -2
- package/dist/es/standards-sdk.es66.js +3 -3
- package/dist/es/standards-sdk.es69.js +2 -2
- package/dist/es/standards-sdk.es7.js +2 -2
- package/dist/es/standards-sdk.es70.js +3 -3
- package/dist/es/standards-sdk.es71.js +2 -2
- package/dist/es/standards-sdk.es72.js +1 -1
- package/dist/es/standards-sdk.es75.js +2 -2
- package/dist/es/standards-sdk.es77.js +2 -2
- package/dist/es/standards-sdk.es78.js +4 -4
- package/dist/es/standards-sdk.es79.js +1 -1
- package/dist/es/standards-sdk.es8.js +1 -1
- package/dist/es/standards-sdk.es80.js +41 -27
- package/dist/es/standards-sdk.es80.js.map +1 -1
- package/dist/es/standards-sdk.es81.js +6 -78
- package/dist/es/standards-sdk.es81.js.map +1 -1
- package/dist/es/standards-sdk.es82.js +27 -64
- package/dist/es/standards-sdk.es82.js.map +1 -1
- package/dist/es/standards-sdk.es83.js +69 -23
- package/dist/es/standards-sdk.es83.js.map +1 -1
- package/dist/es/standards-sdk.es84.js +165 -23
- package/dist/es/standards-sdk.es84.js.map +1 -1
- package/dist/es/standards-sdk.es85.js +31 -166
- package/dist/es/standards-sdk.es85.js.map +1 -1
- package/dist/es/standards-sdk.es86.js +24 -127
- package/dist/es/standards-sdk.es86.js.map +1 -1
- package/dist/es/standards-sdk.es87.js +65 -142
- package/dist/es/standards-sdk.es87.js.map +1 -1
- package/dist/es/standards-sdk.es88.js +52 -127
- package/dist/es/standards-sdk.es88.js.map +1 -1
- package/dist/es/standards-sdk.es89.js +26 -41
- package/dist/es/standards-sdk.es89.js.map +1 -1
- package/dist/es/standards-sdk.es90.js +23 -261
- package/dist/es/standards-sdk.es90.js.map +1 -1
- package/dist/es/standards-sdk.es91.js +162 -93
- package/dist/es/standards-sdk.es91.js.map +1 -1
- package/dist/es/standards-sdk.es92.js +112 -83
- package/dist/es/standards-sdk.es92.js.map +1 -1
- package/dist/es/standards-sdk.es93.js +156 -28
- package/dist/es/standards-sdk.es93.js.map +1 -1
- package/dist/es/standards-sdk.es94.js +133 -225
- package/dist/es/standards-sdk.es94.js.map +1 -1
- package/dist/es/standards-sdk.es95.js +40 -108
- package/dist/es/standards-sdk.es95.js.map +1 -1
- package/dist/es/standards-sdk.es96.js +253 -24
- package/dist/es/standards-sdk.es96.js.map +1 -1
- package/dist/es/standards-sdk.es97.js +96 -80
- package/dist/es/standards-sdk.es97.js.map +1 -1
- package/dist/es/standards-sdk.es98.js +91 -21
- package/dist/es/standards-sdk.es98.js.map +1 -1
- package/dist/es/standards-sdk.es99.js +28 -141
- package/dist/es/standards-sdk.es99.js.map +1 -1
- package/package.json +62 -59
|
@@ -1,172 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
tx.setSubmitKey(params.submitKey);
|
|
30
|
-
}
|
|
31
|
-
if (params.feeScheduleKey) {
|
|
32
|
-
tx.setFeeScheduleKey(params.feeScheduleKey);
|
|
33
|
-
}
|
|
34
|
-
if (params.customFees && params.customFees.length > 0) {
|
|
35
|
-
const fees = params.customFees.map((fee) => {
|
|
36
|
-
const cf = new CustomFixedFee().setAmount(fee.amount).setFeeCollectorAccountId(
|
|
37
|
-
AccountId.fromString(fee.feeCollectorAccountId)
|
|
38
|
-
);
|
|
39
|
-
if (fee.denominatingTokenId) {
|
|
40
|
-
cf.setDenominatingTokenId(TokenId.fromString(fee.denominatingTokenId));
|
|
1
|
+
import { HCS21BaseClient } from "./standards-sdk.es83.js";
|
|
2
|
+
class HCS21BrowserClient extends HCS21BaseClient {
|
|
3
|
+
constructor(config) {
|
|
4
|
+
super({ network: config.network, logger: config.logger });
|
|
5
|
+
this.hwc = config.hwc;
|
|
6
|
+
}
|
|
7
|
+
async publishDeclaration(params) {
|
|
8
|
+
const declaration = "p" in params.declaration ? this.validateDeclaration(params.declaration) : this.buildDeclaration(params.declaration);
|
|
9
|
+
await this.hwc.submitMessageToTopic(
|
|
10
|
+
params.topicId,
|
|
11
|
+
JSON.stringify(declaration)
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
async fetchDeclarations(topicId) {
|
|
15
|
+
const { messages = [] } = await this.hwc.getMessages(topicId);
|
|
16
|
+
const envelopes = [];
|
|
17
|
+
for (const message of messages) {
|
|
18
|
+
try {
|
|
19
|
+
const declaration = this.validateDeclaration(message.message);
|
|
20
|
+
envelopes.push({
|
|
21
|
+
declaration,
|
|
22
|
+
consensusTimestamp: message.consensus_timestamp,
|
|
23
|
+
sequenceNumber: Number(message.sequence_number || 0),
|
|
24
|
+
payer: message.payer_account_id
|
|
25
|
+
});
|
|
26
|
+
} catch (error) {
|
|
27
|
+
const detail = error instanceof Error ? error.message : "unknown error";
|
|
28
|
+
this.logger.warn(`Skipping invalid HCS-21 browser message: ${detail}`);
|
|
41
29
|
}
|
|
42
|
-
return cf;
|
|
43
|
-
});
|
|
44
|
-
tx.setCustomFees(fees);
|
|
45
|
-
}
|
|
46
|
-
if (params.feeExemptKeys && params.feeExemptKeys.length > 0) {
|
|
47
|
-
throw new Error("feeExemptKeys not supported by installed @hashgraph/sdk");
|
|
48
|
-
}
|
|
49
|
-
return tx;
|
|
50
|
-
}
|
|
51
|
-
function buildHcs16CreateAccountTx(params) {
|
|
52
|
-
const tx = new AccountCreateTransaction().setKey(params.keyList);
|
|
53
|
-
const initial = typeof params.initialBalanceHbar === "number" ? params.initialBalanceHbar : 1;
|
|
54
|
-
tx.setInitialBalance(new Hbar(initial));
|
|
55
|
-
const maxAssoc = typeof params.maxAutomaticTokenAssociations === "number" ? params.maxAutomaticTokenAssociations : -1;
|
|
56
|
-
tx.setMaxAutomaticTokenAssociations(maxAssoc);
|
|
57
|
-
return tx;
|
|
58
|
-
}
|
|
59
|
-
function buildHcs16ScheduleAccountKeyUpdateTx(params) {
|
|
60
|
-
const inner = new AccountUpdateTransaction().setAccountId(AccountId.fromString(params.floraAccountId)).setKey(params.newKeyList);
|
|
61
|
-
if (params.memo) {
|
|
62
|
-
inner.setTransactionMemo(params.memo);
|
|
63
|
-
}
|
|
64
|
-
return new ScheduleCreateTransaction().setScheduledTransaction(inner);
|
|
65
|
-
}
|
|
66
|
-
function buildHcs16ScheduleTopicKeyUpdateTx(params) {
|
|
67
|
-
const inner = new TopicUpdateTransaction().setTopicId(params.topicId);
|
|
68
|
-
if (params.adminKey) {
|
|
69
|
-
inner.setAdminKey(params.adminKey);
|
|
70
|
-
}
|
|
71
|
-
if (params.submitKey) {
|
|
72
|
-
inner.setSubmitKey(params.submitKey);
|
|
73
|
-
}
|
|
74
|
-
if (params.memo) {
|
|
75
|
-
inner.setTransactionMemo(params.memo);
|
|
76
|
-
}
|
|
77
|
-
return new ScheduleCreateTransaction().setScheduledTransaction(inner);
|
|
78
|
-
}
|
|
79
|
-
function buildHcs16MessageTx(params) {
|
|
80
|
-
const payload = {
|
|
81
|
-
p: "hcs-16",
|
|
82
|
-
op: params.op,
|
|
83
|
-
operator_id: params.operatorId,
|
|
84
|
-
...params.body || {}
|
|
85
|
-
};
|
|
86
|
-
return buildMessageTx({
|
|
87
|
-
topicId: params.topicId,
|
|
88
|
-
message: JSON.stringify(payload)
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
function buildHcs16FloraCreatedTx(params) {
|
|
92
|
-
return buildHcs16MessageTx({
|
|
93
|
-
topicId: params.topicId,
|
|
94
|
-
operatorId: params.operatorId,
|
|
95
|
-
op: FloraOperation.FLORA_CREATED,
|
|
96
|
-
body: {
|
|
97
|
-
flora_account_id: params.floraAccountId,
|
|
98
|
-
topics: params.topics
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
function buildHcs16TransactionTx(params) {
|
|
103
|
-
return buildHcs16MessageTx({
|
|
104
|
-
topicId: params.topicId,
|
|
105
|
-
operatorId: params.operatorId,
|
|
106
|
-
op: FloraOperation.TRANSACTION,
|
|
107
|
-
body: {
|
|
108
|
-
schedule_id: params.scheduleId,
|
|
109
|
-
data: params.data,
|
|
110
|
-
m: params.data
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
function buildHcs16StateUpdateTx(params) {
|
|
115
|
-
return buildHcs16MessageTx({
|
|
116
|
-
topicId: params.topicId,
|
|
117
|
-
operatorId: params.operatorId,
|
|
118
|
-
op: FloraOperation.STATE_UPDATE,
|
|
119
|
-
body: {
|
|
120
|
-
hash: params.hash,
|
|
121
|
-
epoch: params.epoch,
|
|
122
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
123
30
|
}
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
function buildHcs16FloraJoinRequestTx(params) {
|
|
127
|
-
return buildHcs16MessageTx({
|
|
128
|
-
topicId: params.topicId,
|
|
129
|
-
operatorId: params.operatorId,
|
|
130
|
-
op: FloraOperation.FLORA_JOIN_REQUEST,
|
|
131
|
-
body: {
|
|
132
|
-
candidate_account_id: params.candidateAccountId
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
function buildHcs16FloraJoinVoteTx(params) {
|
|
137
|
-
return buildHcs16MessageTx({
|
|
138
|
-
topicId: params.topicId,
|
|
139
|
-
operatorId: params.operatorId,
|
|
140
|
-
op: FloraOperation.FLORA_JOIN_VOTE,
|
|
141
|
-
body: {
|
|
142
|
-
candidate_account_id: params.candidateAccountId,
|
|
143
|
-
approve: params.approve
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
function buildHcs16FloraJoinAcceptedTx(params) {
|
|
148
|
-
return buildHcs16MessageTx({
|
|
149
|
-
topicId: params.topicId,
|
|
150
|
-
operatorId: params.operatorId,
|
|
151
|
-
op: FloraOperation.FLORA_JOIN_ACCEPTED,
|
|
152
|
-
body: {
|
|
153
|
-
members: params.members,
|
|
154
|
-
epoch: params.epoch
|
|
155
|
-
}
|
|
156
|
-
});
|
|
31
|
+
return envelopes;
|
|
32
|
+
}
|
|
157
33
|
}
|
|
158
34
|
export {
|
|
159
|
-
|
|
160
|
-
buildHcs16CreateFloraTopicTx,
|
|
161
|
-
buildHcs16CreateTransactionTopicTx,
|
|
162
|
-
buildHcs16FloraCreatedTx,
|
|
163
|
-
buildHcs16FloraJoinAcceptedTx,
|
|
164
|
-
buildHcs16FloraJoinRequestTx,
|
|
165
|
-
buildHcs16FloraJoinVoteTx,
|
|
166
|
-
buildHcs16MessageTx,
|
|
167
|
-
buildHcs16ScheduleAccountKeyUpdateTx,
|
|
168
|
-
buildHcs16ScheduleTopicKeyUpdateTx,
|
|
169
|
-
buildHcs16StateUpdateTx,
|
|
170
|
-
buildHcs16TransactionTx
|
|
35
|
+
HCS21BrowserClient
|
|
171
36
|
};
|
|
172
37
|
//# sourceMappingURL=standards-sdk.es85.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es85.js","sources":["../../src/hcs-16/tx.ts"],"sourcesContent":["import {\n TopicCreateTransaction,\n TopicMessageSubmitTransaction,\n TopicUpdateTransaction,\n AccountCreateTransaction,\n AccountUpdateTransaction,\n ScheduleCreateTransaction,\n Hbar,\n PublicKey,\n KeyList,\n AccountId,\n CustomFixedFee,\n TokenId,\n} from '@hashgraph/sdk';\nimport {\n buildTopicCreateTx,\n buildMessageTx,\n type MaybeKey,\n} from '../common/tx/tx-utils';\nimport { FloraOperation, FloraTopicType, type FloraMessage } from './types';\n\nfunction encodeHcs16FloraMemo(params: {\n floraAccountId: string;\n topicType: FloraTopicType;\n}): string {\n return `hcs-16:${params.floraAccountId}:${params.topicType}`;\n}\n\n/**\n * Build a TopicCreateTransaction for HCS‑16 Flora topics (communication/transaction/state).\n */\nexport function buildHcs16CreateFloraTopicTx(params: {\n floraAccountId: string;\n topicType: FloraTopicType;\n adminKey?: MaybeKey;\n submitKey?: MaybeKey;\n operatorPublicKey?: PublicKey;\n autoRenewAccountId?: string;\n}): TopicCreateTransaction {\n const memo = encodeHcs16FloraMemo({\n floraAccountId: params.floraAccountId,\n topicType: params.topicType,\n });\n const tx = buildTopicCreateTx({\n memo,\n adminKey: params.adminKey,\n submitKey: params.submitKey,\n operatorPublicKey: params.operatorPublicKey,\n });\n if (params.autoRenewAccountId) {\n tx.setAutoRenewAccountId(AccountId.fromString(params.autoRenewAccountId));\n }\n return tx;\n}\n\n/**\n * Build a TopicCreateTransaction for a generic HCS‑16 transaction topic with HIP‑991 fees.\n */\nexport function buildHcs16CreateTransactionTopicTx(params: {\n memo: string;\n adminKey?: KeyList | PublicKey;\n submitKey?: KeyList | PublicKey;\n feeScheduleKey?: KeyList | PublicKey;\n customFees?: Array<{\n amount: number;\n feeCollectorAccountId: string;\n denominatingTokenId?: string;\n }>;\n feeExemptKeys?: PublicKey[];\n}): TopicCreateTransaction {\n const tx = new TopicCreateTransaction().setTopicMemo(params.memo);\n if (params.adminKey) {\n tx.setAdminKey(params.adminKey);\n }\n if (params.submitKey) {\n tx.setSubmitKey(params.submitKey);\n }\n if (params.feeScheduleKey) {\n tx.setFeeScheduleKey(params.feeScheduleKey);\n }\n if (params.customFees && params.customFees.length > 0) {\n const fees = params.customFees.map(fee => {\n const cf = new CustomFixedFee()\n .setAmount(fee.amount)\n .setFeeCollectorAccountId(\n AccountId.fromString(fee.feeCollectorAccountId),\n );\n if (fee.denominatingTokenId) {\n cf.setDenominatingTokenId(TokenId.fromString(fee.denominatingTokenId));\n }\n return cf;\n });\n tx.setCustomFees(fees);\n }\n if (params.feeExemptKeys && params.feeExemptKeys.length > 0) {\n throw new Error('feeExemptKeys not supported by installed @hashgraph/sdk');\n }\n return tx;\n}\n\n/**\n * Build an AccountCreateTransaction for a Flora account given a KeyList and optional params.\n */\nexport function buildHcs16CreateAccountTx(params: {\n keyList: KeyList;\n initialBalanceHbar?: number;\n maxAutomaticTokenAssociations?: number;\n}): AccountCreateTransaction {\n const tx = new AccountCreateTransaction().setKey(params.keyList);\n const initial =\n typeof params.initialBalanceHbar === 'number'\n ? params.initialBalanceHbar\n : 1;\n tx.setInitialBalance(new Hbar(initial));\n const maxAssoc =\n typeof params.maxAutomaticTokenAssociations === 'number'\n ? params.maxAutomaticTokenAssociations\n : -1;\n tx.setMaxAutomaticTokenAssociations(maxAssoc);\n return tx;\n}\n\n/**\n * Build a ScheduleCreateTransaction that wraps an AccountUpdateTransaction to rotate the Flora account KeyList.\n * Members will sign this scheduled transaction until threshold is reached and it executes.\n */\nexport function buildHcs16ScheduleAccountKeyUpdateTx(params: {\n floraAccountId: string;\n newKeyList: KeyList;\n memo?: string;\n}): ScheduleCreateTransaction {\n const inner = new AccountUpdateTransaction()\n .setAccountId(AccountId.fromString(params.floraAccountId))\n .setKey(params.newKeyList);\n if (params.memo) {\n inner.setTransactionMemo(params.memo);\n }\n return new ScheduleCreateTransaction().setScheduledTransaction(inner);\n}\n\n/**\n * Build a ScheduleCreateTransaction that wraps a TopicUpdateTransaction to rotate topic admin/submit keys.\n * Repeat for CTopic, TTopic, and STopic as needed for membership changes.\n */\nexport function buildHcs16ScheduleTopicKeyUpdateTx(params: {\n topicId: string;\n adminKey?: KeyList | PublicKey;\n submitKey?: KeyList | PublicKey;\n memo?: string;\n}): ScheduleCreateTransaction {\n const inner = new TopicUpdateTransaction().setTopicId(params.topicId);\n if (params.adminKey) {\n inner.setAdminKey(params.adminKey);\n }\n if (params.submitKey) {\n inner.setSubmitKey(params.submitKey);\n }\n if (params.memo) {\n inner.setTransactionMemo(params.memo);\n }\n return new ScheduleCreateTransaction().setScheduledTransaction(inner);\n}\n\n/**\n * Build a TopicMessageSubmitTransaction for generic HCS‑16 messages.\n * Body fields are merged into the envelope `{ p: 'hcs-16', op, operator_id }`.\n */\nexport function buildHcs16MessageTx(params: {\n topicId: string;\n operatorId: string;\n op: FloraOperation;\n body?: Record<string, unknown>;\n}): TopicMessageSubmitTransaction {\n const payload: FloraMessage = {\n p: 'hcs-16',\n op: params.op,\n operator_id: params.operatorId,\n ...(params.body || {}),\n } as FloraMessage;\n\n return buildMessageTx({\n topicId: params.topicId,\n message: JSON.stringify(payload),\n });\n}\n\n/**\n * Build HCS‑16 flora_created message.\n */\nexport function buildHcs16FloraCreatedTx(params: {\n topicId: string;\n operatorId: string;\n floraAccountId: string;\n topics: { communication: string; transaction: string; state: string };\n}): TopicMessageSubmitTransaction {\n return buildHcs16MessageTx({\n topicId: params.topicId,\n operatorId: params.operatorId,\n op: FloraOperation.FLORA_CREATED,\n body: {\n flora_account_id: params.floraAccountId,\n topics: params.topics,\n },\n });\n}\n\n/**\n * Build HCS‑16 transaction message.\n */\nexport function buildHcs16TransactionTx(params: {\n topicId: string;\n operatorId: string;\n scheduleId: string;\n data?: string;\n}): TopicMessageSubmitTransaction {\n return buildHcs16MessageTx({\n topicId: params.topicId,\n operatorId: params.operatorId,\n op: FloraOperation.TRANSACTION,\n body: {\n schedule_id: params.scheduleId,\n data: params.data,\n m: params.data,\n },\n });\n}\n\n/**\n * Build HCS‑16 state_update message.\n */\nexport function buildHcs16StateUpdateTx(params: {\n topicId: string;\n operatorId: string;\n hash: string;\n epoch?: number;\n}): TopicMessageSubmitTransaction {\n return buildHcs16MessageTx({\n topicId: params.topicId,\n operatorId: params.operatorId,\n op: FloraOperation.STATE_UPDATE,\n body: {\n hash: params.hash,\n epoch: params.epoch,\n timestamp: new Date().toISOString(),\n },\n });\n}\n\n/**\n * Build HCS‑16 flora_join_request message.\n */\nexport function buildHcs16FloraJoinRequestTx(params: {\n topicId: string;\n operatorId: string;\n candidateAccountId: string;\n}): TopicMessageSubmitTransaction {\n return buildHcs16MessageTx({\n topicId: params.topicId,\n operatorId: params.operatorId,\n op: FloraOperation.FLORA_JOIN_REQUEST,\n body: {\n candidate_account_id: params.candidateAccountId,\n },\n });\n}\n\n/**\n * Build HCS‑16 flora_join_vote message.\n */\nexport function buildHcs16FloraJoinVoteTx(params: {\n topicId: string;\n operatorId: string;\n candidateAccountId: string;\n approve: boolean;\n}): TopicMessageSubmitTransaction {\n return buildHcs16MessageTx({\n topicId: params.topicId,\n operatorId: params.operatorId,\n op: FloraOperation.FLORA_JOIN_VOTE,\n body: {\n candidate_account_id: params.candidateAccountId,\n approve: params.approve,\n },\n });\n}\n\n/**\n * Build HCS‑16 flora_join_accepted message.\n */\nexport function buildHcs16FloraJoinAcceptedTx(params: {\n topicId: string;\n operatorId: string;\n members: string[];\n epoch?: number;\n}): TopicMessageSubmitTransaction {\n return buildHcs16MessageTx({\n topicId: params.topicId,\n operatorId: params.operatorId,\n op: FloraOperation.FLORA_JOIN_ACCEPTED,\n body: {\n members: params.members,\n epoch: params.epoch,\n },\n });\n}\n"],"names":[],"mappings":";;;AAqBA,SAAS,qBAAqB,QAGnB;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"standards-sdk.es85.js","sources":["../../src/hcs-21/browser.ts"],"sourcesContent":["import type { HashinalsWalletConnectSDK } from '@hashgraphonline/hashinal-wc';\nimport type { ILogger } from '../utils/logger';\nimport { NetworkType } from '../utils/types';\nimport { HCS21BaseClient, BuildDeclarationParams } from './base-client';\nimport { PackageDeclaration, PackageDeclarationEnvelope } from './types';\n\nexport interface BrowserHCS21ClientConfig {\n network: NetworkType;\n hwc: HashinalsWalletConnectSDK;\n logger?: ILogger;\n}\n\nexport class HCS21BrowserClient extends HCS21BaseClient {\n private readonly hwc: HashinalsWalletConnectSDK;\n\n constructor(config: BrowserHCS21ClientConfig) {\n super({ network: config.network, logger: config.logger });\n this.hwc = config.hwc;\n }\n\n async publishDeclaration(params: {\n topicId: string;\n declaration: PackageDeclaration | BuildDeclarationParams;\n }): Promise<void> {\n const declaration =\n 'p' in params.declaration\n ? this.validateDeclaration(params.declaration)\n : this.buildDeclaration(params.declaration);\n\n await this.hwc.submitMessageToTopic(\n params.topicId,\n JSON.stringify(declaration),\n );\n }\n\n async fetchDeclarations(\n topicId: string,\n ): Promise<PackageDeclarationEnvelope[]> {\n const { messages = [] } = await this.hwc.getMessages(topicId);\n const envelopes: PackageDeclarationEnvelope[] = [];\n\n for (const message of messages) {\n try {\n const declaration = this.validateDeclaration(message.message);\n envelopes.push({\n declaration,\n consensusTimestamp: message.consensus_timestamp,\n sequenceNumber: Number(message.sequence_number || 0),\n payer: message.payer_account_id,\n });\n } catch (error) {\n const detail = error instanceof Error ? error.message : 'unknown error';\n this.logger.warn(`Skipping invalid HCS-21 browser message: ${detail}`);\n }\n }\n\n return envelopes;\n }\n}\n"],"names":[],"mappings":";AAYO,MAAM,2BAA2B,gBAAgB;AAAA,EAGtD,YAAY,QAAkC;AAC5C,UAAM,EAAE,SAAS,OAAO,SAAS,QAAQ,OAAO,QAAQ;AACxD,SAAK,MAAM,OAAO;AAAA,EACpB;AAAA,EAEA,MAAM,mBAAmB,QAGP;AAChB,UAAM,cACJ,OAAO,OAAO,cACV,KAAK,oBAAoB,OAAO,WAAW,IAC3C,KAAK,iBAAiB,OAAO,WAAW;AAE9C,UAAM,KAAK,IAAI;AAAA,MACb,OAAO;AAAA,MACP,KAAK,UAAU,WAAW;AAAA,IAAA;AAAA,EAE9B;AAAA,EAEA,MAAM,kBACJ,SACuC;AACvC,UAAM,EAAE,WAAW,GAAC,IAAM,MAAM,KAAK,IAAI,YAAY,OAAO;AAC5D,UAAM,YAA0C,CAAA;AAEhD,eAAW,WAAW,UAAU;AAC9B,UAAI;AACF,cAAM,cAAc,KAAK,oBAAoB,QAAQ,OAAO;AAC5D,kBAAU,KAAK;AAAA,UACb;AAAA,UACA,oBAAoB,QAAQ;AAAA,UAC5B,gBAAgB,OAAO,QAAQ,mBAAmB,CAAC;AAAA,UACnD,OAAO,QAAQ;AAAA,QAAA,CAChB;AAAA,MACH,SAAS,OAAO;AACd,cAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU;AACxD,aAAK,OAAO,KAAK,4CAA4C,MAAM,EAAE;AAAA,MACvE;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;"}
|
|
@@ -1,133 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.client = this.operatorCtx.client;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Create a Flora topic with memo `hcs-16:<floraAccountId>:<topicType>`.
|
|
24
|
-
*/
|
|
25
|
-
async createFloraTopic(params) {
|
|
26
|
-
const tx = buildHcs16CreateFloraTopicTx({
|
|
27
|
-
floraAccountId: params.floraAccountId,
|
|
28
|
-
topicType: params.topicType,
|
|
29
|
-
adminKey: params.adminKey,
|
|
30
|
-
submitKey: params.submitKey,
|
|
31
|
-
operatorPublicKey: this.client.operatorPublicKey || void 0,
|
|
32
|
-
autoRenewAccountId: params.autoRenewAccountId
|
|
33
|
-
});
|
|
34
|
-
const resp = await tx.execute(this.client);
|
|
35
|
-
const receipt = await resp.getReceipt(this.client);
|
|
36
|
-
if (!receipt.topicId) {
|
|
37
|
-
throw new Error("Failed to create Flora topic");
|
|
38
|
-
}
|
|
39
|
-
return receipt.topicId.toString();
|
|
40
|
-
}
|
|
41
|
-
async sendFloraCreated(params) {
|
|
42
|
-
const tx = buildHcs16FloraCreatedTx(params);
|
|
43
|
-
const resp = await tx.execute(this.client);
|
|
44
|
-
return resp.getReceipt(this.client);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Send HCS-16 transaction (preferred). scheduleId is the ScheduleId entity (e.g., 0.0.12345).
|
|
48
|
-
*/
|
|
49
|
-
async sendTransaction(params) {
|
|
50
|
-
const tx = buildHcs16TransactionTx(params);
|
|
51
|
-
const resp = await tx.execute(this.client);
|
|
52
|
-
return resp.getReceipt(this.client);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Sign a scheduled transaction by ScheduleId entity using provided signer key (PrivateKey).
|
|
56
|
-
* The signer must be a valid member key for the scheduled transaction to count toward threshold.
|
|
57
|
-
*/
|
|
58
|
-
async signSchedule(params) {
|
|
59
|
-
const tx = await new ScheduleSignTransaction().setScheduleId(params.scheduleId).freezeWith(this.client);
|
|
60
|
-
const signed = await tx.sign(params.signerKey);
|
|
61
|
-
const resp = await signed.execute(this.client);
|
|
62
|
-
return resp.getReceipt(this.client);
|
|
63
|
-
}
|
|
64
|
-
async sendStateUpdate(params) {
|
|
65
|
-
const tx = buildHcs16StateUpdateTx(params);
|
|
66
|
-
const resp = await tx.execute(this.client);
|
|
67
|
-
return resp.getReceipt(this.client);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Resolve member public keys from Mirror Node and build a KeyList with the given threshold.
|
|
71
|
-
*/
|
|
72
|
-
async assembleKeyList(params) {
|
|
73
|
-
return super.assembleKeyList(params);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Create a Flora account with a threshold KeyList, then create the three Flora topics.
|
|
77
|
-
* Returns the Flora account ID and the topic IDs.
|
|
78
|
-
*/
|
|
79
|
-
async createFloraAccountWithTopics(params) {
|
|
80
|
-
const keyList = await this.assembleKeyList({
|
|
81
|
-
members: params.members,
|
|
82
|
-
threshold: params.threshold
|
|
83
|
-
});
|
|
84
|
-
const submitList = await this.assembleSubmitKeyList(params.members);
|
|
85
|
-
const createAcc = buildHcs16CreateAccountTx({
|
|
86
|
-
keyList,
|
|
87
|
-
initialBalanceHbar: typeof params.initialBalanceHbar === "number" ? params.initialBalanceHbar : 5,
|
|
88
|
-
maxAutomaticTokenAssociations: -1
|
|
89
|
-
});
|
|
90
|
-
const accResp = await createAcc.execute(this.client);
|
|
91
|
-
const accReceipt = await accResp.getReceipt(this.client);
|
|
92
|
-
if (!accReceipt.accountId) {
|
|
93
|
-
throw new Error("Failed to create Flora account");
|
|
94
|
-
}
|
|
95
|
-
const floraAccountId = accReceipt.accountId.toString();
|
|
96
|
-
const {
|
|
97
|
-
communication: commTx,
|
|
98
|
-
transaction: trnTx,
|
|
99
|
-
state: stateTx
|
|
100
|
-
} = this.buildFloraTopicCreateTxs({
|
|
101
|
-
floraAccountId,
|
|
102
|
-
keyList,
|
|
103
|
-
submitList,
|
|
104
|
-
autoRenewAccountId: params.autoRenewAccountId
|
|
105
|
-
});
|
|
106
|
-
const commR = await commTx.execute(this.client).then((r) => r.getReceipt(this.client));
|
|
107
|
-
const trnR = await trnTx.execute(this.client).then((r) => r.getReceipt(this.client));
|
|
108
|
-
const stateR = await stateTx.execute(this.client).then((r) => r.getReceipt(this.client));
|
|
109
|
-
const topics = {
|
|
110
|
-
communication: commR.topicId.toString(),
|
|
111
|
-
transaction: trnR.topicId.toString(),
|
|
112
|
-
state: stateR.topicId.toString()
|
|
113
|
-
};
|
|
114
|
-
return { floraAccountId, topics };
|
|
1
|
+
import { AccountCreateTransaction, Hbar } from "@hashgraph/sdk";
|
|
2
|
+
function buildHcs15BaseAccountCreateTx(params) {
|
|
3
|
+
const tx = new AccountCreateTransaction().setECDSAKeyWithAlias(params.publicKey).setInitialBalance(
|
|
4
|
+
params.initialBalance instanceof Hbar ? params.initialBalance : new Hbar(params.initialBalance ?? 1)
|
|
5
|
+
);
|
|
6
|
+
if (typeof params.maxAutomaticTokenAssociations === "number") {
|
|
7
|
+
tx.setMaxAutomaticTokenAssociations(params.maxAutomaticTokenAssociations);
|
|
8
|
+
}
|
|
9
|
+
if (params.accountMemo) {
|
|
10
|
+
tx.setAccountMemo(params.accountMemo);
|
|
11
|
+
}
|
|
12
|
+
return tx;
|
|
13
|
+
}
|
|
14
|
+
function buildHcs15PetalAccountCreateTx(params) {
|
|
15
|
+
const tx = new AccountCreateTransaction().setKeyWithoutAlias(params.publicKey).setInitialBalance(
|
|
16
|
+
params.initialBalance instanceof Hbar ? params.initialBalance : new Hbar(params.initialBalance ?? 1)
|
|
17
|
+
);
|
|
18
|
+
if (typeof params.maxAutomaticTokenAssociations === "number") {
|
|
19
|
+
tx.setMaxAutomaticTokenAssociations(params.maxAutomaticTokenAssociations);
|
|
115
20
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
*/
|
|
119
|
-
async publishFloraCreated(params) {
|
|
120
|
-
const tx = buildHcs16FloraCreatedTx({
|
|
121
|
-
topicId: params.communicationTopicId,
|
|
122
|
-
operatorId: params.operatorId,
|
|
123
|
-
floraAccountId: params.floraAccountId,
|
|
124
|
-
topics: params.topics
|
|
125
|
-
});
|
|
126
|
-
const resp = await tx.execute(this.client);
|
|
127
|
-
return resp.getReceipt(this.client);
|
|
21
|
+
if (params.accountMemo) {
|
|
22
|
+
tx.setAccountMemo(params.accountMemo);
|
|
128
23
|
}
|
|
24
|
+
return tx;
|
|
129
25
|
}
|
|
130
26
|
export {
|
|
131
|
-
|
|
27
|
+
buildHcs15BaseAccountCreateTx,
|
|
28
|
+
buildHcs15PetalAccountCreateTx
|
|
132
29
|
};
|
|
133
30
|
//# sourceMappingURL=standards-sdk.es86.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es86.js","sources":["../../src/hcs-16/sdk.ts"],"sourcesContent":["import {\n Client,\n AccountId,\n PublicKey,\n KeyList,\n TransactionReceipt,\n Hbar,\n ScheduleSignTransaction,\n PrivateKey,\n} from '@hashgraph/sdk';\nimport type { NetworkType } from '../utils/types';\nimport type { Logger } from '../utils/logger';\nimport {\n createNodeOperatorContext,\n type NodeOperatorContext,\n} from '../common/node-operator-resolver';\nimport { HederaMirrorNode } from '../services/mirror-node';\nimport { HCS16BaseClient } from './base-client';\nimport {\n buildHcs16CreateFloraTopicTx,\n buildHcs16FloraCreatedTx,\n buildHcs16TransactionTx,\n buildHcs16StateUpdateTx,\n} from './tx';\nimport { FloraTopicType } from './types';\nimport {\n buildHcs16FloraJoinRequestTx,\n buildHcs16FloraJoinVoteTx,\n buildHcs16FloraJoinAcceptedTx,\n buildHcs16CreateAccountTx,\n} from './tx';\n\nexport interface HCS16ClientConfig {\n network: NetworkType;\n operatorId: string;\n operatorKey: string;\n keyType?: 'ecdsa' | 'ed25519';\n logger?: Logger;\n}\n\n/**\n * Node SDK client for HCS‑16 Flora operations.\n */\nexport class HCS16Client extends HCS16BaseClient {\n private readonly client: Client;\n private readonly operatorId: AccountId;\n private readonly operatorCtx: NodeOperatorContext;\n\n constructor(config: HCS16ClientConfig) {\n super({ network: config.network, logger: config.logger });\n this.operatorId = AccountId.fromString(config.operatorId);\n const mirror = new HederaMirrorNode(config.network, this.logger);\n this.operatorCtx = createNodeOperatorContext({\n network: config.network,\n operatorId: this.operatorId,\n operatorKey: config.operatorKey,\n keyType: config.keyType,\n mirrorNode: mirror,\n logger: this.logger,\n client:\n config.network === 'mainnet'\n ? Client.forMainnet()\n : Client.forTestnet(),\n });\n this.client = this.operatorCtx.client;\n }\n\n /**\n * Create a Flora topic with memo `hcs-16:<floraAccountId>:<topicType>`.\n */\n async createFloraTopic(params: {\n floraAccountId: string;\n topicType: FloraTopicType;\n adminKey?: PublicKey | KeyList;\n submitKey?: PublicKey | KeyList;\n autoRenewAccountId?: string;\n }): Promise<string> {\n const tx = buildHcs16CreateFloraTopicTx({\n floraAccountId: params.floraAccountId,\n topicType: params.topicType,\n adminKey: params.adminKey,\n submitKey: params.submitKey,\n operatorPublicKey: this.client.operatorPublicKey || undefined,\n autoRenewAccountId: params.autoRenewAccountId,\n });\n const resp = await tx.execute(this.client);\n const receipt = await resp.getReceipt(this.client);\n if (!receipt.topicId) {\n throw new Error('Failed to create Flora topic');\n }\n return receipt.topicId.toString();\n }\n\n async sendFloraCreated(params: {\n topicId: string;\n operatorId: string;\n floraAccountId: string;\n topics: { communication: string; transaction: string; state: string };\n }): Promise<TransactionReceipt> {\n const tx = buildHcs16FloraCreatedTx(params);\n const resp = await tx.execute(this.client);\n return resp.getReceipt(this.client);\n }\n\n /**\n * Send HCS-16 transaction (preferred). scheduleId is the ScheduleId entity (e.g., 0.0.12345).\n */\n async sendTransaction(params: {\n topicId: string;\n operatorId: string;\n scheduleId: string;\n data?: string;\n }): Promise<TransactionReceipt> {\n const tx = buildHcs16TransactionTx(params);\n const resp = await tx.execute(this.client);\n return resp.getReceipt(this.client);\n }\n\n /**\n * Sign a scheduled transaction by ScheduleId entity using provided signer key (PrivateKey).\n * The signer must be a valid member key for the scheduled transaction to count toward threshold.\n */\n async signSchedule(params: {\n scheduleId: string;\n signerKey: PrivateKey;\n }): Promise<TransactionReceipt> {\n const tx = await new ScheduleSignTransaction()\n .setScheduleId(params.scheduleId)\n .freezeWith(this.client);\n const signed = await tx.sign(params.signerKey);\n const resp = await signed.execute(this.client);\n return resp.getReceipt(this.client);\n }\n\n async sendStateUpdate(params: {\n topicId: string;\n operatorId: string;\n hash: string;\n epoch?: number;\n }): Promise<TransactionReceipt> {\n const tx = buildHcs16StateUpdateTx(params);\n const resp = await tx.execute(this.client);\n return resp.getReceipt(this.client);\n }\n\n /**\n * Resolve member public keys from Mirror Node and build a KeyList with the given threshold.\n */\n async assembleKeyList(params: {\n members: string[];\n threshold: number;\n }): Promise<KeyList> {\n return super.assembleKeyList(params);\n }\n\n /**\n * Create a Flora account with a threshold KeyList, then create the three Flora topics.\n * Returns the Flora account ID and the topic IDs.\n */\n async createFloraAccountWithTopics(params: {\n members: string[];\n threshold: number;\n initialBalanceHbar?: number;\n autoRenewAccountId?: string;\n }): Promise<{\n floraAccountId: string;\n topics: { communication: string; transaction: string; state: string };\n }> {\n const keyList = await this.assembleKeyList({\n members: params.members,\n threshold: params.threshold,\n });\n const submitList = await this.assembleSubmitKeyList(params.members);\n\n const createAcc = buildHcs16CreateAccountTx({\n keyList,\n initialBalanceHbar:\n typeof params.initialBalanceHbar === 'number'\n ? params.initialBalanceHbar\n : 5,\n maxAutomaticTokenAssociations: -1,\n });\n const accResp = await createAcc.execute(this.client);\n const accReceipt = await accResp.getReceipt(this.client);\n if (!accReceipt.accountId) {\n throw new Error('Failed to create Flora account');\n }\n const floraAccountId = accReceipt.accountId.toString();\n\n const {\n communication: commTx,\n transaction: trnTx,\n state: stateTx,\n } = this.buildFloraTopicCreateTxs({\n floraAccountId,\n keyList,\n submitList,\n autoRenewAccountId: params.autoRenewAccountId,\n });\n\n const commR = await commTx\n .execute(this.client)\n .then(r => r.getReceipt(this.client));\n const trnR = await trnTx\n .execute(this.client)\n .then(r => r.getReceipt(this.client));\n const stateR = await stateTx\n .execute(this.client)\n .then(r => r.getReceipt(this.client));\n const topics = {\n communication: commR.topicId!.toString(),\n transaction: trnR.topicId!.toString(),\n state: stateR.topicId!.toString(),\n };\n return { floraAccountId, topics };\n }\n\n /**\n * Convenience: publish flora_created on the communication topic.\n */\n async publishFloraCreated(params: {\n communicationTopicId: string;\n operatorId: string;\n floraAccountId: string;\n topics: { communication: string; transaction: string; state: string };\n }): Promise<TransactionReceipt> {\n const tx = buildHcs16FloraCreatedTx({\n topicId: params.communicationTopicId,\n operatorId: params.operatorId,\n floraAccountId: params.floraAccountId,\n topics: params.topics,\n });\n const resp = await tx.execute(this.client);\n return resp.getReceipt(this.client);\n }\n}\n"],"names":[],"mappings":";;;;;AA2CO,MAAM,oBAAoB,gBAAgB;AAAA,EAK/C,YAAY,QAA2B;AACrC,UAAM,EAAE,SAAS,OAAO,SAAS,QAAQ,OAAO,QAAQ;AACxD,SAAK,aAAa,UAAU,WAAW,OAAO,UAAU;AACxD,UAAM,SAAS,IAAI,iBAAiB,OAAO,SAAS,KAAK,MAAM;AAC/D,SAAK,cAAc,0BAA0B;AAAA,MAC3C,SAAS,OAAO;AAAA,MAChB,YAAY,KAAK;AAAA,MACjB,aAAa,OAAO;AAAA,MACpB,SAAS,OAAO;AAAA,MAChB,YAAY;AAAA,MACZ,QAAQ,KAAK;AAAA,MACb,QACE,OAAO,YAAY,YACf,OAAO,WAAA,IACP,OAAO,WAAA;AAAA,IAAW,CACzB;AACD,SAAK,SAAS,KAAK,YAAY;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,iBAAiB,QAMH;AAClB,UAAM,KAAK,6BAA6B;AAAA,MACtC,gBAAgB,OAAO;AAAA,MACvB,WAAW,OAAO;AAAA,MAClB,UAAU,OAAO;AAAA,MACjB,WAAW,OAAO;AAAA,MAClB,mBAAmB,KAAK,OAAO,qBAAqB;AAAA,MACpD,oBAAoB,OAAO;AAAA,IAAA,CAC5B;AACD,UAAM,OAAO,MAAM,GAAG,QAAQ,KAAK,MAAM;AACzC,UAAM,UAAU,MAAM,KAAK,WAAW,KAAK,MAAM;AACjD,QAAI,CAAC,QAAQ,SAAS;AACpB,YAAM,IAAI,MAAM,8BAA8B;AAAA,IAChD;AACA,WAAO,QAAQ,QAAQ,SAAA;AAAA,EACzB;AAAA,EAEA,MAAM,iBAAiB,QAKS;AAC9B,UAAM,KAAK,yBAAyB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,UAAM,aAAa,MAAM,QAAQ,WAAW,KAAK,MAAM;AACvD,QAAI,CAAC,WAAW,WAAW;AACzB,YAAM,IAAI,MAAM,gCAAgC;AAAA,IAClD;AACA,UAAM,iBAAiB,WAAW,UAAU,SAAA;AAE5C,UAAM;AAAA,MACJ,eAAe;AAAA,MACf,aAAa;AAAA,MACb,OAAO;AAAA,IAAA,IACL,KAAK,yBAAyB;AAAA,MAChC;AAAA,MACA;AAAA,MACA;AAAA,MACA,oBAAoB,OAAO;AAAA,IAAA,CAC5B;AAED,UAAM,QAAQ,MAAM,OACjB,QAAQ,KAAK,MAAM,EACnB,KAAK,CAAA,MAAK,EAAE,WAAW,KAAK,MAAM,CAAC;AACtC,UAAM,OAAO,MAAM,MAChB,QAAQ,KAAK,MAAM,EACnB,KAAK,CAAA,MAAK,EAAE,WAAW,KAAK,MAAM,CAAC;AACtC,UAAM,SAAS,MAAM,QAClB,QAAQ,KAAK,MAAM,EACnB,KAAK,CAAA,MAAK,EAAE,WAAW,KAAK,MAAM,CAAC;AACtC,UAAM,SAAS;AAAA,MACb,eAAe,MAAM,QAAS,SAAA;AAAA,MAC9B,aAAa,KAAK,QAAS,SAAA;AAAA,MAC3B,OAAO,OAAO,QAAS,SAAA;AAAA,IAAS;AAElC,WAAO,EAAE,gBAAgB,OAAA;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,oBAAoB,QAKM;AAC9B,UAAM,KAAK,yBAAyB;AAAA,MAClC,SAAS,OAAO;AAAA,MAChB,YAAY,OAAO;AAAA,MACnB,gBAAgB,OAAO;AAAA,MACvB,QAAQ,OAAO;AAAA,IAAA,CAChB;AACD,UAAM,OAAO,MAAM,GAAG,QAAQ,KAAK,MAAM;AACzC,WAAO,KAAK,WAAW,KAAK,MAAM;AAAA,EACpC;AACF;"}
|
|
1
|
+
{"version":3,"file":"standards-sdk.es86.js","sources":["../../src/hcs-15/tx.ts"],"sourcesContent":["import { AccountCreateTransaction, Hbar, PublicKey } from '@hashgraph/sdk';\n\n/**\n * Build AccountCreateTransaction for an HCS-15 base account.\n * Uses an ECDSA public key and sets the EVM alias from it.\n */\nexport function buildHcs15BaseAccountCreateTx(params: {\n publicKey: PublicKey;\n initialBalance?: Hbar | number;\n maxAutomaticTokenAssociations?: number;\n accountMemo?: string;\n}): AccountCreateTransaction {\n const tx = new AccountCreateTransaction()\n .setECDSAKeyWithAlias(params.publicKey)\n .setInitialBalance(\n params.initialBalance instanceof Hbar\n ? params.initialBalance\n : new Hbar(params.initialBalance ?? 1),\n );\n\n if (typeof params.maxAutomaticTokenAssociations === 'number') {\n tx.setMaxAutomaticTokenAssociations(params.maxAutomaticTokenAssociations);\n }\n if (params.accountMemo) {\n tx.setAccountMemo(params.accountMemo);\n }\n return tx;\n}\n\n/**\n * Build AccountCreateTransaction for an HCS-15 Petal account.\n * Reuses the same public key as the base account, without alias.\n */\nexport function buildHcs15PetalAccountCreateTx(params: {\n publicKey: PublicKey;\n initialBalance?: Hbar | number;\n maxAutomaticTokenAssociations?: number;\n accountMemo?: string;\n}): AccountCreateTransaction {\n const tx = new AccountCreateTransaction()\n .setKeyWithoutAlias(params.publicKey)\n .setInitialBalance(\n params.initialBalance instanceof Hbar\n ? params.initialBalance\n : new Hbar(params.initialBalance ?? 1),\n );\n\n if (typeof params.maxAutomaticTokenAssociations === 'number') {\n tx.setMaxAutomaticTokenAssociations(params.maxAutomaticTokenAssociations);\n }\n if (params.accountMemo) {\n tx.setAccountMemo(params.accountMemo);\n }\n return tx;\n}\n"],"names":[],"mappings":";AAMO,SAAS,8BAA8B,QAKjB;AAC3B,QAAM,KAAK,IAAI,yBAAA,EACZ,qBAAqB,OAAO,SAAS,EACrC;AAAA,IACC,OAAO,0BAA0B,OAC7B,OAAO,iBACP,IAAI,KAAK,OAAO,kBAAkB,CAAC;AAAA,EAAA;AAG3C,MAAI,OAAO,OAAO,kCAAkC,UAAU;AAC5D,OAAG,iCAAiC,OAAO,6BAA6B;AAAA,EAC1E;AACA,MAAI,OAAO,aAAa;AACtB,OAAG,eAAe,OAAO,WAAW;AAAA,EACtC;AACA,SAAO;AACT;AAMO,SAAS,+BAA+B,QAKlB;AAC3B,QAAM,KAAK,IAAI,yBAAA,EACZ,mBAAmB,OAAO,SAAS,EACnC;AAAA,IACC,OAAO,0BAA0B,OAC7B,OAAO,iBACP,IAAI,KAAK,OAAO,kBAAkB,CAAC;AAAA,EAAA;AAG3C,MAAI,OAAO,OAAO,kCAAkC,UAAU;AAC5D,OAAG,iCAAiC,OAAO,6BAA6B;AAAA,EAC1E;AACA,MAAI,OAAO,aAAa;AACtB,OAAG,eAAe,OAAO,WAAW;AAAA,EACtC;AACA,SAAO;AACT;"}
|
|
@@ -1,160 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { AccountId, Client, PrivateKey, Hbar } from "@hashgraph/sdk";
|
|
2
|
+
import { createNodeOperatorContext } from "./standards-sdk.es135.js";
|
|
3
|
+
import { buildHcs15BaseAccountCreateTx, buildHcs15PetalAccountCreateTx } from "./standards-sdk.es86.js";
|
|
4
|
+
import { HCS15BaseClient } from "./standards-sdk.es89.js";
|
|
5
|
+
class HCS15Client extends HCS15BaseClient {
|
|
5
6
|
constructor(config) {
|
|
6
|
-
super(
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (!accountId) {
|
|
17
|
-
throw new Error("No active wallet connection");
|
|
18
|
-
}
|
|
19
|
-
return accountId;
|
|
20
|
-
}
|
|
21
|
-
getSigner() {
|
|
22
|
-
if (this.signer) {
|
|
23
|
-
return this.signer;
|
|
24
|
-
}
|
|
25
|
-
this.ensureConnected();
|
|
26
|
-
const s = this.hwc?.dAppConnector?.signers?.[0];
|
|
27
|
-
if (!s) {
|
|
28
|
-
throw new Error("No active wallet signer");
|
|
29
|
-
}
|
|
30
|
-
return s;
|
|
31
|
-
}
|
|
32
|
-
async createFloraTopic(params) {
|
|
33
|
-
this.ensureConnected();
|
|
34
|
-
const signer = this.getSigner();
|
|
35
|
-
const tx = buildHcs16CreateFloraTopicTx({
|
|
36
|
-
floraAccountId: params.floraAccountId,
|
|
37
|
-
topicType: params.topicType,
|
|
38
|
-
adminKey: params.adminKey,
|
|
39
|
-
submitKey: params.submitKey,
|
|
40
|
-
autoRenewAccountId: params.autoRenewAccountId
|
|
7
|
+
super(config);
|
|
8
|
+
this.operatorId = AccountId.fromString(config.operatorId);
|
|
9
|
+
this.operatorCtx = createNodeOperatorContext({
|
|
10
|
+
network: this.network,
|
|
11
|
+
operatorId: this.operatorId,
|
|
12
|
+
operatorKey: config.operatorKey,
|
|
13
|
+
keyType: config.keyType,
|
|
14
|
+
mirrorNode: this.mirrorNode,
|
|
15
|
+
logger: this.logger,
|
|
16
|
+
client: this.network === "mainnet" ? Client.forMainnet() : Client.forTestnet()
|
|
41
17
|
});
|
|
42
|
-
|
|
43
|
-
const res = await frozen.executeWithSigner(signer);
|
|
44
|
-
const receipt = await res.getReceiptWithSigner(signer);
|
|
45
|
-
const topicId = receipt?.topicId?.toString?.() || "";
|
|
46
|
-
return topicId;
|
|
47
|
-
}
|
|
48
|
-
async sendFloraCreated(params) {
|
|
49
|
-
const signer = this.getSigner();
|
|
50
|
-
const tx = buildHcs16FloraCreatedTx(params);
|
|
51
|
-
const frozen = await tx.freezeWithSigner(signer);
|
|
52
|
-
await frozen.executeWithSigner(signer);
|
|
18
|
+
this.client = this.operatorCtx.client;
|
|
53
19
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const tx = buildHcs16TransactionTx(params);
|
|
57
|
-
const frozen = await tx.freezeWithSigner(signer);
|
|
58
|
-
await frozen.executeWithSigner(signer);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Wallet-signed ScheduleSign for a given scheduleId.
|
|
62
|
-
*/
|
|
63
|
-
async signSchedule(params) {
|
|
64
|
-
const signer = this.getSigner();
|
|
65
|
-
const tx = await new ScheduleSignTransaction().setScheduleId(params.scheduleId).freezeWithSigner(signer);
|
|
66
|
-
await tx.executeWithSigner(signer);
|
|
20
|
+
getKeyType() {
|
|
21
|
+
return this.operatorCtx.keyType;
|
|
67
22
|
}
|
|
68
|
-
async
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
23
|
+
async close() {
|
|
24
|
+
try {
|
|
25
|
+
this.client.close();
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
73
28
|
}
|
|
74
|
-
/** credit_purchase is not part of HCS-16 specification */
|
|
75
29
|
/**
|
|
76
|
-
* Create
|
|
77
|
-
* - Account KeyList = threshold of members
|
|
78
|
-
* - Topic submitKey = 1-of-M KeyList of members
|
|
79
|
-
* Returns created Flora account ID and topic IDs.
|
|
30
|
+
* Create a new base account with a newly generated ECDSA key and EVM alias.
|
|
80
31
|
*/
|
|
81
|
-
async
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
keyList,
|
|
90
|
-
initialBalanceHbar: typeof params.initialBalanceHbar === "number" ? params.initialBalanceHbar : 5,
|
|
91
|
-
maxAutomaticTokenAssociations: -1
|
|
32
|
+
async createBaseAccount(options) {
|
|
33
|
+
const priv = PrivateKey.generateECDSA();
|
|
34
|
+
const pub = priv.publicKey;
|
|
35
|
+
const tx = buildHcs15BaseAccountCreateTx({
|
|
36
|
+
publicKey: pub,
|
|
37
|
+
initialBalance: new Hbar(options?.initialBalance ?? 10),
|
|
38
|
+
maxAutomaticTokenAssociations: options?.maxAutomaticTokenAssociations,
|
|
39
|
+
accountMemo: options?.accountMemo
|
|
92
40
|
});
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (!floraAccountId) {
|
|
98
|
-
throw new Error("Failed to create Flora account");
|
|
41
|
+
const resp = await tx.execute(this.client);
|
|
42
|
+
const receipt = await resp.getReceipt(this.client);
|
|
43
|
+
if (!receipt.accountId) {
|
|
44
|
+
throw new Error("HCS-15 BASE_ACCOUNT_CREATE_FAILED");
|
|
99
45
|
}
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const commR = await (await (await commTx.freezeWithSigner(signer)).executeWithSigner(signer)).getReceiptWithSigner(signer);
|
|
111
|
-
const trnR = await (await (await trnTx.freezeWithSigner(signer)).executeWithSigner(signer)).getReceiptWithSigner(signer);
|
|
112
|
-
const stateR = await (await (await stateTx.freezeWithSigner(signer)).executeWithSigner(signer)).getReceiptWithSigner(signer);
|
|
113
|
-
const topics = {
|
|
114
|
-
communication: commR?.topicId?.toString?.() || "",
|
|
115
|
-
transaction: trnR?.topicId?.toString?.() || "",
|
|
116
|
-
state: stateR?.topicId?.toString?.() || ""
|
|
46
|
+
const accountId = receipt.accountId.toString();
|
|
47
|
+
const evmAddress = `0x${pub.toEvmAddress()}`;
|
|
48
|
+
this.logger.info("Created HCS-15 base account", { accountId, evmAddress });
|
|
49
|
+
return {
|
|
50
|
+
accountId,
|
|
51
|
+
privateKey: priv,
|
|
52
|
+
privateKeyHex: priv.toStringRaw(),
|
|
53
|
+
publicKey: pub,
|
|
54
|
+
evmAddress,
|
|
55
|
+
receipt
|
|
117
56
|
};
|
|
118
|
-
return { floraAccountId, topics };
|
|
119
|
-
}
|
|
120
|
-
/** Publish flora_created on the communication topic. */
|
|
121
|
-
async publishFloraCreated(params) {
|
|
122
|
-
const signer = this.getSigner();
|
|
123
|
-
const tx = buildHcs16FloraCreatedTx({
|
|
124
|
-
topicId: params.communicationTopicId,
|
|
125
|
-
operatorId: params.operatorId,
|
|
126
|
-
floraAccountId: params.floraAccountId,
|
|
127
|
-
topics: params.topics
|
|
128
|
-
});
|
|
129
|
-
const frozen = await tx.freezeWithSigner(signer);
|
|
130
|
-
await frozen.executeWithSigner(signer);
|
|
131
57
|
}
|
|
132
58
|
/**
|
|
133
|
-
*
|
|
134
|
-
* If submitKey=1/M, a member must relay the message.
|
|
59
|
+
* Create a Petal account that reuses the base account ECDSA key (no alias).
|
|
135
60
|
*/
|
|
136
|
-
async
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const frozen = await tx.freezeWithSigner(signer);
|
|
154
|
-
await frozen.executeWithSigner(signer);
|
|
61
|
+
async createPetalAccount(params) {
|
|
62
|
+
const baseKey = typeof params.basePrivateKey === "string" ? PrivateKey.fromStringECDSA(params.basePrivateKey) : params.basePrivateKey;
|
|
63
|
+
const pub = baseKey.publicKey;
|
|
64
|
+
const tx = buildHcs15PetalAccountCreateTx({
|
|
65
|
+
publicKey: pub,
|
|
66
|
+
initialBalance: new Hbar(params.initialBalance ?? 1),
|
|
67
|
+
maxAutomaticTokenAssociations: params.maxAutomaticTokenAssociations,
|
|
68
|
+
accountMemo: params.accountMemo
|
|
69
|
+
});
|
|
70
|
+
const resp = await tx.execute(this.client);
|
|
71
|
+
const receipt = await resp.getReceipt(this.client);
|
|
72
|
+
if (!receipt.accountId) {
|
|
73
|
+
throw new Error("HCS-15 PETAL_ACCOUNT_CREATE_FAILED");
|
|
74
|
+
}
|
|
75
|
+
const accountId = receipt.accountId.toString();
|
|
76
|
+
this.logger.info("Created HCS-15 petal account", { accountId });
|
|
77
|
+
return { accountId, receipt };
|
|
155
78
|
}
|
|
156
79
|
}
|
|
157
80
|
export {
|
|
158
|
-
|
|
81
|
+
HCS15Client
|
|
159
82
|
};
|
|
160
83
|
//# sourceMappingURL=standards-sdk.es87.js.map
|