@agentbadge/hedera-core 0.1.15
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/catalog.d.ts +13 -0
- package/dist/catalog.js +231 -0
- package/dist/chain-adapter.d.ts +62 -0
- package/dist/chain-adapter.js +1 -0
- package/dist/datahub.client.d.ts +58 -0
- package/dist/datahub.client.js +356 -0
- package/dist/did.d.ts +7 -0
- package/dist/did.js +33 -0
- package/dist/hedera-chain-adapter-instance.d.ts +2 -0
- package/dist/hedera-chain-adapter-instance.js +10 -0
- package/dist/hedera-chain-adapter.d.ts +18 -0
- package/dist/hedera-chain-adapter.js +121 -0
- package/dist/hedera.service.d.ts +52 -0
- package/dist/hedera.service.js +415 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +261 -0
- package/dist/mirror.service.d.ts +34 -0
- package/dist/mirror.service.js +187 -0
- package/dist/mock-hedera.service.d.ts +69 -0
- package/dist/mock-hedera.service.js +195 -0
- package/dist/mock-mirror.service.d.ts +22 -0
- package/dist/mock-mirror.service.js +72 -0
- package/dist/mock-settle.d.ts +1 -0
- package/dist/mock-settle.js +6 -0
- package/dist/services-index.d.ts +84 -0
- package/dist/services-index.js +133 -0
- package/dist/signing.d.ts +5 -0
- package/dist/signing.js +17 -0
- package/dist/types.d.ts +215 -0
- package/dist/types.js +56 -0
- package/package.json +44 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
const nftStore = new Map();
|
|
2
|
+
const serialCounters = new Map();
|
|
3
|
+
const topicMessages = new Map();
|
|
4
|
+
const messageCounters = new Map();
|
|
5
|
+
function nftKey(tokenId, serial) {
|
|
6
|
+
return `${tokenId}:${serial}`;
|
|
7
|
+
}
|
|
8
|
+
function fakeTxId() {
|
|
9
|
+
const accountId = process.env.HEDERA_OPERATOR_ID ?? "0.0.2";
|
|
10
|
+
const seconds = Math.floor(Date.now() / 1000);
|
|
11
|
+
const nanos = Math.floor(Math.random() * 1_000_000_000);
|
|
12
|
+
return `${accountId}@${seconds}.${nanos}`;
|
|
13
|
+
}
|
|
14
|
+
function fakeTimestamp() {
|
|
15
|
+
const seconds = Math.floor(Date.now() / 1000);
|
|
16
|
+
const nanos = Math.floor(Math.random() * 1_000_000_000);
|
|
17
|
+
return `${seconds}.${String(nanos).padStart(9, "0")}`;
|
|
18
|
+
}
|
|
19
|
+
export async function mintPassportNFT(tokenId, ipfsUri) {
|
|
20
|
+
const current = serialCounters.get(tokenId) ?? 0;
|
|
21
|
+
const serial = current + 1;
|
|
22
|
+
serialCounters.set(tokenId, serial);
|
|
23
|
+
const treasury = process.env.HEDERA_OPERATOR_ID ?? "0.0.2";
|
|
24
|
+
const key = nftKey(tokenId, serial);
|
|
25
|
+
nftStore.set(key, {
|
|
26
|
+
token_id: tokenId,
|
|
27
|
+
serial_number: serial,
|
|
28
|
+
account_id: treasury,
|
|
29
|
+
metadata: ipfsUri,
|
|
30
|
+
deleted: false,
|
|
31
|
+
created_timestamp: fakeTimestamp(),
|
|
32
|
+
});
|
|
33
|
+
return { tokenId, serial };
|
|
34
|
+
}
|
|
35
|
+
export async function transferNFTToAgent(tokenId, serial, _fromAccountId, toAccountId) {
|
|
36
|
+
const key = nftKey(tokenId, serial);
|
|
37
|
+
const nft = nftStore.get(key);
|
|
38
|
+
if (!nft)
|
|
39
|
+
throw new Error(`NFT not found: ${key}`);
|
|
40
|
+
nft.account_id = toAccountId;
|
|
41
|
+
}
|
|
42
|
+
export async function grantKyc(_tokenId, _accountId) {
|
|
43
|
+
}
|
|
44
|
+
export async function burnPassportNFT(tokenId, serial) {
|
|
45
|
+
const key = nftKey(tokenId, serial);
|
|
46
|
+
if (!nftStore.has(key))
|
|
47
|
+
throw new Error(`NFT not found: ${key}`);
|
|
48
|
+
nftStore.delete(key);
|
|
49
|
+
}
|
|
50
|
+
export async function submitAuditMessage(message) {
|
|
51
|
+
const topicId = process.env.AUDIT_TOPIC_ID ?? "0.0.555";
|
|
52
|
+
return pushTopicMessage(topicId, JSON.stringify(message));
|
|
53
|
+
}
|
|
54
|
+
export async function submitDirectoryMessage(message) {
|
|
55
|
+
const topicId = process.env.DIRECTORY_TOPIC_ID ?? "0.0.666";
|
|
56
|
+
return pushTopicMessage(topicId, JSON.stringify(message));
|
|
57
|
+
}
|
|
58
|
+
export async function submitA2AMessage(message) {
|
|
59
|
+
const topicId = process.env.A2A_TOPIC_ID ?? "0.0.777";
|
|
60
|
+
const txId = pushTopicMessage(topicId, JSON.stringify(message));
|
|
61
|
+
return { txId, consensusTimestamp: fakeTimestamp() };
|
|
62
|
+
}
|
|
63
|
+
export async function submitTaskMessage(message) {
|
|
64
|
+
const topicId = process.env.MARKET_TOPIC_ID ?? "0.0.888";
|
|
65
|
+
const txId = pushTopicMessage(topicId, JSON.stringify(message));
|
|
66
|
+
return { txId, consensusTimestamp: fakeTimestamp() };
|
|
67
|
+
}
|
|
68
|
+
export async function prepareTopicMessageTransaction(agentAccountId, message, topicIdOverride) {
|
|
69
|
+
const topicId = topicIdOverride ?? process.env.MARKET_TOPIC_ID ?? "0.0.888";
|
|
70
|
+
const messageStr = JSON.stringify(message);
|
|
71
|
+
const txId = `${agentAccountId}-${Date.now()}-0000000000`;
|
|
72
|
+
const mockData = JSON.stringify({ topicId, messageStr, agentAccountId, txId });
|
|
73
|
+
return { txBytes: Buffer.from(mockData).toString("base64"), txId };
|
|
74
|
+
}
|
|
75
|
+
export async function prepareA2ATopicMessage(agentAccountId, message) {
|
|
76
|
+
const topicId = process.env.A2A_TOPIC_ID ?? "0.0.777";
|
|
77
|
+
return prepareTopicMessageTransaction(agentAccountId, message, topicId);
|
|
78
|
+
}
|
|
79
|
+
export async function submitSignedTopicMessage(_txBytesBase64, _publicKeyDer, _signatureBytes) {
|
|
80
|
+
try {
|
|
81
|
+
const data = JSON.parse(Buffer.from(_txBytesBase64, "base64").toString("utf8"));
|
|
82
|
+
const topicId = data.topicId ?? process.env.MARKET_TOPIC_ID ?? "0.0.888";
|
|
83
|
+
return pushTopicMessage(topicId, data.messageStr ?? "{}");
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
const topicId = process.env.MARKET_TOPIC_ID ?? "0.0.888";
|
|
87
|
+
return pushTopicMessage(topicId, "{}");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function pushTopicMessage(topicId, messageStr) {
|
|
91
|
+
const seq = (messageCounters.get(topicId) ?? 0) + 1;
|
|
92
|
+
messageCounters.set(topicId, seq);
|
|
93
|
+
const txId = fakeTxId();
|
|
94
|
+
const msgs = topicMessages.get(topicId) ?? [];
|
|
95
|
+
msgs.push({
|
|
96
|
+
consensus_timestamp: fakeTimestamp(),
|
|
97
|
+
message: messageStr,
|
|
98
|
+
sequence_number: seq,
|
|
99
|
+
running_hash: `mock_hash_${seq}`,
|
|
100
|
+
transaction_id: txId,
|
|
101
|
+
});
|
|
102
|
+
topicMessages.set(topicId, msgs);
|
|
103
|
+
return txId;
|
|
104
|
+
}
|
|
105
|
+
export async function wipeNFT(tokenId, _accountId, serial) {
|
|
106
|
+
const key = nftKey(tokenId, serial);
|
|
107
|
+
const nft = nftStore.get(key);
|
|
108
|
+
if (!nft)
|
|
109
|
+
throw new Error(`NFT not found: ${key}`);
|
|
110
|
+
nft.deleted = true;
|
|
111
|
+
}
|
|
112
|
+
export async function updateNftMetadata(tokenId, serial, newUri) {
|
|
113
|
+
const key = nftKey(tokenId, serial);
|
|
114
|
+
const nft = nftStore.get(key);
|
|
115
|
+
if (!nft)
|
|
116
|
+
throw new Error(`NFT not found: ${key}`);
|
|
117
|
+
nft.metadata = newUri;
|
|
118
|
+
}
|
|
119
|
+
export async function transferHbar(fromAccountId, toAccountId, amountHbar) {
|
|
120
|
+
const txId = `0.0.${fromAccountId.split(".")[2]}@${fakeTimestamp()}`;
|
|
121
|
+
return txId;
|
|
122
|
+
}
|
|
123
|
+
export async function transferHbarWithKey(fromAccountId, _fromPrivateKey, toAccountId, amountHbar) {
|
|
124
|
+
return transferHbar(fromAccountId, toAccountId, amountHbar);
|
|
125
|
+
}
|
|
126
|
+
export async function prepareTransferTransaction(_fromAccountId, _toAccountId, _amountHbar) {
|
|
127
|
+
return {
|
|
128
|
+
txBytes: "mock-tx-bytes-base64",
|
|
129
|
+
txId: fakeTxId(),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export async function transferHbarWithSignature(_txBytesBase64, _publicKeyStr, signatureBytes) {
|
|
133
|
+
const sigs = Array.isArray(signatureBytes) ? signatureBytes : [signatureBytes];
|
|
134
|
+
if (!sigs.length || sigs.some((s) => !s || s.length === 0)) {
|
|
135
|
+
throw new Error("Invalid signature: signatureBytes must be non-empty");
|
|
136
|
+
}
|
|
137
|
+
return fakeTxId();
|
|
138
|
+
}
|
|
139
|
+
let scheduleCounter = 0;
|
|
140
|
+
function fakeScheduleNum() {
|
|
141
|
+
scheduleCounter += 1;
|
|
142
|
+
return 10_000 + scheduleCounter;
|
|
143
|
+
}
|
|
144
|
+
export async function createScheduledTransfer(fromAccountId, toAccountId, amountHbar, options) {
|
|
145
|
+
const scheduleId = `0.0.${fakeScheduleNum()}`;
|
|
146
|
+
const scheduleTxId = `${fromAccountId}@${fakeTimestamp()}`;
|
|
147
|
+
return { scheduleId, scheduleTxId };
|
|
148
|
+
}
|
|
149
|
+
export async function signScheduledTransaction(scheduleId, _signerPrivateKey) {
|
|
150
|
+
if (!scheduleId || !scheduleId.trim()) {
|
|
151
|
+
throw new Error("scheduleId must be a non-empty string");
|
|
152
|
+
}
|
|
153
|
+
return { txId: fakeTxId(), executed: true };
|
|
154
|
+
}
|
|
155
|
+
export async function signScheduledTransactionWithSignature(scheduleId, _txBytesBase64, _publicKeyStr, _signatureBytes) {
|
|
156
|
+
if (!scheduleId || !scheduleId.trim()) {
|
|
157
|
+
throw new Error("scheduleId must be a non-empty string");
|
|
158
|
+
}
|
|
159
|
+
return { txId: fakeTxId(), executed: true };
|
|
160
|
+
}
|
|
161
|
+
export async function deleteScheduledTransaction(scheduleId) {
|
|
162
|
+
if (!scheduleId || !scheduleId.trim()) {
|
|
163
|
+
throw new Error("scheduleId must be a non-empty string");
|
|
164
|
+
}
|
|
165
|
+
return { scheduleId, deleted: true };
|
|
166
|
+
}
|
|
167
|
+
const fileStore = new Map();
|
|
168
|
+
let fileCounter = 0;
|
|
169
|
+
const HFS_MAX_SIZE_BYTES = 1024 * 1024;
|
|
170
|
+
export async function uploadFileToHFS(contents, _fileMemo) {
|
|
171
|
+
if (contents.length > HFS_MAX_SIZE_BYTES) {
|
|
172
|
+
throw new Error(`File too large: ${contents.length} bytes exceeds max size of ${HFS_MAX_SIZE_BYTES} bytes (1024 KB)`);
|
|
173
|
+
}
|
|
174
|
+
fileCounter += 1;
|
|
175
|
+
const fileId = `0.0.${fileCounter}`;
|
|
176
|
+
fileStore.set(fileId, Buffer.from(contents));
|
|
177
|
+
return { fileId, txId: fakeTxId() };
|
|
178
|
+
}
|
|
179
|
+
export async function downloadFileFromHFS(fileId) {
|
|
180
|
+
const data = fileStore.get(fileId);
|
|
181
|
+
if (!data) {
|
|
182
|
+
throw new Error(`File not found: ${fileId} (404)`);
|
|
183
|
+
}
|
|
184
|
+
return Buffer.from(data);
|
|
185
|
+
}
|
|
186
|
+
export function resetMockState() {
|
|
187
|
+
nftStore.clear();
|
|
188
|
+
serialCounters.clear();
|
|
189
|
+
topicMessages.clear();
|
|
190
|
+
messageCounters.clear();
|
|
191
|
+
scheduleCounter = 0;
|
|
192
|
+
fileStore.clear();
|
|
193
|
+
fileCounter = 0;
|
|
194
|
+
}
|
|
195
|
+
export { nftStore, topicMessages };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { NftInfo, TopicMessage } from "./types";
|
|
2
|
+
import type { PaginatedMessages, ScheduleInfo } from "./mirror.service";
|
|
3
|
+
export declare function getNftInfo(tokenId: string, serial: number): Promise<NftInfo | null>;
|
|
4
|
+
export declare function getNftsForToken(tokenId: string, opts?: {
|
|
5
|
+
maxResults?: number;
|
|
6
|
+
}): Promise<NftInfo[]>;
|
|
7
|
+
export declare function getNftsForAccount(accountId: string, opts?: {
|
|
8
|
+
maxResults?: number;
|
|
9
|
+
}): Promise<NftInfo[]>;
|
|
10
|
+
export declare function getTopicMessages(topicId: string, opts?: {
|
|
11
|
+
startTime?: string;
|
|
12
|
+
endTime?: string;
|
|
13
|
+
limit?: number;
|
|
14
|
+
maxResults?: number;
|
|
15
|
+
}): Promise<TopicMessage[]>;
|
|
16
|
+
export declare function getTopicMessagesPaginated(topicId: string, opts?: {
|
|
17
|
+
startTime?: string;
|
|
18
|
+
endTime?: string;
|
|
19
|
+
limit?: number;
|
|
20
|
+
pageUrl?: string;
|
|
21
|
+
}): Promise<PaginatedMessages>;
|
|
22
|
+
export declare function getScheduleInfo(scheduleId: string): Promise<ScheduleInfo | null>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { nftStore, topicMessages } from "./mock-hedera.service";
|
|
2
|
+
export async function getNftInfo(tokenId, serial) {
|
|
3
|
+
const key = `${tokenId}:${serial}`;
|
|
4
|
+
const nft = nftStore.get(key);
|
|
5
|
+
if (!nft)
|
|
6
|
+
return null;
|
|
7
|
+
return { ...nft };
|
|
8
|
+
}
|
|
9
|
+
export async function getNftsForToken(tokenId, opts) {
|
|
10
|
+
const result = [];
|
|
11
|
+
for (const nft of nftStore.values()) {
|
|
12
|
+
if (nft.token_id === tokenId) {
|
|
13
|
+
result.push({ ...nft });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (opts?.maxResults)
|
|
17
|
+
return result.slice(0, opts.maxResults);
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
export async function getNftsForAccount(accountId, opts) {
|
|
21
|
+
const result = [];
|
|
22
|
+
for (const nft of nftStore.values()) {
|
|
23
|
+
if (nft.account_id === accountId) {
|
|
24
|
+
result.push({ ...nft });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (opts?.maxResults)
|
|
28
|
+
return result.slice(0, opts.maxResults);
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
export async function getTopicMessages(topicId, opts) {
|
|
32
|
+
const msgs = topicMessages.get(topicId) ?? [];
|
|
33
|
+
let result = [...msgs];
|
|
34
|
+
if (opts?.startTime) {
|
|
35
|
+
result = result.filter((m) => m.consensus_timestamp > opts.startTime);
|
|
36
|
+
}
|
|
37
|
+
if (opts?.endTime) {
|
|
38
|
+
result = result.filter((m) => m.consensus_timestamp < opts.endTime);
|
|
39
|
+
}
|
|
40
|
+
const limit = opts?.limit ?? 100;
|
|
41
|
+
result.sort((a, b) => b.sequence_number - a.sequence_number);
|
|
42
|
+
const sliced = result.slice(0, limit);
|
|
43
|
+
if (opts?.maxResults)
|
|
44
|
+
return sliced.slice(0, opts.maxResults);
|
|
45
|
+
return sliced;
|
|
46
|
+
}
|
|
47
|
+
export async function getTopicMessagesPaginated(topicId, opts) {
|
|
48
|
+
const msgs = topicMessages.get(topicId) ?? [];
|
|
49
|
+
let result = [...msgs];
|
|
50
|
+
if (opts?.startTime) {
|
|
51
|
+
result = result.filter((m) => m.consensus_timestamp > opts.startTime);
|
|
52
|
+
}
|
|
53
|
+
if (opts?.endTime) {
|
|
54
|
+
result = result.filter((m) => m.consensus_timestamp < opts.endTime);
|
|
55
|
+
}
|
|
56
|
+
const limit = opts?.limit ?? 100;
|
|
57
|
+
result.sort((a, b) => b.sequence_number - a.sequence_number);
|
|
58
|
+
const sliced = result.slice(0, limit);
|
|
59
|
+
return {
|
|
60
|
+
messages: sliced,
|
|
61
|
+
nextPageUrl: null,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export async function getScheduleInfo(scheduleId) {
|
|
65
|
+
return {
|
|
66
|
+
scheduleId,
|
|
67
|
+
executed: false,
|
|
68
|
+
deleted: false,
|
|
69
|
+
signers: [],
|
|
70
|
+
memo: "mock-escrow",
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mockSettle(_payTo: string, _amount: number): Promise<string>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export async function mockSettle(_payTo, _amount) {
|
|
2
|
+
const accountId = process.env.HEDERA_OPERATOR_ID ?? "0.0.2";
|
|
3
|
+
const seconds = Math.floor(Date.now() / 1000);
|
|
4
|
+
const nanos = Math.floor(Math.random() * 1_000_000_000);
|
|
5
|
+
return `${accountId}@${seconds}.${nanos}`;
|
|
6
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { A2AMessage, AuditMessage, HcsMessageReceipt, HFSUploadResult, MintResult, NftInfo, TaskMessage, TaskMessageWithTx, TopicMessage } from "./types";
|
|
2
|
+
import type { DirectoryMessage } from "./hedera.service";
|
|
3
|
+
import type { PaginatedMessages, ScheduleInfo } from "./mirror.service";
|
|
4
|
+
export declare function mintPassportNFT(tokenId: string, ipfsUri: string): Promise<MintResult>;
|
|
5
|
+
export declare function burnPassportNFT(tokenId: string, serial: number): Promise<void>;
|
|
6
|
+
export declare function transferNFTToAgent(tokenId: string, serial: number, fromAccountId: string, toAccountId: string): Promise<void>;
|
|
7
|
+
export declare function grantKyc(tokenId: string, accountId: string): Promise<void>;
|
|
8
|
+
export declare function submitAuditMessage(message: AuditMessage): Promise<string>;
|
|
9
|
+
export declare function submitDirectoryMessage(message: DirectoryMessage): Promise<string>;
|
|
10
|
+
export declare function submitA2AMessage(message: A2AMessage): Promise<HcsMessageReceipt>;
|
|
11
|
+
export declare function submitTaskMessage(message: TaskMessage): Promise<HcsMessageReceipt>;
|
|
12
|
+
export declare function prepareTopicMessageTransaction(agentAccountId: string, message: object, topicIdOverride?: string): Promise<{
|
|
13
|
+
txBytes: string;
|
|
14
|
+
txId: string;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function prepareA2ATopicMessage(agentAccountId: string, message: A2AMessage): Promise<{
|
|
17
|
+
txBytes: string;
|
|
18
|
+
txId: string;
|
|
19
|
+
}>;
|
|
20
|
+
export declare function submitSignedTopicMessage(txBytesBase64: string, publicKeyDer: string, signatureBytes: Uint8Array[]): Promise<string>;
|
|
21
|
+
export declare function wipeNFT(tokenId: string, accountId: string, serial: number): Promise<void>;
|
|
22
|
+
export declare function updateNftMetadata(tokenId: string, serial: number, newUri: string): Promise<void>;
|
|
23
|
+
export declare function transferHbar(fromAccountId: string, toAccountId: string, amountHbar: number): Promise<string>;
|
|
24
|
+
export declare function transferHbarWithKey(fromAccountId: string, fromPrivateKey: string, toAccountId: string, amountHbar: number): Promise<string>;
|
|
25
|
+
export declare function prepareTransferTransaction(fromAccountId: string, toAccountId: string, amountHbar: number): Promise<{
|
|
26
|
+
txBytes: string;
|
|
27
|
+
txId: string;
|
|
28
|
+
}>;
|
|
29
|
+
export declare function transferHbarWithSignature(txBytesBase64: string, publicKeyStr: string, signatureBytes: Uint8Array | Uint8Array[]): Promise<string>;
|
|
30
|
+
export declare function createScheduledTransfer(fromAccountId: string, toAccountId: string, amountHbar: number, options?: {
|
|
31
|
+
adminKey?: boolean;
|
|
32
|
+
expirationSeconds?: number;
|
|
33
|
+
memo?: string;
|
|
34
|
+
}): Promise<{
|
|
35
|
+
scheduleId: string;
|
|
36
|
+
scheduleTxId: string;
|
|
37
|
+
}>;
|
|
38
|
+
export declare function signScheduledTransaction(scheduleId: string, signerPrivateKey: string): Promise<{
|
|
39
|
+
txId: string;
|
|
40
|
+
executed: boolean;
|
|
41
|
+
}>;
|
|
42
|
+
export declare function signScheduledTransactionWithSignature(scheduleId: string, txBytesBase64: string, publicKeyStr: string, signatureBytes: Uint8Array | Uint8Array[]): Promise<{
|
|
43
|
+
txId: string;
|
|
44
|
+
executed: boolean;
|
|
45
|
+
}>;
|
|
46
|
+
export declare function deleteScheduledTransaction(scheduleId: string): Promise<{
|
|
47
|
+
scheduleId: string;
|
|
48
|
+
deleted: boolean;
|
|
49
|
+
}>;
|
|
50
|
+
export type { HFSUploadResult } from "./types";
|
|
51
|
+
export declare function uploadFileToHFS(contents: Buffer, fileMemo?: string): Promise<HFSUploadResult>;
|
|
52
|
+
export declare function downloadFileFromHFS(fileId: string): Promise<Buffer>;
|
|
53
|
+
export type { ScheduleInfo } from "./mirror.service";
|
|
54
|
+
export declare function getScheduleInfo(scheduleId: string): Promise<ScheduleInfo | null>;
|
|
55
|
+
export { signTransactionBytes, type SignatureResult } from "./signing";
|
|
56
|
+
export declare function getNftInfo(tokenId: string, serial: number): Promise<NftInfo | null>;
|
|
57
|
+
export declare function getNftsForToken(tokenId: string, opts?: {
|
|
58
|
+
maxResults?: number;
|
|
59
|
+
}): Promise<NftInfo[]>;
|
|
60
|
+
export declare function getNftsForAccount(accountId: string, opts?: {
|
|
61
|
+
maxResults?: number;
|
|
62
|
+
}): Promise<NftInfo[]>;
|
|
63
|
+
export declare function getTopicMessages(topicId: string, opts?: {
|
|
64
|
+
startTime?: string;
|
|
65
|
+
endTime?: string;
|
|
66
|
+
limit?: number;
|
|
67
|
+
maxResults?: number;
|
|
68
|
+
}): Promise<TopicMessage[]>;
|
|
69
|
+
export declare function getTopicMessagesPaginated(topicId: string, opts?: {
|
|
70
|
+
startTime?: string;
|
|
71
|
+
endTime?: string;
|
|
72
|
+
limit?: number;
|
|
73
|
+
pageUrl?: string;
|
|
74
|
+
}): Promise<PaginatedMessages>;
|
|
75
|
+
export declare function getTaskMessages(topicId: string, opts?: {
|
|
76
|
+
startTime?: string;
|
|
77
|
+
endTime?: string;
|
|
78
|
+
limit?: number;
|
|
79
|
+
}): Promise<TaskMessageWithTx[]>;
|
|
80
|
+
export { DataHubClient } from "./datahub.client";
|
|
81
|
+
export type { DataHubSearchResult, DataHubEntity, DataHubSchemaField, DataHubLineage, DataHubAssertion, DataHubAssertionResult, LineageEdge, } from "./datahub.client";
|
|
82
|
+
export declare function verifyA2ADid(did: string): Promise<boolean>;
|
|
83
|
+
export { HederaChainAdapter } from "./hedera-chain-adapter";
|
|
84
|
+
export { hederaChainAdapter } from "./hedera-chain-adapter-instance";
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { isValidTaskMessage } from "./types";
|
|
2
|
+
import * as realHedera from "./hedera.service";
|
|
3
|
+
import * as mockHedera from "./mock-hedera.service";
|
|
4
|
+
import * as realMirror from "./mirror.service";
|
|
5
|
+
import * as mockMirror from "./mock-mirror.service";
|
|
6
|
+
function isMockMode() {
|
|
7
|
+
return process.env.MOCK_HEDERA === "true";
|
|
8
|
+
}
|
|
9
|
+
function hedera() {
|
|
10
|
+
return isMockMode() ? mockHedera : realHedera;
|
|
11
|
+
}
|
|
12
|
+
function mirror() {
|
|
13
|
+
return isMockMode() ? mockMirror : realMirror;
|
|
14
|
+
}
|
|
15
|
+
export async function mintPassportNFT(tokenId, ipfsUri) {
|
|
16
|
+
return hedera().mintPassportNFT(tokenId, ipfsUri);
|
|
17
|
+
}
|
|
18
|
+
export async function burnPassportNFT(tokenId, serial) {
|
|
19
|
+
return hedera().burnPassportNFT(tokenId, serial);
|
|
20
|
+
}
|
|
21
|
+
export async function transferNFTToAgent(tokenId, serial, fromAccountId, toAccountId) {
|
|
22
|
+
return hedera().transferNFTToAgent(tokenId, serial, fromAccountId, toAccountId);
|
|
23
|
+
}
|
|
24
|
+
export async function grantKyc(tokenId, accountId) {
|
|
25
|
+
return hedera().grantKyc(tokenId, accountId);
|
|
26
|
+
}
|
|
27
|
+
export async function submitAuditMessage(message) {
|
|
28
|
+
return hedera().submitAuditMessage(message);
|
|
29
|
+
}
|
|
30
|
+
export async function submitDirectoryMessage(message) {
|
|
31
|
+
return hedera().submitDirectoryMessage(message);
|
|
32
|
+
}
|
|
33
|
+
export async function submitA2AMessage(message) {
|
|
34
|
+
return hedera().submitA2AMessage(message);
|
|
35
|
+
}
|
|
36
|
+
export async function submitTaskMessage(message) {
|
|
37
|
+
return hedera().submitTaskMessage(message);
|
|
38
|
+
}
|
|
39
|
+
export async function prepareTopicMessageTransaction(agentAccountId, message, topicIdOverride) {
|
|
40
|
+
return hedera().prepareTopicMessageTransaction(agentAccountId, message, topicIdOverride);
|
|
41
|
+
}
|
|
42
|
+
export async function prepareA2ATopicMessage(agentAccountId, message) {
|
|
43
|
+
return hedera().prepareA2ATopicMessage(agentAccountId, message);
|
|
44
|
+
}
|
|
45
|
+
export async function submitSignedTopicMessage(txBytesBase64, publicKeyDer, signatureBytes) {
|
|
46
|
+
return hedera().submitSignedTopicMessage(txBytesBase64, publicKeyDer, signatureBytes);
|
|
47
|
+
}
|
|
48
|
+
export async function wipeNFT(tokenId, accountId, serial) {
|
|
49
|
+
return hedera().wipeNFT(tokenId, accountId, serial);
|
|
50
|
+
}
|
|
51
|
+
export async function updateNftMetadata(tokenId, serial, newUri) {
|
|
52
|
+
return hedera().updateNftMetadata(tokenId, serial, newUri);
|
|
53
|
+
}
|
|
54
|
+
export async function transferHbar(fromAccountId, toAccountId, amountHbar) {
|
|
55
|
+
return hedera().transferHbar(fromAccountId, toAccountId, amountHbar);
|
|
56
|
+
}
|
|
57
|
+
export async function transferHbarWithKey(fromAccountId, fromPrivateKey, toAccountId, amountHbar) {
|
|
58
|
+
return hedera().transferHbarWithKey(fromAccountId, fromPrivateKey, toAccountId, amountHbar);
|
|
59
|
+
}
|
|
60
|
+
export async function prepareTransferTransaction(fromAccountId, toAccountId, amountHbar) {
|
|
61
|
+
return hedera().prepareTransferTransaction(fromAccountId, toAccountId, amountHbar);
|
|
62
|
+
}
|
|
63
|
+
export async function transferHbarWithSignature(txBytesBase64, publicKeyStr, signatureBytes) {
|
|
64
|
+
return hedera().transferHbarWithSignature(txBytesBase64, publicKeyStr, signatureBytes);
|
|
65
|
+
}
|
|
66
|
+
export async function createScheduledTransfer(fromAccountId, toAccountId, amountHbar, options) {
|
|
67
|
+
return hedera().createScheduledTransfer(fromAccountId, toAccountId, amountHbar, options);
|
|
68
|
+
}
|
|
69
|
+
export async function signScheduledTransaction(scheduleId, signerPrivateKey) {
|
|
70
|
+
return hedera().signScheduledTransaction(scheduleId, signerPrivateKey);
|
|
71
|
+
}
|
|
72
|
+
export async function signScheduledTransactionWithSignature(scheduleId, txBytesBase64, publicKeyStr, signatureBytes) {
|
|
73
|
+
return hedera().signScheduledTransactionWithSignature(scheduleId, txBytesBase64, publicKeyStr, signatureBytes);
|
|
74
|
+
}
|
|
75
|
+
export async function deleteScheduledTransaction(scheduleId) {
|
|
76
|
+
return hedera().deleteScheduledTransaction(scheduleId);
|
|
77
|
+
}
|
|
78
|
+
export async function uploadFileToHFS(contents, fileMemo) {
|
|
79
|
+
return hedera().uploadFileToHFS(contents, fileMemo);
|
|
80
|
+
}
|
|
81
|
+
export async function downloadFileFromHFS(fileId) {
|
|
82
|
+
return hedera().downloadFileFromHFS(fileId);
|
|
83
|
+
}
|
|
84
|
+
export async function getScheduleInfo(scheduleId) {
|
|
85
|
+
return mirror().getScheduleInfo(scheduleId);
|
|
86
|
+
}
|
|
87
|
+
export { signTransactionBytes } from "./signing";
|
|
88
|
+
export async function getNftInfo(tokenId, serial) {
|
|
89
|
+
return mirror().getNftInfo(tokenId, serial);
|
|
90
|
+
}
|
|
91
|
+
export async function getNftsForToken(tokenId, opts) {
|
|
92
|
+
return mirror().getNftsForToken(tokenId, opts);
|
|
93
|
+
}
|
|
94
|
+
export async function getNftsForAccount(accountId, opts) {
|
|
95
|
+
return mirror().getNftsForAccount(accountId, opts);
|
|
96
|
+
}
|
|
97
|
+
export async function getTopicMessages(topicId, opts) {
|
|
98
|
+
return mirror().getTopicMessages(topicId, opts);
|
|
99
|
+
}
|
|
100
|
+
export async function getTopicMessagesPaginated(topicId, opts) {
|
|
101
|
+
return mirror().getTopicMessagesPaginated(topicId, opts);
|
|
102
|
+
}
|
|
103
|
+
export async function getTaskMessages(topicId, opts) {
|
|
104
|
+
const messages = await getTopicMessages(topicId, opts);
|
|
105
|
+
const result = [];
|
|
106
|
+
for (const msg of messages) {
|
|
107
|
+
try {
|
|
108
|
+
const parsed = JSON.parse(msg.message);
|
|
109
|
+
if (isValidTaskMessage(parsed)) {
|
|
110
|
+
result.push({ message: parsed, txId: msg.transaction_id });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
export { DataHubClient } from "./datahub.client";
|
|
119
|
+
export async function verifyA2ADid(did) {
|
|
120
|
+
const { extractTokenAndSerial } = await import("./did");
|
|
121
|
+
const parsed = extractTokenAndSerial(did);
|
|
122
|
+
if (!parsed)
|
|
123
|
+
return false;
|
|
124
|
+
try {
|
|
125
|
+
const nft = await getNftInfo(parsed.tokenId, parsed.serial);
|
|
126
|
+
return nft !== null && !nft.deleted;
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
export { HederaChainAdapter } from "./hedera-chain-adapter";
|
|
133
|
+
export { hederaChainAdapter } from "./hedera-chain-adapter-instance";
|
package/dist/signing.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Transaction, PrivateKey } from "@hashgraph/sdk";
|
|
2
|
+
export function signTransactionBytes(txBytesBase64, privateKeyHex) {
|
|
3
|
+
if (!txBytesBase64)
|
|
4
|
+
throw new Error("txBytesBase64 is required");
|
|
5
|
+
if (!privateKeyHex)
|
|
6
|
+
throw new Error("privateKeyHex is required");
|
|
7
|
+
const txBytes = Buffer.from(txBytesBase64, "base64");
|
|
8
|
+
const tx = Transaction.fromBytes(txBytes);
|
|
9
|
+
const privateKey = PrivateKey.fromString(privateKeyHex);
|
|
10
|
+
const signatureBytes = privateKey.signTransaction(tx, true);
|
|
11
|
+
const publicKey = privateKey.publicKey.toStringDer();
|
|
12
|
+
const sigArray = Array.isArray(signatureBytes) ? signatureBytes : [signatureBytes];
|
|
13
|
+
return {
|
|
14
|
+
publicKey,
|
|
15
|
+
signature: JSON.stringify(sigArray.map((sb) => Buffer.from(sb).toString("base64"))),
|
|
16
|
+
};
|
|
17
|
+
}
|