@hashgraphonline/standards-sdk 0.0.157-canary.2 → 0.0.157-canary.4
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-10/base-client.d.ts +1 -1
- package/dist/cjs/hcs-10/base-client.d.ts.map +1 -1
- package/dist/cjs/hcs-10/sdk.d.ts +1 -1
- package/dist/cjs/hcs-10/sdk.d.ts.map +1 -1
- package/dist/cjs/hcs-11/agent-builder.d.ts +2 -0
- package/dist/cjs/hcs-11/agent-builder.d.ts.map +1 -1
- package/dist/cjs/hcs-11/client.d.ts +2 -0
- package/dist/cjs/hcs-11/client.d.ts.map +1 -1
- package/dist/cjs/hcs-11/types.d.ts +4 -2
- package/dist/cjs/hcs-11/types.d.ts.map +1 -1
- package/dist/cjs/hcs-15/index.d.ts +3 -0
- package/dist/cjs/hcs-15/index.d.ts.map +1 -0
- package/dist/cjs/hcs-15/petal-manager.d.ts +27 -0
- package/dist/cjs/hcs-15/petal-manager.d.ts.map +1 -0
- package/dist/cjs/hcs-15/types.d.ts +41 -0
- package/dist/cjs/hcs-15/types.d.ts.map +1 -0
- package/dist/cjs/hcs-16/flora-account-manager.d.ts.map +1 -1
- package/dist/cjs/hcs-16/types.d.ts +3 -5
- package/dist/cjs/hcs-16/types.d.ts.map +1 -1
- package/dist/cjs/hcs-18/discovery.d.ts +1 -0
- package/dist/cjs/hcs-18/discovery.d.ts.map +1 -1
- package/dist/cjs/hcs-18/types.d.ts +1 -0
- package/dist/cjs/hcs-18/types.d.ts.map +1 -1
- package/dist/cjs/hcs-20/sdk.d.ts.map +1 -1
- package/dist/cjs/hcs-7/evm-bridge.d.ts.map +1 -1
- package/dist/cjs/hcs-7/redis-cache.d.ts.map +1 -1
- package/dist/cjs/hcs-7/wasm-bridge.d.ts.map +1 -1
- package/dist/cjs/{index-xZmk-HBD.cjs → index-CJsmyij2.cjs} +12 -12
- package/dist/cjs/index-CJsmyij2.cjs.map +1 -0
- package/dist/cjs/{index-CyAbgH2f-Cv8mxAhS.cjs → index-CyAbgH2f-Dn5WQtPx.cjs} +2 -2
- package/dist/cjs/{index-CyAbgH2f-Cv8mxAhS.cjs.map → index-CyAbgH2f-Dn5WQtPx.cjs.map} +1 -1
- package/dist/cjs/index.d.ts +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 +1 -1
- package/dist/cjs/{standards-sdk.es45-BxAtDqsy-ELd4REyl.cjs → standards-sdk.es45-BxAtDqsy-CiMtsDbD.cjs} +2 -2
- package/dist/cjs/{standards-sdk.es45-BxAtDqsy-ELd4REyl.cjs.map → standards-sdk.es45-BxAtDqsy-CiMtsDbD.cjs.map} +1 -1
- package/dist/cjs/{standards-sdk.es46-BI8ACeLM-DRmcgoN0.cjs → standards-sdk.es46-BI8ACeLM-DFYgO-fP.cjs} +2 -2
- package/dist/cjs/{standards-sdk.es46-BI8ACeLM-DRmcgoN0.cjs.map → standards-sdk.es46-BI8ACeLM-DFYgO-fP.cjs.map} +1 -1
- package/dist/cjs/{standards-sdk.es47-DbkY3FlD-DfMpZygD.cjs → standards-sdk.es47-DbkY3FlD-2qTWs2BD.cjs} +2 -2
- package/dist/cjs/{standards-sdk.es47-DbkY3FlD-DfMpZygD.cjs.map → standards-sdk.es47-DbkY3FlD-2qTWs2BD.cjs.map} +1 -1
- package/dist/cjs/{standards-sdk.es48-DzT9Qc3F-CmCkJl3x.cjs → standards-sdk.es48-DzT9Qc3F-Byz0fQnW.cjs} +2 -2
- package/dist/cjs/{standards-sdk.es48-DzT9Qc3F-CmCkJl3x.cjs.map → standards-sdk.es48-DzT9Qc3F-Byz0fQnW.cjs.map} +1 -1
- package/dist/cjs/utils/logger.d.ts.map +1 -1
- package/dist/es/hcs-10/base-client.d.ts +1 -1
- package/dist/es/hcs-10/base-client.d.ts.map +1 -1
- package/dist/es/hcs-10/sdk.d.ts +1 -1
- package/dist/es/hcs-10/sdk.d.ts.map +1 -1
- package/dist/es/hcs-11/agent-builder.d.ts +2 -0
- package/dist/es/hcs-11/agent-builder.d.ts.map +1 -1
- package/dist/es/hcs-11/client.d.ts +2 -0
- package/dist/es/hcs-11/client.d.ts.map +1 -1
- package/dist/es/hcs-11/types.d.ts +4 -2
- package/dist/es/hcs-11/types.d.ts.map +1 -1
- package/dist/es/hcs-15/index.d.ts +3 -0
- package/dist/es/hcs-15/index.d.ts.map +1 -0
- package/dist/es/hcs-15/petal-manager.d.ts +27 -0
- package/dist/es/hcs-15/petal-manager.d.ts.map +1 -0
- package/dist/es/hcs-15/types.d.ts +41 -0
- package/dist/es/hcs-15/types.d.ts.map +1 -0
- package/dist/es/hcs-16/flora-account-manager.d.ts.map +1 -1
- package/dist/es/hcs-16/types.d.ts +3 -5
- package/dist/es/hcs-16/types.d.ts.map +1 -1
- package/dist/es/hcs-18/discovery.d.ts +1 -0
- package/dist/es/hcs-18/discovery.d.ts.map +1 -1
- package/dist/es/hcs-18/types.d.ts +1 -0
- package/dist/es/hcs-18/types.d.ts.map +1 -1
- package/dist/es/hcs-20/sdk.d.ts.map +1 -1
- package/dist/es/hcs-7/evm-bridge.d.ts.map +1 -1
- package/dist/es/hcs-7/redis-cache.d.ts.map +1 -1
- package/dist/es/hcs-7/wasm-bridge.d.ts.map +1 -1
- package/dist/es/index.d.ts +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 +19 -22
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/es/standards-sdk.es10.js +1 -1
- package/dist/es/standards-sdk.es11.js +10 -2
- package/dist/es/standards-sdk.es11.js.map +1 -1
- package/dist/es/standards-sdk.es12.js +1 -1
- package/dist/es/standards-sdk.es13.js +1 -1
- package/dist/es/standards-sdk.es13.js.map +1 -1
- package/dist/es/standards-sdk.es14.js +1 -1
- package/dist/es/standards-sdk.es15.js +39 -9
- package/dist/es/standards-sdk.es15.js.map +1 -1
- package/dist/es/standards-sdk.es16.js +1 -0
- package/dist/es/standards-sdk.es16.js.map +1 -1
- package/dist/es/standards-sdk.es18.js +1 -1
- package/dist/es/standards-sdk.es19.js +1 -1
- package/dist/es/standards-sdk.es2.js +1 -1
- package/dist/es/standards-sdk.es20.js +2 -2
- package/dist/es/standards-sdk.es23.js +2 -2
- package/dist/es/standards-sdk.es25.js +4 -2
- package/dist/es/standards-sdk.es25.js.map +1 -1
- package/dist/es/standards-sdk.es26.js +2 -2
- package/dist/es/standards-sdk.es27.js +152 -6
- package/dist/es/standards-sdk.es27.js.map +1 -1
- package/dist/es/standards-sdk.es28.js +26 -189
- package/dist/es/standards-sdk.es28.js.map +1 -1
- package/dist/es/standards-sdk.es29.js +446 -26
- package/dist/es/standards-sdk.es29.js.map +1 -1
- package/dist/es/standards-sdk.es3.js +1 -1
- package/dist/es/standards-sdk.es3.js.map +1 -1
- package/dist/es/standards-sdk.es30.js +6 -342
- package/dist/es/standards-sdk.es30.js.map +1 -1
- package/dist/es/standards-sdk.es31.js +202 -6
- package/dist/es/standards-sdk.es31.js.map +1 -1
- package/dist/es/standards-sdk.es32.js +34 -202
- package/dist/es/standards-sdk.es32.js.map +1 -1
- package/dist/es/standards-sdk.es33.js +529 -34
- package/dist/es/standards-sdk.es33.js.map +1 -1
- package/dist/es/standards-sdk.es34.js +87 -501
- package/dist/es/standards-sdk.es34.js.map +1 -1
- package/dist/es/standards-sdk.es35.js +19 -98
- package/dist/es/standards-sdk.es35.js.map +1 -1
- package/dist/es/standards-sdk.es36.js +156 -18
- package/dist/es/standards-sdk.es36.js.map +1 -1
- package/dist/es/standards-sdk.es37.js +146 -150
- package/dist/es/standards-sdk.es37.js.map +1 -1
- package/dist/es/standards-sdk.es38.js +561 -134
- package/dist/es/standards-sdk.es38.js.map +1 -1
- package/dist/es/standards-sdk.es39.js +562 -543
- package/dist/es/standards-sdk.es39.js.map +1 -1
- package/dist/es/standards-sdk.es4.js +6 -4
- package/dist/es/standards-sdk.es4.js.map +1 -1
- package/dist/es/standards-sdk.es40.js +4 -601
- package/dist/es/standards-sdk.es40.js.map +1 -1
- package/dist/es/standards-sdk.es41.js +415 -4
- package/dist/es/standards-sdk.es41.js.map +1 -1
- package/dist/es/standards-sdk.es42.js +1536 -389
- package/dist/es/standards-sdk.es42.js.map +1 -1
- package/dist/es/standards-sdk.es43.js +133 -1541
- package/dist/es/standards-sdk.es43.js.map +1 -1
- package/dist/es/standards-sdk.es44.js +7 -155
- package/dist/es/standards-sdk.es44.js.map +1 -1
- package/dist/es/standards-sdk.es45.js +2 -7
- package/dist/es/standards-sdk.es45.js.map +1 -1
- package/dist/es/standards-sdk.es46.js +5 -5
- package/dist/es/standards-sdk.es48.js +1 -1
- package/dist/es/standards-sdk.es49.js +1 -1
- package/dist/es/standards-sdk.es5.js +4 -6
- package/dist/es/standards-sdk.es5.js.map +1 -1
- package/dist/es/standards-sdk.es50.js +1 -1
- package/dist/es/standards-sdk.es51.js +1 -1
- package/dist/es/standards-sdk.es52.js +1 -1
- package/dist/es/standards-sdk.es54.js +7135 -2
- package/dist/es/standards-sdk.es54.js.map +1 -1
- package/dist/es/standards-sdk.es55.js +7134 -41
- package/dist/es/standards-sdk.es55.js.map +1 -1
- package/dist/es/standards-sdk.es56.js +37 -37
- package/dist/es/standards-sdk.es56.js.map +1 -1
- package/dist/es/standards-sdk.es57.js +37 -37
- package/dist/es/standards-sdk.es57.js.map +1 -1
- package/dist/es/standards-sdk.es58.js +78 -72
- package/dist/es/standards-sdk.es58.js.map +1 -1
- package/dist/es/standards-sdk.es59.js +41 -7134
- package/dist/es/standards-sdk.es59.js.map +1 -1
- package/dist/es/standards-sdk.es6.js.map +1 -1
- package/dist/es/standards-sdk.es7.js +28 -22
- package/dist/es/standards-sdk.es7.js.map +1 -1
- package/dist/es/standards-sdk.es8.js +5 -5
- package/dist/es/utils/logger.d.ts.map +1 -1
- package/package.json +37 -35
- package/dist/cjs/hcs-21/index.d.ts +0 -4
- package/dist/cjs/hcs-21/index.d.ts.map +0 -1
- package/dist/cjs/hcs-21/petal-account-manager.d.ts +0 -52
- package/dist/cjs/hcs-21/petal-account-manager.d.ts.map +0 -1
- package/dist/cjs/hcs-21/types.d.ts +0 -44
- package/dist/cjs/hcs-21/types.d.ts.map +0 -1
- package/dist/cjs/index-xZmk-HBD.cjs.map +0 -1
- package/dist/es/hcs-21/index.d.ts +0 -4
- package/dist/es/hcs-21/index.d.ts.map +0 -1
- package/dist/es/hcs-21/petal-account-manager.d.ts +0 -52
- package/dist/es/hcs-21/petal-account-manager.d.ts.map +0 -1
- package/dist/es/hcs-21/types.d.ts +0 -44
- package/dist/es/hcs-21/types.d.ts.map +0 -1
- package/dist/es/standards-sdk.es60.js +0 -7144
- package/dist/es/standards-sdk.es60.js.map +0 -1
|
@@ -1,11 +1,157 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { PrivateKey, AccountCreateTransaction, Hbar } from "@hashgraph/sdk";
|
|
2
|
+
import { Logger } from "./standards-sdk.es34.js";
|
|
3
|
+
import { HCS11Client } from "./standards-sdk.es15.js";
|
|
4
|
+
import { HCS10Client } from "./standards-sdk.es7.js";
|
|
5
|
+
import { AgentBuilder } from "./standards-sdk.es11.js";
|
|
6
|
+
import { PersonBuilder } from "./standards-sdk.es12.js";
|
|
7
|
+
import { MCPServerBuilder } from "./standards-sdk.es13.js";
|
|
8
|
+
import { HederaMirrorNode } from "./standards-sdk.es42.js";
|
|
9
|
+
class HCS15PetalManager {
|
|
10
|
+
constructor(client, logger) {
|
|
11
|
+
this.client = client;
|
|
12
|
+
this.logger = logger || new Logger({ module: "HCS15PetalManager", level: "debug" });
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new Petal account using a builder for ultimate flexibility
|
|
16
|
+
*/
|
|
17
|
+
async createPetal(builder, options) {
|
|
18
|
+
this.logger.info("Creating Petal account with builder", {
|
|
19
|
+
baseAccount: options.baseAccountId
|
|
20
|
+
});
|
|
21
|
+
const basePrivateKey = PrivateKey.fromStringECDSA(options.basePrivateKey);
|
|
22
|
+
const sharedPublicKey = basePrivateKey.publicKey;
|
|
23
|
+
const accountTx = new AccountCreateTransaction().setKeyWithoutAlias(sharedPublicKey).setInitialBalance(new Hbar(options.initialBalance || 1));
|
|
24
|
+
if (options.maxAutomaticTokenAssociations !== void 0) {
|
|
25
|
+
accountTx.setMaxAutomaticTokenAssociations(
|
|
26
|
+
options.maxAutomaticTokenAssociations
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
const txResponse = await accountTx.execute(this.client);
|
|
30
|
+
const receipt = await txResponse.getReceipt(this.client);
|
|
31
|
+
const petalAccountId = receipt.accountId;
|
|
32
|
+
this.logger.info(`Petal account created: ${petalAccountId}`);
|
|
33
|
+
const network = this.client.ledgerId?.toString().includes("testnet") ? "testnet" : "mainnet";
|
|
34
|
+
const petalHcs10Client = new HCS10Client({
|
|
35
|
+
network,
|
|
36
|
+
operatorId: options.baseAccountId,
|
|
37
|
+
operatorPrivateKey: options.basePrivateKey,
|
|
38
|
+
keyType: "ecdsa"
|
|
39
|
+
});
|
|
40
|
+
if (builder instanceof AgentBuilder) {
|
|
41
|
+
builder.setBaseAccount(options.baseAccountId).setNetwork(network);
|
|
42
|
+
const result = await petalHcs10Client.createAgent(
|
|
43
|
+
builder,
|
|
44
|
+
options.ttl || 60
|
|
45
|
+
);
|
|
46
|
+
return {
|
|
47
|
+
petalAccount: {
|
|
48
|
+
accountId: petalAccountId,
|
|
49
|
+
baseAccountId: options.baseAccountId,
|
|
50
|
+
privateKey: basePrivateKey,
|
|
51
|
+
publicKey: sharedPublicKey,
|
|
52
|
+
profileTopicId: result.profileTopicId,
|
|
53
|
+
inboundTopicId: result.inboundTopicId,
|
|
54
|
+
outboundTopicId: result.outboundTopicId
|
|
55
|
+
},
|
|
56
|
+
transactionId: txResponse.transactionId.toString(),
|
|
57
|
+
profileTopicId: result.profileTopicId
|
|
58
|
+
};
|
|
59
|
+
} else if (builder instanceof MCPServerBuilder) {
|
|
60
|
+
builder.setNetworkType(network);
|
|
61
|
+
const result = await petalHcs10Client.createMCPServer(
|
|
62
|
+
builder,
|
|
63
|
+
options.ttl || 60
|
|
64
|
+
);
|
|
65
|
+
return {
|
|
66
|
+
petalAccount: {
|
|
67
|
+
accountId: petalAccountId,
|
|
68
|
+
baseAccountId: options.baseAccountId,
|
|
69
|
+
privateKey: basePrivateKey,
|
|
70
|
+
publicKey: sharedPublicKey,
|
|
71
|
+
profileTopicId: result.profileTopicId,
|
|
72
|
+
inboundTopicId: result.inboundTopicId,
|
|
73
|
+
outboundTopicId: result.outboundTopicId
|
|
74
|
+
},
|
|
75
|
+
transactionId: txResponse.transactionId.toString(),
|
|
76
|
+
profileTopicId: result.profileTopicId
|
|
77
|
+
};
|
|
78
|
+
} else if (builder instanceof PersonBuilder) {
|
|
79
|
+
const hcs11Client = new HCS11Client({
|
|
80
|
+
network,
|
|
81
|
+
auth: {
|
|
82
|
+
operatorId: petalAccountId.toString(),
|
|
83
|
+
privateKey: options.basePrivateKey
|
|
84
|
+
},
|
|
85
|
+
keyType: "ecdsa"
|
|
86
|
+
});
|
|
87
|
+
const profile = builder.build();
|
|
88
|
+
profile.base_account = options.baseAccountId;
|
|
89
|
+
const inscriptionResult = await hcs11Client.createAndInscribeProfile(
|
|
90
|
+
profile,
|
|
91
|
+
true
|
|
92
|
+
);
|
|
93
|
+
return {
|
|
94
|
+
petalAccount: {
|
|
95
|
+
accountId: petalAccountId,
|
|
96
|
+
baseAccountId: options.baseAccountId,
|
|
97
|
+
privateKey: basePrivateKey,
|
|
98
|
+
publicKey: sharedPublicKey,
|
|
99
|
+
profileTopicId: inscriptionResult.profileTopicId,
|
|
100
|
+
inboundTopicId: inscriptionResult.inboundTopicId,
|
|
101
|
+
outboundTopicId: inscriptionResult.outboundTopicId
|
|
102
|
+
},
|
|
103
|
+
transactionId: txResponse.transactionId.toString(),
|
|
104
|
+
profileTopicId: inscriptionResult.profileTopicId
|
|
105
|
+
};
|
|
106
|
+
} else {
|
|
107
|
+
throw new Error("Unsupported builder type");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Creates a base account with ECDSA key and EVM alias
|
|
112
|
+
*/
|
|
113
|
+
async createBaseAccount(initialBalance = 10) {
|
|
114
|
+
this.logger.info("Creating base account with ECDSA key and EVM alias");
|
|
115
|
+
const privateKey = PrivateKey.generateECDSA();
|
|
116
|
+
const privateKeyHex = privateKey.toStringRaw();
|
|
117
|
+
const publicKey = privateKey.publicKey;
|
|
118
|
+
const evmAddress = publicKey.toEvmAddress();
|
|
119
|
+
const accountTx = await new AccountCreateTransaction().setECDSAKeyWithAlias(publicKey).setInitialBalance(new Hbar(initialBalance)).execute(this.client);
|
|
120
|
+
const receipt = await accountTx.getReceipt(this.client);
|
|
121
|
+
const accountId = receipt.accountId;
|
|
122
|
+
this.logger.info(`Base account created: ${accountId}`);
|
|
123
|
+
this.logger.info(`EVM address: 0x${evmAddress}`);
|
|
124
|
+
return {
|
|
125
|
+
accountId,
|
|
126
|
+
privateKey,
|
|
127
|
+
privateKeyHex,
|
|
128
|
+
publicKey,
|
|
129
|
+
evmAddress: `0x${evmAddress}`
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Verifies that a Petal account is valid
|
|
134
|
+
*/
|
|
135
|
+
async verifyPetalAccount(petalAccountId, baseAccountId) {
|
|
136
|
+
try {
|
|
137
|
+
const mirrorNode = new HederaMirrorNode(
|
|
138
|
+
this.client.network?.toString()
|
|
139
|
+
);
|
|
140
|
+
const accountInfo = await mirrorNode.requestAccount(petalAccountId);
|
|
141
|
+
const petalKey = accountInfo.key?.key;
|
|
142
|
+
const baseAccountInfo = await mirrorNode.requestAccount(baseAccountId);
|
|
143
|
+
if (!baseAccountInfo) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
const baseKey = baseAccountInfo?.key?.key;
|
|
147
|
+
return petalKey === baseKey;
|
|
148
|
+
} catch (error) {
|
|
149
|
+
this.logger.error("Error verifying petal account:", error);
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
6
152
|
}
|
|
7
153
|
}
|
|
8
154
|
export {
|
|
9
|
-
|
|
155
|
+
HCS15PetalManager
|
|
10
156
|
};
|
|
11
157
|
//# sourceMappingURL=standards-sdk.es27.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es27.js","sources":["../../src/hcs-21/types.ts"],"sourcesContent":["import { AccountId, PublicKey, PrivateKey } from '@hashgraph/sdk';\n\n/**\n * HCS-21 Petal Account configuration\n */\nexport interface PetalAccountConfig {\n sharedPrivateKey: PrivateKey;\n initialBalance?: number;\n maxAutomaticTokenAssociations?: number;\n memo?: string;\n}\n\n/**\n * HCS-21 Petal Account creation result\n */\nexport interface PetalAccountResult {\n accountId: AccountId;\n publicKey: PublicKey;\n evmAddress?: string;\n transactionId: string;\n}\n\n/**\n * HCS-21 Profile reference in account memo\n */\nexport interface PetalProfileReference {\n protocol: 'hcs-11';\n resourceLocator: string;\n baseAccount?: string;\n}\n\n/**\n * HCS-21 Petal relationship\n */\nexport interface PetalRelationship {\n petalAccountId: string;\n baseAccountId: string;\n sharedPublicKey: PublicKey;\n profileTopicId?: string;\n}\n\n/**\n * HCS-21 errors\n */\nexport class PetalAccountError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n ) {\n super(message);\n this.name = 'PetalAccountError';\n }\n}\n"],"names":[],"mappings":"AA4CO,MAAM,0BAA0B,MAAM;AAAA,EAC3C,YACE,SACgB,MAChB;AACA,UAAM,OAAO;AAFG,SAAA,OAAA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;"}
|
|
1
|
+
{"version":3,"file":"standards-sdk.es27.js","sources":["../../src/hcs-15/petal-manager.ts"],"sourcesContent":["/**\n * HCS-15 Petal Account Manager\n *\n * Manages creation and management of Petal (shadow) accounts that share\n * the same private key as the base account.\n */\n\nimport {\n Client,\n AccountCreateTransaction,\n PrivateKey,\n PublicKey,\n AccountId,\n Hbar,\n} from '@hashgraph/sdk';\nimport { Logger } from '../utils/logger';\nimport { HCS11Client } from '../hcs-11/client';\nimport { HCS10Client } from '../hcs-10/sdk';\nimport { AgentBuilder } from '../hcs-11/agent-builder';\nimport { PersonBuilder } from '../hcs-11/person-builder';\nimport { MCPServerBuilder } from '../hcs-11/mcp-server-builder';\nimport { FloraBuilder } from '../hcs-11/flora-builder';\nimport type { NetworkType } from '../utils/types';\nimport {\n PetalConfig,\n PetalAccount,\n PetalCreationResult,\n PetalProfile,\n ProfileBuilder,\n PetalCreationOptions,\n} from './types';\nimport {\n AIAgentProfile,\n PersonalProfile,\n MCPServerProfile,\n InboundTopicType,\n ProfileType,\n} from '../hcs-11/types';\nimport { FloraProfile } from '../hcs-16/types';\nimport { HederaMirrorNode } from '../services';\nimport { detectKeyTypeFromString } from '../utils/key-type-detector';\n\nexport class HCS15PetalManager {\n private client: Client;\n private logger: Logger;\n\n constructor(client: Client, logger?: Logger) {\n this.client = client;\n this.logger =\n logger || new Logger({ module: 'HCS15PetalManager', level: 'debug' });\n }\n\n /**\n * Creates a new Petal account using a builder for ultimate flexibility\n */\n async createPetal(\n builder: ProfileBuilder,\n options: PetalCreationOptions,\n ): Promise<PetalCreationResult> {\n this.logger.info('Creating Petal account with builder', {\n baseAccount: options.baseAccountId,\n });\n\n // Create the Petal account\n const basePrivateKey = PrivateKey.fromStringECDSA(options.basePrivateKey);\n const sharedPublicKey = basePrivateKey.publicKey;\n\n const accountTx = new AccountCreateTransaction()\n .setKeyWithoutAlias(sharedPublicKey)\n .setInitialBalance(new Hbar(options.initialBalance || 1));\n\n if (options.maxAutomaticTokenAssociations !== undefined) {\n accountTx.setMaxAutomaticTokenAssociations(\n options.maxAutomaticTokenAssociations,\n );\n }\n\n const txResponse = await accountTx.execute(this.client);\n const receipt = await txResponse.getReceipt(this.client);\n const petalAccountId = receipt.accountId!;\n\n this.logger.info(`Petal account created: ${petalAccountId}`);\n\n const network: NetworkType = this.client.ledgerId\n ?.toString()\n .includes('testnet')\n ? 'testnet'\n : 'mainnet';\n\n const petalHcs10Client = new HCS10Client({\n network,\n operatorId: options.baseAccountId,\n operatorPrivateKey: options.basePrivateKey,\n keyType: 'ecdsa',\n });\n\n if (builder instanceof AgentBuilder) {\n builder.setBaseAccount(options.baseAccountId).setNetwork(network);\n\n const result = await petalHcs10Client.createAgent(\n builder,\n options.ttl || 60,\n );\n\n return {\n petalAccount: {\n accountId: petalAccountId,\n baseAccountId: options.baseAccountId,\n privateKey: basePrivateKey,\n publicKey: sharedPublicKey,\n profileTopicId: result.profileTopicId,\n inboundTopicId: result.inboundTopicId,\n outboundTopicId: result.outboundTopicId,\n },\n transactionId: txResponse.transactionId.toString(),\n profileTopicId: result.profileTopicId,\n };\n } else if (builder instanceof MCPServerBuilder) {\n builder.setNetworkType(network);\n\n const result = await petalHcs10Client.createMCPServer(\n builder,\n options.ttl || 60,\n );\n\n return {\n petalAccount: {\n accountId: petalAccountId,\n baseAccountId: options.baseAccountId,\n privateKey: basePrivateKey,\n publicKey: sharedPublicKey,\n profileTopicId: result.profileTopicId,\n inboundTopicId: result.inboundTopicId,\n outboundTopicId: result.outboundTopicId,\n },\n transactionId: txResponse.transactionId.toString(),\n profileTopicId: result.profileTopicId,\n };\n } else if (builder instanceof PersonBuilder) {\n // PersonBuilder doesn't have setExistingAccount, use HCS11Client directly\n const hcs11Client = new HCS11Client({\n network,\n auth: {\n operatorId: petalAccountId.toString(),\n privateKey: options.basePrivateKey,\n },\n keyType: 'ecdsa',\n });\n\n const profile = builder.build() as PersonalProfile & {\n base_account?: string;\n };\n profile.base_account = options.baseAccountId;\n\n const inscriptionResult = await hcs11Client.createAndInscribeProfile(\n profile as PersonalProfile,\n true,\n );\n\n return {\n petalAccount: {\n accountId: petalAccountId,\n baseAccountId: options.baseAccountId,\n privateKey: basePrivateKey,\n publicKey: sharedPublicKey,\n profileTopicId: inscriptionResult.profileTopicId,\n inboundTopicId: inscriptionResult.inboundTopicId,\n outboundTopicId: inscriptionResult.outboundTopicId,\n },\n transactionId: txResponse.transactionId.toString(),\n profileTopicId: inscriptionResult.profileTopicId,\n };\n } else {\n throw new Error('Unsupported builder type');\n }\n }\n\n\n /**\n * Creates a base account with ECDSA key and EVM alias\n */\n async createBaseAccount(initialBalance: number = 10): Promise<{\n accountId: AccountId;\n privateKey: PrivateKey;\n privateKeyHex: string;\n publicKey: PublicKey;\n evmAddress: string;\n }> {\n this.logger.info('Creating base account with ECDSA key and EVM alias');\n\n const privateKey = PrivateKey.generateECDSA();\n const privateKeyHex = privateKey.toStringRaw();\n const publicKey = privateKey.publicKey;\n const evmAddress = publicKey.toEvmAddress();\n\n const accountTx = await new AccountCreateTransaction()\n .setECDSAKeyWithAlias(publicKey)\n .setInitialBalance(new Hbar(initialBalance))\n .execute(this.client);\n\n const receipt = await accountTx.getReceipt(this.client);\n const accountId = receipt.accountId!;\n\n this.logger.info(`Base account created: ${accountId}`);\n this.logger.info(`EVM address: 0x${evmAddress}`);\n\n return {\n accountId,\n privateKey,\n privateKeyHex,\n publicKey,\n evmAddress: `0x${evmAddress}`,\n };\n }\n\n /**\n * Verifies that a Petal account is valid\n */\n async verifyPetalAccount(\n petalAccountId: string,\n baseAccountId: string,\n ): Promise<boolean> {\n try {\n const mirrorNode = new HederaMirrorNode(\n this.client.network?.toString() as NetworkType,\n );\n\n const accountInfo = await mirrorNode.requestAccount(petalAccountId);\n\n const petalKey = accountInfo.key?.key;\n\n const baseAccountInfo = await mirrorNode.requestAccount(baseAccountId);\n\n if (!baseAccountInfo) {\n return false;\n }\n\n const baseKey = baseAccountInfo?.key?.key;\n\n return petalKey === baseKey;\n } catch (error) {\n this.logger.error('Error verifying petal account:', error);\n return false;\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;AA0CO,MAAM,kBAAkB;AAAA,EAI7B,YAAY,QAAgB,QAAiB;AA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
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!receipt.accountId) {
|
|
25
|
-
throw new PetalAccountError(
|
|
26
|
-
"Failed to create base account - no account ID in receipt",
|
|
27
|
-
"CREATE_FAILED"
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
this.logger.info("Base account created", {
|
|
31
|
-
accountId: receipt.accountId.toString(),
|
|
32
|
-
evmAddress
|
|
33
|
-
});
|
|
34
|
-
return {
|
|
35
|
-
accountId: receipt.accountId,
|
|
36
|
-
publicKey,
|
|
37
|
-
evmAddress,
|
|
38
|
-
transactionId: response.transactionId.toString(),
|
|
39
|
-
privateKey
|
|
40
|
-
};
|
|
41
|
-
} catch (error) {
|
|
42
|
-
this.logger.error("Failed to create base account", {
|
|
43
|
-
error: error instanceof Error ? error.message : error,
|
|
44
|
-
stack: error instanceof Error ? error.stack : void 0
|
|
45
|
-
});
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Create a petal account using the same key as the base account
|
|
51
|
-
*/
|
|
52
|
-
async createPetalAccount(config) {
|
|
53
|
-
try {
|
|
54
|
-
this.logger.info("Creating petal account with shared key");
|
|
55
|
-
const publicKey = config.sharedPrivateKey.publicKey;
|
|
56
|
-
const transaction = new AccountCreateTransaction().setKey(publicKey).setInitialBalance(new Hbar(config.initialBalance || 1)).setMaxAutomaticTokenAssociations(
|
|
57
|
-
config.maxAutomaticTokenAssociations || -1
|
|
58
|
-
);
|
|
59
|
-
if (config.memo) {
|
|
60
|
-
transaction.setAccountMemo(config.memo);
|
|
61
|
-
}
|
|
62
|
-
const response = await transaction.execute(this.client);
|
|
63
|
-
const receipt = await response.getReceipt(this.client);
|
|
64
|
-
if (!receipt.accountId) {
|
|
65
|
-
throw new PetalAccountError(
|
|
66
|
-
"Failed to create petal account - no account ID in receipt",
|
|
67
|
-
"CREATE_FAILED"
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
this.logger.info("Petal account created", {
|
|
71
|
-
accountId: receipt.accountId.toString(),
|
|
72
|
-
publicKey: publicKey.toString()
|
|
73
|
-
});
|
|
74
|
-
return {
|
|
75
|
-
accountId: receipt.accountId,
|
|
76
|
-
publicKey,
|
|
77
|
-
transactionId: response.transactionId.toString()
|
|
78
|
-
};
|
|
79
|
-
} catch (error) {
|
|
80
|
-
this.logger.error("Failed to create petal account", error);
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Update account memo with HCS-11 profile reference
|
|
86
|
-
* Format: hcs-11:<protocol_reference>
|
|
87
|
-
*/
|
|
88
|
-
async updateAccountMemo(accountId, profileReference) {
|
|
89
|
-
try {
|
|
90
|
-
const memo = `hcs-11:${profileReference}`;
|
|
91
|
-
this.logger.info("Updating account memo", {
|
|
92
|
-
accountId: accountId.toString(),
|
|
93
|
-
memo
|
|
94
|
-
});
|
|
95
|
-
const transaction = new AccountUpdateTransaction().setAccountId(accountId).setAccountMemo(memo);
|
|
96
|
-
const response = await transaction.execute(this.client);
|
|
97
|
-
await response.getReceipt(this.client);
|
|
98
|
-
this.logger.info("Account memo updated successfully");
|
|
99
|
-
} catch (error) {
|
|
100
|
-
this.logger.error("Failed to update account memo", error);
|
|
101
|
-
throw error;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Parse HCS-11 profile reference from account memo
|
|
106
|
-
*/
|
|
107
|
-
parseProfileReference(memo) {
|
|
108
|
-
const match = memo.match(/^hcs-11:(.+)$/);
|
|
109
|
-
if (!match) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
const resourceLocator = match[1];
|
|
113
|
-
const hrlMatch = resourceLocator.match(/hcs:\/\/\d+\/([0-9.]+)/);
|
|
114
|
-
return {
|
|
115
|
-
protocol: "hcs-11",
|
|
116
|
-
resourceLocator,
|
|
117
|
-
baseAccount: hrlMatch ? hrlMatch[1] : void 0
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Create multiple petal accounts from a single base account
|
|
122
|
-
*/
|
|
123
|
-
async createPetalBouquet(basePrivateKey, count, config) {
|
|
124
|
-
const results = [];
|
|
125
|
-
for (let i = 0; i < count; i++) {
|
|
126
|
-
const memo = config?.memoPrefix ? `${config.memoPrefix}-${i + 1}` : void 0;
|
|
127
|
-
const petal = await this.createPetalAccount({
|
|
128
|
-
sharedPrivateKey: basePrivateKey,
|
|
129
|
-
initialBalance: config?.initialBalance,
|
|
130
|
-
maxAutomaticTokenAssociations: config?.maxAutomaticTokenAssociations,
|
|
131
|
-
memo
|
|
132
|
-
});
|
|
133
|
-
results.push(petal);
|
|
134
|
-
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
135
|
-
}
|
|
136
|
-
return results;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Verify that two accounts share the same public key
|
|
140
|
-
*/
|
|
141
|
-
async verifySharedKey(accountId1, accountId2) {
|
|
142
|
-
try {
|
|
143
|
-
const [info1, info2] = await Promise.all([
|
|
144
|
-
new AccountInfoQuery().setAccountId(accountId1).execute(this.client),
|
|
145
|
-
new AccountInfoQuery().setAccountId(accountId2).execute(this.client)
|
|
146
|
-
]);
|
|
147
|
-
const key1 = info1.key;
|
|
148
|
-
const key2 = info2.key;
|
|
149
|
-
return key1.toString() === key2.toString();
|
|
150
|
-
} catch (error) {
|
|
151
|
-
this.logger.error("Failed to verify shared keys", error);
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Get all petal relationships for a given public key
|
|
157
|
-
*/
|
|
158
|
-
async findPetalsByPublicKey(publicKey, knownAccountIds) {
|
|
159
|
-
const relationships = [];
|
|
160
|
-
let baseAccountId;
|
|
161
|
-
for (const accountId of knownAccountIds) {
|
|
162
|
-
try {
|
|
163
|
-
const info = await new AccountInfoQuery().setAccountId(accountId).execute(this.client);
|
|
164
|
-
if (info.key.toString() === publicKey.toString()) {
|
|
165
|
-
const hasEvmAlias = info.contractAccountId !== null;
|
|
166
|
-
if (hasEvmAlias && !baseAccountId) {
|
|
167
|
-
baseAccountId = accountId;
|
|
168
|
-
}
|
|
169
|
-
const profileRef = info.accountMemo ? this.parseProfileReference(info.accountMemo) : null;
|
|
170
|
-
relationships.push({
|
|
171
|
-
petalAccountId: accountId,
|
|
172
|
-
baseAccountId: baseAccountId || accountId,
|
|
173
|
-
sharedPublicKey: publicKey,
|
|
174
|
-
profileTopicId: profileRef?.resourceLocator
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
} catch (error) {
|
|
178
|
-
this.logger.warn(`Failed to check account ${accountId}`, error);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
if (baseAccountId) {
|
|
182
|
-
relationships.forEach((rel) => {
|
|
183
|
-
if (!rel.baseAccountId || rel.baseAccountId === rel.petalAccountId) {
|
|
184
|
-
rel.baseAccountId = baseAccountId;
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
return relationships;
|
|
1
|
+
var FloraTopicType = /* @__PURE__ */ ((FloraTopicType2) => {
|
|
2
|
+
FloraTopicType2[FloraTopicType2["COMMUNICATION"] = 0] = "COMMUNICATION";
|
|
3
|
+
FloraTopicType2[FloraTopicType2["TRANSACTION"] = 1] = "TRANSACTION";
|
|
4
|
+
FloraTopicType2[FloraTopicType2["STATE"] = 2] = "STATE";
|
|
5
|
+
return FloraTopicType2;
|
|
6
|
+
})(FloraTopicType || {});
|
|
7
|
+
var FloraOperation = /* @__PURE__ */ ((FloraOperation2) => {
|
|
8
|
+
FloraOperation2["FLORA_CREATE_REQUEST"] = "flora_create_request";
|
|
9
|
+
FloraOperation2["FLORA_CREATE_ACCEPTED"] = "flora_create_accepted";
|
|
10
|
+
FloraOperation2["FLORA_CREATED"] = "flora_created";
|
|
11
|
+
FloraOperation2["TX_PROPOSAL"] = "tx_proposal";
|
|
12
|
+
FloraOperation2["STATE_UPDATE"] = "state_update";
|
|
13
|
+
FloraOperation2["FLORA_JOIN_REQUEST"] = "flora_join_request";
|
|
14
|
+
FloraOperation2["FLORA_JOIN_VOTE"] = "flora_join_vote";
|
|
15
|
+
FloraOperation2["FLORA_JOIN_ACCEPTED"] = "flora_join_accepted";
|
|
16
|
+
FloraOperation2["CREDIT_PURCHASE"] = "credit_purchase";
|
|
17
|
+
return FloraOperation2;
|
|
18
|
+
})(FloraOperation || {});
|
|
19
|
+
class FloraError extends Error {
|
|
20
|
+
constructor(message, code) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.name = "FloraError";
|
|
189
24
|
}
|
|
190
25
|
}
|
|
191
26
|
export {
|
|
192
|
-
|
|
27
|
+
FloraError,
|
|
28
|
+
FloraOperation,
|
|
29
|
+
FloraTopicType
|
|
193
30
|
};
|
|
194
31
|
//# sourceMappingURL=standards-sdk.es28.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es28.js","sources":["../../src/hcs-21/petal-account-manager.ts"],"sourcesContent":["import {\n Client,\n AccountCreateTransaction,\n AccountUpdateTransaction,\n AccountInfoQuery,\n PrivateKey,\n PublicKey,\n Hbar,\n AccountId,\n TransactionReceipt,\n} from '@hashgraph/sdk';\nimport { Logger } from '../utils/logger';\nimport {\n PetalAccountConfig,\n PetalAccountResult,\n PetalProfileReference,\n PetalRelationship,\n PetalAccountError,\n} from './types';\n\n/**\n * HCS-21 Petal Account Manager\n * Manages creation and management of Petal accounts that share keys with base accounts\n */\nexport class PetalAccountManager {\n private readonly logger: Logger;\n\n constructor(\n private readonly client: Client,\n logger?: Logger,\n ) {\n this.logger = logger || new Logger({ module: 'PetalAccountManager' });\n }\n\n /**\n * Create a base account with ECDSA key and EVM alias\n * This is the recommended approach for the initial account\n */\n async createBaseAccount(config: {\n initialBalance?: number;\n maxAutomaticTokenAssociations?: number;\n }): Promise<PetalAccountResult & { privateKey: PrivateKey }> {\n try {\n this.logger.info('Creating base account with ECDSA key and EVM alias');\n\n const privateKey = PrivateKey.generateECDSA();\n const publicKey = privateKey.publicKey;\n const evmAddress = publicKey.toEvmAddress();\n const transaction = new AccountCreateTransaction()\n .setKey(publicKey)\n .setAlias(evmAddress)\n .setInitialBalance(new Hbar(config.initialBalance || 10))\n .setMaxAutomaticTokenAssociations(\n config.maxAutomaticTokenAssociations || 10,\n );\n\n const response = await transaction.execute(this.client);\n const receipt = await response.getReceipt(this.client);\n\n if (!receipt.accountId) {\n throw new PetalAccountError(\n 'Failed to create base account - no account ID in receipt',\n 'CREATE_FAILED',\n );\n }\n\n this.logger.info('Base account created', {\n accountId: receipt.accountId.toString(),\n evmAddress,\n });\n\n return {\n accountId: receipt.accountId,\n publicKey,\n evmAddress,\n transactionId: response.transactionId.toString(),\n privateKey,\n };\n } catch (error) {\n this.logger.error('Failed to create base account', {\n error: error instanceof Error ? error.message : error,\n stack: error instanceof Error ? error.stack : undefined,\n });\n throw error;\n }\n }\n\n /**\n * Create a petal account using the same key as the base account\n */\n async createPetalAccount(\n config: PetalAccountConfig,\n ): Promise<PetalAccountResult> {\n try {\n this.logger.info('Creating petal account with shared key');\n\n const publicKey = config.sharedPrivateKey.publicKey;\n\n const transaction = new AccountCreateTransaction()\n .setKey(publicKey)\n .setInitialBalance(new Hbar(config.initialBalance || 1))\n .setMaxAutomaticTokenAssociations(\n config.maxAutomaticTokenAssociations || -1,\n );\n\n if (config.memo) {\n transaction.setAccountMemo(config.memo);\n }\n\n const response = await transaction.execute(this.client);\n const receipt = await response.getReceipt(this.client);\n\n if (!receipt.accountId) {\n throw new PetalAccountError(\n 'Failed to create petal account - no account ID in receipt',\n 'CREATE_FAILED',\n );\n }\n\n this.logger.info('Petal account created', {\n accountId: receipt.accountId.toString(),\n publicKey: publicKey.toString(),\n });\n\n return {\n accountId: receipt.accountId,\n publicKey,\n transactionId: response.transactionId.toString(),\n };\n } catch (error) {\n this.logger.error('Failed to create petal account', error);\n throw error;\n }\n }\n\n /**\n * Update account memo with HCS-11 profile reference\n * Format: hcs-11:<protocol_reference>\n */\n async updateAccountMemo(\n accountId: string | AccountId,\n profileReference: string,\n ): Promise<void> {\n try {\n const memo = `hcs-11:${profileReference}`;\n\n this.logger.info('Updating account memo', {\n accountId: accountId.toString(),\n memo,\n });\n\n const transaction = new AccountUpdateTransaction()\n .setAccountId(accountId)\n .setAccountMemo(memo);\n\n const response = await transaction.execute(this.client);\n await response.getReceipt(this.client);\n\n this.logger.info('Account memo updated successfully');\n } catch (error) {\n this.logger.error('Failed to update account memo', error);\n throw error;\n }\n }\n\n /**\n * Parse HCS-11 profile reference from account memo\n */\n parseProfileReference(memo: string): PetalProfileReference | null {\n const match = memo.match(/^hcs-11:(.+)$/);\n if (!match) {\n return null;\n }\n\n const resourceLocator = match[1];\n\n const hrlMatch = resourceLocator.match(/hcs:\\/\\/\\d+\\/([0-9.]+)/);\n\n return {\n protocol: 'hcs-11',\n resourceLocator,\n baseAccount: hrlMatch ? hrlMatch[1] : undefined,\n };\n }\n\n /**\n * Create multiple petal accounts from a single base account\n */\n async createPetalBouquet(\n basePrivateKey: PrivateKey,\n count: number,\n config?: {\n initialBalance?: number;\n maxAutomaticTokenAssociations?: number;\n memoPrefix?: string;\n },\n ): Promise<PetalAccountResult[]> {\n const results: PetalAccountResult[] = [];\n\n for (let i = 0; i < count; i++) {\n const memo = config?.memoPrefix\n ? `${config.memoPrefix}-${i + 1}`\n : undefined;\n\n const petal = await this.createPetalAccount({\n sharedPrivateKey: basePrivateKey,\n initialBalance: config?.initialBalance,\n maxAutomaticTokenAssociations: config?.maxAutomaticTokenAssociations,\n memo,\n });\n\n results.push(petal);\n\n await new Promise(resolve => setTimeout(resolve, 1000));\n }\n\n return results;\n }\n\n /**\n * Verify that two accounts share the same public key\n */\n async verifySharedKey(\n accountId1: string | AccountId,\n accountId2: string | AccountId,\n ): Promise<boolean> {\n try {\n const [info1, info2] = await Promise.all([\n new AccountInfoQuery().setAccountId(accountId1).execute(this.client),\n new AccountInfoQuery().setAccountId(accountId2).execute(this.client),\n ]);\n\n const key1 = info1.key;\n const key2 = info2.key;\n\n return key1.toString() === key2.toString();\n } catch (error) {\n this.logger.error('Failed to verify shared keys', error);\n return false;\n }\n }\n\n /**\n * Get all petal relationships for a given public key\n */\n async findPetalsByPublicKey(\n publicKey: PublicKey,\n knownAccountIds: string[],\n ): Promise<PetalRelationship[]> {\n const relationships: PetalRelationship[] = [];\n let baseAccountId: string | undefined;\n\n for (const accountId of knownAccountIds) {\n try {\n const info = await new AccountInfoQuery()\n .setAccountId(accountId)\n .execute(this.client);\n\n if (info.key.toString() === publicKey.toString()) {\n const hasEvmAlias = info.contractAccountId !== null;\n\n if (hasEvmAlias && !baseAccountId) {\n baseAccountId = accountId;\n }\n\n const profileRef = info.accountMemo\n ? this.parseProfileReference(info.accountMemo)\n : null;\n\n relationships.push({\n petalAccountId: accountId,\n baseAccountId: baseAccountId || accountId,\n sharedPublicKey: publicKey,\n profileTopicId: profileRef?.resourceLocator,\n });\n }\n } catch (error) {\n this.logger.warn(`Failed to check account ${accountId}`, error);\n }\n }\n\n if (baseAccountId) {\n relationships.forEach(rel => {\n if (!rel.baseAccountId || rel.baseAccountId === rel.petalAccountId) {\n rel.baseAccountId = baseAccountId!;\n }\n });\n }\n\n return relationships;\n }\n}\n"],"names":[],"mappings":";;;AAwBO,MAAM,oBAAoB;AAAA,EAG/B,YACmB,QACjB,QACA;AAFiB,SAAA,SAAA;AAGjB,SAAK,SAAS,UAAU,IAAI,OAAO,EAAE,QAAQ,uBAAuB;AAAA,EACtE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,kBAAkB,QAGqC;AAC3D,QAAI;AACF,WAAK,OAAO,KAAK,oDAAoD;AAErE,YAAM,aAAa,WAAW,cAAA;AAC9B,YAAM,YAAY,WAAW;AAC7B,YAAM,aAAa,UAAU,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Aa,KAAK,cACpB,KAAK,sBAAsB,KAAK,WAAW,IAC3C;AAEJ,wBAAc,KAAK;AAAA,YACjB,gBAAgB;AAAA,YAChB,eAAe,iBAAiB;AAAA,YAChC,iBAAiB;AAAA,YACjB,gBAAgB,YAAY;AAAA,UAAA,CAC7B;AAAA,QACH;AAAA,MACF,SAAS,OAAO;AACd,aAAK,OAAO,KAAK,2BAA2B,SAAS,IAAI,KAAK;AAAA,MAChE;AAAA,IACF;AAEA,QAAI,eAAe;AACjB,oBAAc,QAAQ,CAAA,QAAO;AAC3B,YAAI,CAAC,IAAI,iBAAiB,IAAI,kBAAkB,IAAI,gBAAgB;AAClE,cAAI,gBAAgB;AAAA,QACtB;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AACF;"}
|
|
1
|
+
{"version":3,"file":"standards-sdk.es28.js","sources":["../../src/hcs-16/types.ts"],"sourcesContent":["import {\n AccountId,\n TopicId,\n PublicKey,\n Key,\n PrivateKey,\n KeyList,\n TokenId,\n} from '@hashgraph/sdk';\nimport { SocialLink } from '../hcs-11/types';\n\n/**\n * HCS-16 Topic type enums\n */\nexport enum FloraTopicType {\n COMMUNICATION = 0,\n TRANSACTION = 1,\n STATE = 2,\n}\n\n/**\n * HCS-16 Flora member\n */\nexport interface FloraMember {\n accountId: string;\n publicKey?: PublicKey | string; // Support both PublicKey objects and serialized strings\n privateKey?: string;\n weight?: number;\n}\n\n/**\n * HCS-16 Flora topics\n */\nexport interface FloraTopics {\n communication: TopicId;\n transaction: TopicId;\n state: TopicId;\n custom?: Array<{\n name: string;\n topicId: string;\n description?: string;\n }>;\n}\n\n/**\n * HCS-16 Flora configuration\n */\nexport interface FloraConfig {\n displayName: string;\n bio?: string;\n members: FloraMember[];\n threshold: number;\n initialBalance?: number;\n maxAutomaticTokenAssociations?: number;\n policies?: {\n membershipChange?: string;\n scheduleTxApproval?: string;\n };\n customFees?: {\n amount: number;\n feeCollectorAccountId: string;\n }[];\n metadata?: Record<string, any>;\n}\n\n/**\n * HCS-16 Flora creation result\n */\nexport interface FloraCreationResult {\n floraAccountId: AccountId;\n topics: FloraTopics;\n keyList: Key;\n transactionId: string;\n}\n\n/**\n * HCS-16 Message protocol operations\n */\nexport enum FloraOperation {\n FLORA_CREATE_REQUEST = 'flora_create_request',\n FLORA_CREATE_ACCEPTED = 'flora_create_accepted',\n FLORA_CREATED = 'flora_created',\n TX_PROPOSAL = 'tx_proposal',\n STATE_UPDATE = 'state_update',\n FLORA_JOIN_REQUEST = 'flora_join_request',\n FLORA_JOIN_VOTE = 'flora_join_vote',\n FLORA_JOIN_ACCEPTED = 'flora_join_accepted',\n CREDIT_PURCHASE = 'credit_purchase',\n}\n\n/**\n * HCS-16 Message envelope\n */\nexport interface FloraMessage {\n p: 'hcs-16';\n op: FloraOperation;\n operator_id: string;\n m?: string;\n [key: string]: unknown;\n}\n\n/**\n * HCS-16 Flora profile (extends HCS-11)\n */\nexport interface FloraProfile {\n version: string;\n type: 3;\n display_name: string;\n members: FloraMember[];\n threshold: number;\n topics: {\n communication: string;\n transaction: string;\n state: string;\n custom?: Array<{\n name: string;\n topicId: string;\n description?: string;\n }>;\n };\n alias?: string;\n bio?: string;\n socials?: SocialLink[];\n profileImage?: string;\n properties?: Record<string, unknown>;\n inboundTopicId: string;\n outboundTopicId: string;\n policies?: Record<string, string>;\n metadata?: Record<string, any>;\n}\n\n/**\n * HCS-16 errors\n */\nexport class FloraError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n ) {\n super(message);\n this.name = 'FloraError';\n }\n}\n\n/**\n * Flora state update message\n */\nexport interface FloraStateUpdate {\n p: 'hcs-16';\n op: 'state_update';\n operator_id: string;\n hash: string;\n epoch?: number;\n members?: string[];\n timestamp: string;\n}\n\n/**\n * HIP-991 Custom fee configuration for transaction topics\n */\nexport interface TransactionTopicFee {\n amount: number;\n feeCollectorAccountId: string;\n denominatingTokenId?: string;\n}\n\n/**\n * Configuration for creating HCS-16 transaction topics with HIP-991 support\n */\nexport interface TransactionTopicConfig {\n memo: string;\n adminKey?: PrivateKey | KeyList;\n submitKey?: PrivateKey | KeyList;\n feeScheduleKey?: PrivateKey | KeyList;\n customFees?: TransactionTopicFee[];\n feeExemptKeys?: Key[];\n}\n\n/**\n * HCS-16 Credit purchase message\n */\nexport interface CreditPurchaseMessage extends FloraMessage {\n p: 'hcs-16';\n op: FloraOperation.CREDIT_PURCHASE;\n amount: number;\n purchaser: string;\n timestamp: string;\n}\n"],"names":["FloraTopicType","FloraOperation"],"mappings":"AAcO,IAAK,mCAAAA,oBAAL;AACLA,kBAAAA,gBAAA,mBAAgB,CAAA,IAAhB;AACAA,kBAAAA,gBAAA,iBAAc,CAAA,IAAd;AACAA,kBAAAA,gBAAA,WAAQ,CAAA,IAAR;AAHU,SAAAA;AAAA,GAAA,kBAAA,CAAA,CAAA;AAgEL,IAAK,mCAAAC,oBAAL;AACLA,kBAAA,sBAAA,IAAuB;AACvBA,kBAAA,uBAAA,IAAwB;AACxBA,kBAAA,eAAA,IAAgB;AAChBA,kBAAA,aAAA,IAAc;AACdA,kBAAA,cAAA,IAAe;AACfA,kBAAA,oBAAA,IAAqB;AACrBA,kBAAA,iBAAA,IAAkB;AAClBA,kBAAA,qBAAA,IAAsB;AACtBA,kBAAA,iBAAA,IAAkB;AATR,SAAAA;AAAA,GAAA,kBAAA,CAAA,CAAA;AAwDL,MAAM,mBAAmB,MAAM;AAAA,EACpC,YACE,SACgB,MAChB;AACA,UAAM,OAAO;AAFG,SAAA,OAAA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;"}
|