@hashgraphonline/standards-sdk 0.1.143-feat-solana-register.canary.1870c8f.71 → 0.1.143-feat-solana-register.canary.74520ad.73
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/sdk.d.ts.map +1 -1
- package/dist/cjs/hcs-11/client.d.ts +2 -2
- package/dist/cjs/hcs-11/client.d.ts.map +1 -1
- package/dist/cjs/hcs-11/person-builder.d.ts +1 -0
- package/dist/cjs/hcs-11/person-builder.d.ts.map +1 -1
- package/dist/cjs/hcs-11/types.d.ts +1 -0
- package/dist/cjs/hcs-11/types.d.ts.map +1 -1
- package/dist/cjs/hcs-15/sdk.d.ts +4 -1
- package/dist/cjs/hcs-15/sdk.d.ts.map +1 -1
- package/dist/cjs/hcs-15/types.d.ts +16 -1
- package/dist/cjs/hcs-15/types.d.ts.map +1 -1
- package/dist/cjs/hcs-16/sdk.d.ts +22 -1
- package/dist/cjs/hcs-16/sdk.d.ts.map +1 -1
- package/dist/cjs/hcs-16/tx.d.ts +1 -1
- package/dist/cjs/hcs-16/tx.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client/feedback.d.ts +9 -0
- package/dist/cjs/services/registry-broker/client/feedback.d.ts.map +1 -0
- package/dist/cjs/services/registry-broker/client.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/private-key-signer.d.ts +1 -0
- package/dist/cjs/services/registry-broker/private-key-signer.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/schemas.d.ts +201 -28
- package/dist/cjs/services/registry-broker/schemas.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/types.d.ts +19 -1
- package/dist/cjs/services/registry-broker/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-10/sdk.d.ts.map +1 -1
- package/dist/es/hcs-11/client.d.ts +2 -2
- package/dist/es/hcs-11/client.d.ts.map +1 -1
- package/dist/es/hcs-11/person-builder.d.ts +1 -0
- package/dist/es/hcs-11/person-builder.d.ts.map +1 -1
- package/dist/es/hcs-11/types.d.ts +1 -0
- package/dist/es/hcs-11/types.d.ts.map +1 -1
- package/dist/es/hcs-15/sdk.d.ts +4 -1
- package/dist/es/hcs-15/sdk.d.ts.map +1 -1
- package/dist/es/hcs-15/types.d.ts +16 -1
- package/dist/es/hcs-15/types.d.ts.map +1 -1
- package/dist/es/hcs-16/sdk.d.ts +22 -1
- package/dist/es/hcs-16/sdk.d.ts.map +1 -1
- package/dist/es/hcs-16/tx.d.ts +1 -1
- package/dist/es/hcs-16/tx.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client/feedback.d.ts +9 -0
- package/dist/es/services/registry-broker/client/feedback.d.ts.map +1 -0
- package/dist/es/services/registry-broker/client.d.ts.map +1 -1
- package/dist/es/services/registry-broker/private-key-signer.d.ts +1 -0
- package/dist/es/services/registry-broker/private-key-signer.d.ts.map +1 -1
- package/dist/es/services/registry-broker/schemas.d.ts +201 -28
- package/dist/es/services/registry-broker/schemas.d.ts.map +1 -1
- package/dist/es/services/registry-broker/types.d.ts +19 -1
- package/dist/es/services/registry-broker/types.d.ts.map +1 -1
- package/dist/es/standards-sdk.es.js +10 -8
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/es/standards-sdk.es100.js +1 -1
- package/dist/es/standards-sdk.es102.js +1 -1
- package/dist/es/standards-sdk.es104.js +1 -1
- package/dist/es/standards-sdk.es110.js +2 -1
- package/dist/es/standards-sdk.es110.js.map +1 -1
- package/dist/es/standards-sdk.es111.js +5 -5
- package/dist/es/standards-sdk.es12.js +1 -1
- package/dist/es/standards-sdk.es121.js +1 -1
- package/dist/es/standards-sdk.es122.js +1 -1
- package/dist/es/standards-sdk.es123.js +5 -5
- package/dist/es/standards-sdk.es125.js +1 -1
- package/dist/es/standards-sdk.es126.js +1 -1
- package/dist/es/standards-sdk.es128.js +3 -3
- package/dist/es/standards-sdk.es129.js +4 -4
- package/dist/es/standards-sdk.es13.js +1 -1
- package/dist/es/standards-sdk.es130.js +3 -3
- package/dist/es/standards-sdk.es131.js +4 -4
- package/dist/es/standards-sdk.es132.js +4 -4
- package/dist/es/standards-sdk.es133.js +5 -5
- package/dist/es/standards-sdk.es133.js.map +1 -1
- package/dist/es/standards-sdk.es134.js +2 -2
- package/dist/es/standards-sdk.es135.js +4 -4
- package/dist/es/standards-sdk.es136.js +55 -367
- package/dist/es/standards-sdk.es136.js.map +1 -1
- package/dist/es/standards-sdk.es137.js +363 -14
- package/dist/es/standards-sdk.es137.js.map +1 -1
- package/dist/es/standards-sdk.es138.js +15 -65
- package/dist/es/standards-sdk.es138.js.map +1 -1
- package/dist/es/standards-sdk.es139.js +71 -77
- package/dist/es/standards-sdk.es139.js.map +1 -1
- package/dist/es/standards-sdk.es140.js +80 -152
- package/dist/es/standards-sdk.es140.js.map +1 -1
- package/dist/es/standards-sdk.es141.js +159 -7
- package/dist/es/standards-sdk.es141.js.map +1 -1
- package/dist/es/standards-sdk.es142.js +7 -86
- package/dist/es/standards-sdk.es142.js.map +1 -1
- package/dist/es/standards-sdk.es143.js +64 -43
- package/dist/es/standards-sdk.es143.js.map +1 -1
- package/dist/es/standards-sdk.es144.js +65 -28
- package/dist/es/standards-sdk.es144.js.map +1 -1
- package/dist/es/standards-sdk.es145.js +30 -138
- package/dist/es/standards-sdk.es145.js.map +1 -1
- package/dist/es/standards-sdk.es146.js +34 -42
- package/dist/es/standards-sdk.es146.js.map +1 -1
- package/dist/es/standards-sdk.es147.js +28 -12289
- package/dist/es/standards-sdk.es147.js.map +1 -1
- package/dist/es/standards-sdk.es148.js +132 -50
- package/dist/es/standards-sdk.es148.js.map +1 -1
- package/dist/es/standards-sdk.es149.js +34 -74
- package/dist/es/standards-sdk.es149.js.map +1 -1
- package/dist/es/standards-sdk.es150.js +12284 -12
- package/dist/es/standards-sdk.es150.js.map +1 -1
- package/dist/es/standards-sdk.es151.js +51 -167
- package/dist/es/standards-sdk.es151.js.map +1 -1
- package/dist/es/standards-sdk.es152.js +69 -309
- package/dist/es/standards-sdk.es152.js.map +1 -1
- package/dist/es/standards-sdk.es153.js +120 -294
- package/dist/es/standards-sdk.es153.js.map +1 -1
- package/dist/es/standards-sdk.es154.js +191 -322
- package/dist/es/standards-sdk.es154.js.map +1 -1
- package/dist/es/standards-sdk.es155.js +294 -279
- package/dist/es/standards-sdk.es155.js.map +1 -1
- package/dist/es/standards-sdk.es156.js +440 -63
- package/dist/es/standards-sdk.es156.js.map +1 -1
- package/dist/es/standards-sdk.es157.js +331 -871
- package/dist/es/standards-sdk.es157.js.map +1 -1
- package/dist/es/standards-sdk.es158.js +68 -231
- package/dist/es/standards-sdk.es158.js.map +1 -1
- package/dist/es/standards-sdk.es159.js +15 -242
- package/dist/es/standards-sdk.es159.js.map +1 -1
- package/dist/es/standards-sdk.es160.js +926 -0
- package/dist/es/standards-sdk.es160.js.map +1 -0
- package/dist/es/standards-sdk.es161.js +242 -0
- package/dist/es/standards-sdk.es161.js.map +1 -0
- package/dist/es/standards-sdk.es162.js +247 -0
- package/dist/es/standards-sdk.es162.js.map +1 -0
- package/dist/es/standards-sdk.es17.js +9 -5
- package/dist/es/standards-sdk.es17.js.map +1 -1
- package/dist/es/standards-sdk.es19.js +9 -6
- package/dist/es/standards-sdk.es19.js.map +1 -1
- package/dist/es/standards-sdk.es20.js +3 -2
- package/dist/es/standards-sdk.es20.js.map +1 -1
- package/dist/es/standards-sdk.es23.js +1 -1
- package/dist/es/standards-sdk.es25.js +5 -0
- package/dist/es/standards-sdk.es25.js.map +1 -1
- package/dist/es/standards-sdk.es28.js +25 -5
- package/dist/es/standards-sdk.es28.js.map +1 -1
- package/dist/es/standards-sdk.es29.js.map +1 -1
- package/dist/es/standards-sdk.es31.js +1 -1
- package/dist/es/standards-sdk.es32.js +1 -1
- package/dist/es/standards-sdk.es36.js +3 -2
- package/dist/es/standards-sdk.es36.js.map +1 -1
- package/dist/es/standards-sdk.es37.js +3 -3
- package/dist/es/standards-sdk.es38.js +1 -1
- package/dist/es/standards-sdk.es5.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.es59.js +1 -1
- package/dist/es/standards-sdk.es60.js +1 -1
- package/dist/es/standards-sdk.es61.js +3 -2
- package/dist/es/standards-sdk.es61.js.map +1 -1
- package/dist/es/standards-sdk.es63.js +1 -1
- package/dist/es/standards-sdk.es65.js +1 -1
- package/dist/es/standards-sdk.es66.js +2 -2
- package/dist/es/standards-sdk.es69.js +2 -2
- package/dist/es/standards-sdk.es70.js +1 -1
- package/dist/es/standards-sdk.es72.js +1 -1
- package/dist/es/standards-sdk.es77.js +1 -1
- package/dist/es/standards-sdk.es78.js +2 -1
- package/dist/es/standards-sdk.es78.js.map +1 -1
- package/dist/es/standards-sdk.es79.js +1 -1
- package/dist/es/standards-sdk.es8.js +1 -1
- package/dist/es/standards-sdk.es82.js +1 -1
- package/dist/es/standards-sdk.es84.js +1 -1
- package/dist/es/standards-sdk.es88.js +65 -2
- package/dist/es/standards-sdk.es88.js.map +1 -1
- package/dist/es/standards-sdk.es92.js +2 -2
- package/dist/es/standards-sdk.es92.js.map +1 -1
- package/dist/es/standards-sdk.es93.js +58 -1
- package/dist/es/standards-sdk.es93.js.map +1 -1
- package/dist/es/standards-sdk.es98.js +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,162 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { CustomFeeType } from "./standards-sdk.es142.js";
|
|
2
|
+
import { HederaMirrorNode } from "./standards-sdk.es127.js";
|
|
3
|
+
class FeeConfigBuilder {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
this.customFees = [];
|
|
6
|
+
this.logger = options.logger;
|
|
7
|
+
this.mirrorNode = new HederaMirrorNode(options.network, options.logger);
|
|
8
|
+
this.defaultCollectorAccountId = options.defaultCollectorAccountId || "";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Static factory method to create a FeeConfigBuilder with a single HBAR fee.
|
|
12
|
+
* @param hbarAmount Amount in HBAR.
|
|
13
|
+
* @param collectorAccountId Optional account ID to collect the fee. If omitted or undefined, defaults to the agent's own account ID during topic creation.
|
|
14
|
+
* @param network Network type ('mainnet' or 'testnet').
|
|
15
|
+
* @param logger Logger instance.
|
|
16
|
+
* @param exemptAccounts Optional array of account IDs exempt from this fee.
|
|
17
|
+
* @returns A configured FeeConfigBuilder instance.
|
|
18
|
+
*/
|
|
19
|
+
static forHbar(hbarAmount, collectorAccountId, network, logger, exemptAccounts = []) {
|
|
20
|
+
const builder = new FeeConfigBuilder({
|
|
21
|
+
network,
|
|
22
|
+
logger,
|
|
23
|
+
defaultCollectorAccountId: collectorAccountId
|
|
24
|
+
});
|
|
25
|
+
return builder.addHbarFee(hbarAmount, collectorAccountId, exemptAccounts);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Static factory method to create a FeeConfigBuilder with a single token fee.
|
|
29
|
+
* Automatically fetches token decimals if not provided.
|
|
30
|
+
* @param tokenAmount Amount of tokens.
|
|
31
|
+
* @param feeTokenId Token ID for the fee.
|
|
32
|
+
* @param collectorAccountId Optional account ID to collect the fee. If omitted or undefined, defaults to the agent's own account ID during topic creation.
|
|
33
|
+
* @param network Network type ('mainnet' or 'testnet').
|
|
34
|
+
* @param logger Logger instance.
|
|
35
|
+
* @param exemptAccounts Optional array of account IDs exempt from this fee.
|
|
36
|
+
* @param decimals Optional decimals for the token (fetched if omitted).
|
|
37
|
+
* @returns A Promise resolving to a configured FeeConfigBuilder instance.
|
|
38
|
+
*/
|
|
39
|
+
static async forToken(tokenAmount, feeTokenId, collectorAccountId, network, logger, exemptAccounts = [], decimals) {
|
|
40
|
+
const builder = new FeeConfigBuilder({
|
|
41
|
+
network,
|
|
42
|
+
logger,
|
|
43
|
+
defaultCollectorAccountId: collectorAccountId
|
|
44
|
+
});
|
|
45
|
+
await builder.addTokenFee(
|
|
46
|
+
tokenAmount,
|
|
47
|
+
feeTokenId,
|
|
48
|
+
collectorAccountId,
|
|
49
|
+
decimals,
|
|
50
|
+
exemptAccounts
|
|
51
|
+
);
|
|
52
|
+
return builder;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Adds an HBAR fee configuration to the builder.
|
|
56
|
+
* Allows chaining multiple fee additions.
|
|
57
|
+
* @param hbarAmount The amount in HBAR (e.g., 0.5).
|
|
58
|
+
* @param collectorAccountId Optional. The account ID to collect this fee. If omitted, defaults to the agent's own account ID during topic creation.
|
|
59
|
+
* @param exemptAccountIds Optional. Accounts specifically exempt from *this* HBAR fee.
|
|
60
|
+
* @returns This FeeConfigBuilder instance for chaining.
|
|
61
|
+
*/
|
|
62
|
+
addHbarFee(hbarAmount, collectorAccountId, exemptAccountIds = []) {
|
|
63
|
+
if (hbarAmount <= 0) {
|
|
64
|
+
throw new Error("HBAR amount must be greater than zero");
|
|
65
|
+
}
|
|
66
|
+
this.customFees.push({
|
|
67
|
+
feeAmount: {
|
|
68
|
+
amount: hbarAmount * 1e8,
|
|
69
|
+
decimals: 0
|
|
70
|
+
},
|
|
71
|
+
feeCollectorAccountId: collectorAccountId || this.defaultCollectorAccountId,
|
|
72
|
+
feeTokenId: void 0,
|
|
73
|
+
exemptAccounts: [...exemptAccountIds],
|
|
74
|
+
type: CustomFeeType.FIXED_FEE
|
|
75
|
+
});
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Adds a token fee configuration to the builder.
|
|
80
|
+
* Allows chaining multiple fee additions.
|
|
81
|
+
* Fetches token decimals automatically if not provided.
|
|
82
|
+
* @param tokenAmount The amount of the specified token.
|
|
83
|
+
* @param feeTokenId The ID of the token to charge the fee in.
|
|
84
|
+
* @param collectorAccountId Optional. The account ID to collect this fee. If omitted, defaults to the agent's own account ID during topic creation.
|
|
85
|
+
* @param decimals Optional. The number of decimals for the token. If omitted, it will be fetched from the mirror node.
|
|
86
|
+
* @param exemptAccountIds Optional. Accounts specifically exempt from *this* token fee.
|
|
87
|
+
* @returns A Promise resolving to this FeeConfigBuilder instance for chaining.
|
|
88
|
+
*/
|
|
89
|
+
async addTokenFee(tokenAmount, feeTokenId, collectorAccountId, decimals, exemptAccountIds = []) {
|
|
90
|
+
if (tokenAmount <= 0) {
|
|
91
|
+
throw new Error("Token amount must be greater than zero");
|
|
92
|
+
}
|
|
93
|
+
if (!feeTokenId) {
|
|
94
|
+
throw new Error("Fee token ID is required when adding a token fee");
|
|
95
|
+
}
|
|
96
|
+
let finalDecimals = decimals;
|
|
97
|
+
if (finalDecimals === void 0) {
|
|
98
|
+
try {
|
|
99
|
+
const tokenInfo = await this.mirrorNode.getTokenInfo(feeTokenId);
|
|
100
|
+
if (tokenInfo?.decimals) {
|
|
101
|
+
finalDecimals = parseInt(tokenInfo.decimals, 10);
|
|
102
|
+
this.logger.info(
|
|
103
|
+
`Fetched decimals for ${feeTokenId}: ${finalDecimals}`
|
|
104
|
+
);
|
|
105
|
+
} else {
|
|
106
|
+
this.logger.warn(
|
|
107
|
+
`Could not fetch decimals for ${feeTokenId}, defaulting to 0.`
|
|
108
|
+
);
|
|
109
|
+
finalDecimals = 0;
|
|
110
|
+
}
|
|
111
|
+
} catch (error) {
|
|
112
|
+
this.logger.error(
|
|
113
|
+
`Error fetching decimals for ${feeTokenId}, defaulting to 0: ${error}`
|
|
114
|
+
);
|
|
115
|
+
finalDecimals = 0;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
this.customFees.push({
|
|
119
|
+
feeAmount: {
|
|
120
|
+
amount: tokenAmount * 10 ** finalDecimals,
|
|
121
|
+
decimals: finalDecimals
|
|
122
|
+
},
|
|
123
|
+
feeCollectorAccountId: collectorAccountId || this.defaultCollectorAccountId,
|
|
124
|
+
feeTokenId,
|
|
125
|
+
exemptAccounts: [...exemptAccountIds],
|
|
126
|
+
type: CustomFeeType.FIXED_FEE
|
|
127
|
+
});
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Builds the final TopicFeeConfig object.
|
|
132
|
+
* @returns The TopicFeeConfig containing all added custom fees and a consolidated list of unique exempt accounts.
|
|
133
|
+
* @throws Error if no fees have been added.
|
|
134
|
+
* @throws Error if more than 10 fees have been added.
|
|
135
|
+
*/
|
|
136
|
+
build() {
|
|
137
|
+
if (this.customFees.length === 0) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
"At least one fee must be added using addHbarFee/addTokenFee or created using forHbar/forToken"
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
if (this.customFees.length > 10) {
|
|
143
|
+
throw new Error("Maximum of 10 custom fees per topic allowed");
|
|
144
|
+
}
|
|
145
|
+
const allExemptAccounts = /* @__PURE__ */ new Set();
|
|
146
|
+
this.customFees.forEach((fee) => {
|
|
147
|
+
fee.exemptAccounts.forEach((account) => allExemptAccounts.add(account));
|
|
148
|
+
});
|
|
149
|
+
const resolvedCustomFees = this.customFees.map((fee) => ({
|
|
150
|
+
...fee,
|
|
151
|
+
feeCollectorAccountId: fee.feeCollectorAccountId || this.defaultCollectorAccountId
|
|
152
|
+
}));
|
|
153
|
+
return {
|
|
154
|
+
customFees: resolvedCustomFees,
|
|
155
|
+
exemptAccounts: Array.from(allExemptAccounts)
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
7
159
|
export {
|
|
8
|
-
|
|
160
|
+
FeeConfigBuilder
|
|
9
161
|
};
|
|
10
162
|
//# sourceMappingURL=standards-sdk.es141.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es141.js","sources":["../../src/fees/types.ts"],"sourcesContent":["export interface FeeConfigBuilderInterface {\n addHbarFee(\n hbarAmount: number,\n collectorAccountId?: string,\n exemptAccountIds?: string[],\n ): FeeConfigBuilderInterface;\n addTokenFee(\n tokenAmount: number,\n feeTokenId: string,\n collectorAccountId?: string,\n decimals?: number,\n exemptAccountIds?: string[],\n ): Promise<FeeConfigBuilderInterface>;\n build(): TopicFeeConfig;\n}\n\nexport enum CustomFeeType {\n FIXED_FEE = 'FIXED_FEE',\n FRACTIONAL_FEE = 'FRACTIONAL_FEE',\n ROYALTY_FEE = 'ROYALTY_FEE',\n}\n\nexport type FeeAmount = {\n amount: number;\n decimals?: number;\n};\n\nexport interface TokenFeeConfig {\n feeAmount: FeeAmount;\n feeCollectorAccountId: string;\n feeTokenId?: string;\n exemptAccounts: string[];\n type: CustomFeeType;\n}\n\nexport interface TopicFeeConfig {\n customFees: TokenFeeConfig[];\n exemptAccounts: string[];\n}\n"],"names":["CustomFeeType"],"mappings":"AAgBO,IAAK,kCAAAA,mBAAL;AACLA,iBAAA,WAAA,IAAY;AACZA,iBAAA,gBAAA,IAAiB;AACjBA,iBAAA,aAAA,IAAc;AAHJ,SAAAA;AAAA,GAAA,iBAAA,CAAA,CAAA;"}
|
|
1
|
+
{"version":3,"file":"standards-sdk.es141.js","sources":["../../src/fees/fee-config-builder.ts"],"sourcesContent":["import {\n FeeConfigBuilderInterface,\n TokenFeeConfig,\n TopicFeeConfig,\n CustomFeeType,\n} from './types';\nimport { HederaMirrorNode } from '../services/mirror-node';\nimport { Logger } from '../utils/logger';\nimport { NetworkType } from '../utils/types';\n\n/**\n * FeeConfigBuilder provides a fluent interface for creating fee configurations\n * for HCS-10 topics. This makes it easy to configure fees without dealing with\n * the complexity of the underlying fee structure.\n *\n * Example usage:\n *\n * // Super simple one-liner with the factory method\n * const simpleFeeConfig = FeeConfigBuilder.forHbar(5, '0.0.12345', NetworkType.TESTNET, new Logger(), ['0.0.67890']);\n *\n * // With multiple fees:\n * const multipleFeeConfig = new FeeConfigBuilder({\n * network: NetworkType.TESTNET,\n * logger: new Logger(),\n * defaultCollectorAccountId: '0.0.12345',\n * defaultExemptAccountIds: ['0.0.67890']\n * })\n * .withHbarFee(1) // 1 HBAR fee\n * .withTokenFee(10, '0.0.54321') // 10 units of token 0.0.54321\n * .build();\n *\n * With Agent Builder\n * const agent = new AgentBuilder()\n * .setName('Fee Collector Agent')\n * .setDescription('An agent that collects fees')\n * .setInboundTopicType(InboundTopicType.FEE_BASED)\n * .setFeeConfig(FeeConfigBuilder.forHbar(1, '0.0.12345', NetworkType.TESTNET, new Logger(), ['0.0.67890']))\n * .setNetwork('testnet')\n .build();\n\n * Directly with client\n * const client = new HCS10Client(config);\n * const connectionFeeConfig = new FeeConfigBuilder({\n * network: NetworkType.TESTNET,\n * logger: new Logger(),\n * defaultCollectorAccountId: client.getAccountAndSigner().accountId,\n * defaultExemptAccountIds: ['0.0.67890']\n * })\n * .withHbarFee(0.5) // 0.5 HBAR (simple!)\n * .build();\n\n * const result = await client.handleConnectionRequest(\n * inboundTopicId,\n * requestingAccountId,\n * connectionRequestId,\n * connectionFeeConfig\n * );\n*/\nexport interface FeeConfigBuilderOptions {\n network: NetworkType;\n logger: Logger;\n defaultCollectorAccountId?: string;\n}\n\nexport class FeeConfigBuilder implements FeeConfigBuilderInterface {\n private customFees: TokenFeeConfig[] = [];\n private mirrorNode: HederaMirrorNode;\n private logger: Logger;\n private defaultCollectorAccountId: string;\n\n constructor(options: FeeConfigBuilderOptions) {\n this.logger = options.logger;\n this.mirrorNode = new HederaMirrorNode(options.network, options.logger);\n this.defaultCollectorAccountId = options.defaultCollectorAccountId || '';\n }\n\n /**\n * Static factory method to create a FeeConfigBuilder with a single HBAR fee.\n * @param hbarAmount Amount in HBAR.\n * @param collectorAccountId Optional account ID to collect the fee. If omitted or undefined, defaults to the agent's own account ID during topic creation.\n * @param network Network type ('mainnet' or 'testnet').\n * @param logger Logger instance.\n * @param exemptAccounts Optional array of account IDs exempt from this fee.\n * @returns A configured FeeConfigBuilder instance.\n */\n static forHbar(\n hbarAmount: number,\n collectorAccountId: string | undefined,\n network: NetworkType,\n logger: Logger,\n exemptAccounts: string[] = [],\n ): FeeConfigBuilder {\n const builder = new FeeConfigBuilder({\n network,\n logger,\n defaultCollectorAccountId: collectorAccountId,\n });\n return builder.addHbarFee(hbarAmount, collectorAccountId, exemptAccounts);\n }\n\n /**\n * Static factory method to create a FeeConfigBuilder with a single token fee.\n * Automatically fetches token decimals if not provided.\n * @param tokenAmount Amount of tokens.\n * @param feeTokenId Token ID for the fee.\n * @param collectorAccountId Optional account ID to collect the fee. If omitted or undefined, defaults to the agent's own account ID during topic creation.\n * @param network Network type ('mainnet' or 'testnet').\n * @param logger Logger instance.\n * @param exemptAccounts Optional array of account IDs exempt from this fee.\n * @param decimals Optional decimals for the token (fetched if omitted).\n * @returns A Promise resolving to a configured FeeConfigBuilder instance.\n */\n static async forToken(\n tokenAmount: number,\n feeTokenId: string,\n collectorAccountId: string | undefined,\n network: NetworkType,\n logger: Logger,\n exemptAccounts: string[] = [],\n decimals?: number,\n ): Promise<FeeConfigBuilder> {\n const builder = new FeeConfigBuilder({\n network,\n logger,\n defaultCollectorAccountId: collectorAccountId,\n });\n await builder.addTokenFee(\n tokenAmount,\n feeTokenId,\n collectorAccountId,\n decimals,\n exemptAccounts,\n );\n return builder;\n }\n\n /**\n * Adds an HBAR fee configuration to the builder.\n * Allows chaining multiple fee additions.\n * @param hbarAmount The amount in HBAR (e.g., 0.5).\n * @param collectorAccountId Optional. The account ID to collect this fee. If omitted, defaults to the agent's own account ID during topic creation.\n * @param exemptAccountIds Optional. Accounts specifically exempt from *this* HBAR fee.\n * @returns This FeeConfigBuilder instance for chaining.\n */\n addHbarFee(\n hbarAmount: number,\n collectorAccountId?: string,\n exemptAccountIds: string[] = [],\n ): FeeConfigBuilder {\n if (hbarAmount <= 0) {\n throw new Error('HBAR amount must be greater than zero');\n }\n\n this.customFees.push({\n feeAmount: {\n amount: hbarAmount * 100_000_000,\n decimals: 0,\n },\n feeCollectorAccountId:\n collectorAccountId || this.defaultCollectorAccountId,\n feeTokenId: undefined,\n exemptAccounts: [...exemptAccountIds],\n type: CustomFeeType.FIXED_FEE,\n });\n\n return this;\n }\n\n /**\n * Adds a token fee configuration to the builder.\n * Allows chaining multiple fee additions.\n * Fetches token decimals automatically if not provided.\n * @param tokenAmount The amount of the specified token.\n * @param feeTokenId The ID of the token to charge the fee in.\n * @param collectorAccountId Optional. The account ID to collect this fee. If omitted, defaults to the agent's own account ID during topic creation.\n * @param decimals Optional. The number of decimals for the token. If omitted, it will be fetched from the mirror node.\n * @param exemptAccountIds Optional. Accounts specifically exempt from *this* token fee.\n * @returns A Promise resolving to this FeeConfigBuilder instance for chaining.\n */\n async addTokenFee(\n tokenAmount: number,\n feeTokenId: string,\n collectorAccountId?: string,\n decimals?: number,\n exemptAccountIds: string[] = [],\n ): Promise<FeeConfigBuilder> {\n if (tokenAmount <= 0) {\n throw new Error('Token amount must be greater than zero');\n }\n if (!feeTokenId) {\n throw new Error('Fee token ID is required when adding a token fee');\n }\n\n let finalDecimals = decimals;\n if (finalDecimals === undefined) {\n try {\n const tokenInfo = await this.mirrorNode.getTokenInfo(feeTokenId);\n if (tokenInfo?.decimals) {\n finalDecimals = parseInt(tokenInfo.decimals, 10);\n this.logger.info(\n `Fetched decimals for ${feeTokenId}: ${finalDecimals}`,\n );\n } else {\n this.logger.warn(\n `Could not fetch decimals for ${feeTokenId}, defaulting to 0.`,\n );\n finalDecimals = 0;\n }\n } catch (error) {\n this.logger.error(\n `Error fetching decimals for ${feeTokenId}, defaulting to 0: ${error}`,\n );\n finalDecimals = 0;\n }\n }\n\n this.customFees.push({\n feeAmount: {\n amount: tokenAmount * 10 ** finalDecimals,\n decimals: finalDecimals,\n },\n feeCollectorAccountId:\n collectorAccountId || this.defaultCollectorAccountId,\n feeTokenId: feeTokenId,\n exemptAccounts: [...exemptAccountIds],\n type: CustomFeeType.FIXED_FEE,\n });\n\n return this;\n }\n\n /**\n * Builds the final TopicFeeConfig object.\n * @returns The TopicFeeConfig containing all added custom fees and a consolidated list of unique exempt accounts.\n * @throws Error if no fees have been added.\n * @throws Error if more than 10 fees have been added.\n */\n build(): TopicFeeConfig {\n if (this.customFees.length === 0) {\n throw new Error(\n 'At least one fee must be added using addHbarFee/addTokenFee or created using forHbar/forToken',\n );\n }\n\n if (this.customFees.length > 10) {\n throw new Error('Maximum of 10 custom fees per topic allowed');\n }\n\n const allExemptAccounts = new Set<string>();\n this.customFees.forEach(fee => {\n fee.exemptAccounts.forEach(account => allExemptAccounts.add(account));\n });\n\n const resolvedCustomFees = this.customFees.map(fee => ({\n ...fee,\n feeCollectorAccountId:\n fee.feeCollectorAccountId || this.defaultCollectorAccountId,\n }));\n\n return {\n customFees: resolvedCustomFees,\n exemptAccounts: Array.from(allExemptAccounts),\n };\n }\n}\n"],"names":[],"mappings":";;AAgEO,MAAM,iBAAsD;AAAA,EAMjE,YAAY,SAAkC;AAL9C,SAAQ,aAA+B,CAAA;AAMrC,SAAK,SAAS,QAAQ;AACtB,SAAK,aAAa,IAAI,iBAAiB,QAAQ,SAAS,QAAQ,MAAM;AACtE,SAAK,4BAA4B,QAAQ,6BAA6B;AAAA,EACxE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,OAAO,QACL,YACA,oBACA,SACA,QACA,iBAA2B,IACT;AAClB,UAAM,UAAU,IAAI,iBAAiB;AAAA,MACnC;AAAA,MACA;AAAA,MACA,2BAA2B;AAAA,IAAA,CAC5B;AACD,WAAO,QAAQ,WAAW,YAAY,oBAAoB,cAAc;AAAA,EAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,aAAa,SACX,aACA,YACA,oBACA,SACA,QACA,iBAA2B,CAAA,GAC3B,UAC2B;AAC3B,UAAM,UAAU,IAAI,iBAAiB;AAAA,MACnC;AAAA,MACA;AAAA,MACA,2BAA2B;AAAA,IAAA,CAC5B;AACD,UAAM,QAAQ;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAEF,WAAO;AAAA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QAC5B,UAAU;AAAA,MAAA;AAAA,MAEZ,uBACE,sBAAsB,KAAK;AAAA,MAC7B;AAAA,MACA,gBAAgB,CAAC,GAAG,gBAAgB;AAAA,MACpC,MAAM,cAAc;AAAA,IAAA,CACrB;AAED,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QAAwB;AACtB,QAAI,KAAK,WAAW,WAAW,GAAG;AAChC,YAAM,IAAI;AAAA,QACR;AAAA,MAAA;AAAA,IAEJ;AAEA,QAAI,KAAK,WAAW,SAAS,IAAI;AAC/B,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AAEA,UAAM,wCAAwB,IAAA;AAC9B,SAAK,WAAW,QAAQ,CAAA,QAAO;AAC7B,UAAI,eAAe,QAAQ,CAAA,YAAW,kBAAkB,IAAI,OAAO,CAAC;AAAA,IACtE,CAAC;AAED,UAAM,qBAAqB,KAAK,WAAW,IAAI,CAAA,SAAQ;AAAA,MACrD,GAAG;AAAA,MACH,uBACE,IAAI,yBAAyB,KAAK;AAAA,IAAA,EACpC;AAEF,WAAO;AAAA,MACL,YAAY;AAAA,MACZ,gBAAgB,MAAM,KAAK,iBAAiB;AAAA,IAAA;AAAA,EAEhD;AACF;"}
|
|
@@ -1,89 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
static getInstance() {
|
|
9
|
-
if (!ContentResolverRegistryImpl._instance) {
|
|
10
|
-
ContentResolverRegistryImpl._instance = new ContentResolverRegistryImpl();
|
|
11
|
-
}
|
|
12
|
-
return ContentResolverRegistryImpl._instance;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Register a content resolver (typically called by ContentStoreManager)
|
|
16
|
-
*/
|
|
17
|
-
register(resolver) {
|
|
18
|
-
if (this.resolver) {
|
|
19
|
-
this.logger.warn("Resolver already registered, replacing existing");
|
|
20
|
-
}
|
|
21
|
-
this.resolver = resolver;
|
|
22
|
-
this.logger.info("Content resolver registered");
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Get the registered content resolver
|
|
26
|
-
*/
|
|
27
|
-
getResolver() {
|
|
28
|
-
return this.resolver;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Check if a resolver is available
|
|
32
|
-
*/
|
|
33
|
-
isAvailable() {
|
|
34
|
-
return this.resolver !== null;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Unregister the current resolver
|
|
38
|
-
*/
|
|
39
|
-
unregister() {
|
|
40
|
-
if (this.resolver) {
|
|
41
|
-
this.resolver = null;
|
|
42
|
-
this.logger.info("Content resolver unregistered");
|
|
43
|
-
this.onUnavailableCallbacks.forEach((callback) => {
|
|
44
|
-
try {
|
|
45
|
-
callback();
|
|
46
|
-
} catch (error) {
|
|
47
|
-
this.logger.error("Error in unavailable callback:", error);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Register callback for when resolver becomes unavailable
|
|
54
|
-
*/
|
|
55
|
-
onUnavailable(callback) {
|
|
56
|
-
this.onUnavailableCallbacks.push(callback);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Remove unavailable callback
|
|
60
|
-
*/
|
|
61
|
-
offUnavailable(callback) {
|
|
62
|
-
const index = this.onUnavailableCallbacks.indexOf(callback);
|
|
63
|
-
if (index !== -1) {
|
|
64
|
-
this.onUnavailableCallbacks.splice(index, 1);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Execute operation with resolver or fallback
|
|
69
|
-
*/
|
|
70
|
-
async withResolver(operation, fallback) {
|
|
71
|
-
if (this.resolver) {
|
|
72
|
-
try {
|
|
73
|
-
return await operation(this.resolver);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
this.logger.warn("Resolver operation failed, using fallback:", error);
|
|
76
|
-
return await fallback();
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
this.logger.warn("No resolver available, using fallback");
|
|
80
|
-
return await fallback();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
const ContentResolverRegistry = ContentResolverRegistryImpl.getInstance();
|
|
1
|
+
var CustomFeeType = /* @__PURE__ */ ((CustomFeeType2) => {
|
|
2
|
+
CustomFeeType2["FIXED_FEE"] = "FIXED_FEE";
|
|
3
|
+
CustomFeeType2["FRACTIONAL_FEE"] = "FRACTIONAL_FEE";
|
|
4
|
+
CustomFeeType2["ROYALTY_FEE"] = "ROYALTY_FEE";
|
|
5
|
+
return CustomFeeType2;
|
|
6
|
+
})(CustomFeeType || {});
|
|
85
7
|
export {
|
|
86
|
-
|
|
87
|
-
ContentResolverRegistryImpl
|
|
8
|
+
CustomFeeType
|
|
88
9
|
};
|
|
89
10
|
//# sourceMappingURL=standards-sdk.es142.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es142.js","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"standards-sdk.es142.js","sources":["../../src/fees/types.ts"],"sourcesContent":["export interface FeeConfigBuilderInterface {\n addHbarFee(\n hbarAmount: number,\n collectorAccountId?: string,\n exemptAccountIds?: string[],\n ): FeeConfigBuilderInterface;\n addTokenFee(\n tokenAmount: number,\n feeTokenId: string,\n collectorAccountId?: string,\n decimals?: number,\n exemptAccountIds?: string[],\n ): Promise<FeeConfigBuilderInterface>;\n build(): TopicFeeConfig;\n}\n\nexport enum CustomFeeType {\n FIXED_FEE = 'FIXED_FEE',\n FRACTIONAL_FEE = 'FRACTIONAL_FEE',\n ROYALTY_FEE = 'ROYALTY_FEE',\n}\n\nexport type FeeAmount = {\n amount: number;\n decimals?: number;\n};\n\nexport interface TokenFeeConfig {\n feeAmount: FeeAmount;\n feeCollectorAccountId: string;\n feeTokenId?: string;\n exemptAccounts: string[];\n type: CustomFeeType;\n}\n\nexport interface TopicFeeConfig {\n customFees: TokenFeeConfig[];\n exemptAccounts: string[];\n}\n"],"names":["CustomFeeType"],"mappings":"AAgBO,IAAK,kCAAAA,mBAAL;AACLA,iBAAA,WAAA,IAAY;AACZA,iBAAA,gBAAA,IAAiB;AACjBA,iBAAA,aAAA,IAAc;AAHJ,SAAAA;AAAA,GAAA,iBAAA,CAAA,CAAA;"}
|
|
@@ -1,68 +1,89 @@
|
|
|
1
1
|
import { Logger } from "./standards-sdk.es106.js";
|
|
2
|
-
|
|
3
|
-
class ContentStoreServiceImpl {
|
|
2
|
+
class ContentResolverRegistryImpl {
|
|
4
3
|
constructor() {
|
|
5
|
-
this.
|
|
6
|
-
this.
|
|
4
|
+
this.resolver = null;
|
|
5
|
+
this.onUnavailableCallbacks = [];
|
|
6
|
+
this.logger = Logger.getInstance({ module: "ContentResolverRegistry" });
|
|
7
7
|
}
|
|
8
8
|
static getInstance() {
|
|
9
|
-
if (!
|
|
10
|
-
|
|
9
|
+
if (!ContentResolverRegistryImpl._instance) {
|
|
10
|
+
ContentResolverRegistryImpl._instance = new ContentResolverRegistryImpl();
|
|
11
11
|
}
|
|
12
|
-
return
|
|
12
|
+
return ContentResolverRegistryImpl._instance;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Register a content resolver (typically called by ContentStoreManager)
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
if (this.
|
|
19
|
-
this.logger.warn("
|
|
17
|
+
register(resolver) {
|
|
18
|
+
if (this.resolver) {
|
|
19
|
+
this.logger.warn("Resolver already registered, replacing existing");
|
|
20
20
|
}
|
|
21
|
-
this.
|
|
22
|
-
this.logger.info("Content
|
|
21
|
+
this.resolver = resolver;
|
|
22
|
+
this.logger.info("Content resolver registered");
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* Get the content
|
|
25
|
+
* Get the registered content resolver
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
|
-
return this.
|
|
27
|
+
getResolver() {
|
|
28
|
+
return this.resolver;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Check if a resolver is available
|
|
32
32
|
*/
|
|
33
|
-
|
|
34
|
-
this.
|
|
35
|
-
this.logger.info("Content store disposed");
|
|
33
|
+
isAvailable() {
|
|
34
|
+
return this.resolver !== null;
|
|
36
35
|
}
|
|
37
36
|
/**
|
|
38
|
-
*
|
|
37
|
+
* Unregister the current resolver
|
|
39
38
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
unregister() {
|
|
40
|
+
if (this.resolver) {
|
|
41
|
+
this.resolver = null;
|
|
42
|
+
this.logger.info("Content resolver unregistered");
|
|
43
|
+
this.onUnavailableCallbacks.forEach((callback) => {
|
|
44
|
+
try {
|
|
45
|
+
callback();
|
|
46
|
+
} catch (error) {
|
|
47
|
+
this.logger.error("Error in unavailable callback:", error);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
42
51
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Register callback for when resolver becomes unavailable
|
|
54
|
+
*/
|
|
55
|
+
onUnavailable(callback) {
|
|
56
|
+
this.onUnavailableCallbacks.push(callback);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Remove unavailable callback
|
|
60
|
+
*/
|
|
61
|
+
offUnavailable(callback) {
|
|
62
|
+
const index = this.onUnavailableCallbacks.indexOf(callback);
|
|
63
|
+
if (index !== -1) {
|
|
64
|
+
this.onUnavailableCallbacks.splice(index, 1);
|
|
65
|
+
}
|
|
49
66
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Execute operation with resolver or fallback
|
|
69
|
+
*/
|
|
70
|
+
async withResolver(operation, fallback) {
|
|
71
|
+
if (this.resolver) {
|
|
72
|
+
try {
|
|
73
|
+
return await operation(this.resolver);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
this.logger.warn("Resolver operation failed, using fallback:", error);
|
|
76
|
+
return await fallback();
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
this.logger.warn("No resolver available, using fallback");
|
|
80
|
+
return await fallback();
|
|
81
|
+
}
|
|
53
82
|
}
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
function shouldUseReference(content) {
|
|
57
|
-
const size = typeof content === "string" ? Buffer.byteLength(content, "utf8") : content.length;
|
|
58
|
-
return size > REFERENCE_THRESHOLD;
|
|
59
83
|
}
|
|
60
|
-
const
|
|
84
|
+
const ContentResolverRegistry = ContentResolverRegistryImpl.getInstance();
|
|
61
85
|
export {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
REFERENCE_THRESHOLD,
|
|
65
|
-
extractReferenceId,
|
|
66
|
-
shouldUseReference
|
|
86
|
+
ContentResolverRegistry,
|
|
87
|
+
ContentResolverRegistryImpl
|
|
67
88
|
};
|
|
68
89
|
//# sourceMappingURL=standards-sdk.es143.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es143.js","sources":["../../src/content-store/
|
|
1
|
+
{"version":3,"file":"standards-sdk.es143.js","sources":["../../src/content-store/ContentResolverRegistry.ts"],"sourcesContent":["/**\n * Content Resolver Registry\n *\n * Dependency injection registry for content resolvers.\n * Allows tools to access content resolution without circular dependencies.\n */\n\nimport type { ContentResolverInterface } from './types';\nimport { Logger } from '../utils/logger';\n\nexport class ContentResolverRegistryImpl {\n private static _instance: ContentResolverRegistryImpl;\n private resolver: ContentResolverInterface | null = null;\n private onUnavailableCallbacks: (() => void)[] = [];\n private logger = Logger.getInstance({ module: 'ContentResolverRegistry' });\n\n static getInstance(): ContentResolverRegistryImpl {\n if (!ContentResolverRegistryImpl._instance) {\n ContentResolverRegistryImpl._instance = new ContentResolverRegistryImpl();\n }\n return ContentResolverRegistryImpl._instance;\n }\n\n /**\n * Register a content resolver (typically called by ContentStoreManager)\n */\n register(resolver: ContentResolverInterface): void {\n if (this.resolver) {\n this.logger.warn('Resolver already registered, replacing existing');\n }\n this.resolver = resolver;\n this.logger.info('Content resolver registered');\n }\n\n /**\n * Get the registered content resolver\n */\n getResolver(): ContentResolverInterface | null {\n return this.resolver;\n }\n\n /**\n * Check if a resolver is available\n */\n isAvailable(): boolean {\n return this.resolver !== null;\n }\n\n /**\n * Unregister the current resolver\n */\n unregister(): void {\n if (this.resolver) {\n this.resolver = null;\n this.logger.info('Content resolver unregistered');\n this.onUnavailableCallbacks.forEach(callback => {\n try {\n callback();\n } catch (error) {\n this.logger.error('Error in unavailable callback:', error);\n }\n });\n }\n }\n\n /**\n * Register callback for when resolver becomes unavailable\n */\n onUnavailable(callback: () => void): void {\n this.onUnavailableCallbacks.push(callback);\n }\n\n /**\n * Remove unavailable callback\n */\n offUnavailable(callback: () => void): void {\n const index = this.onUnavailableCallbacks.indexOf(callback);\n if (index !== -1) {\n this.onUnavailableCallbacks.splice(index, 1);\n }\n }\n\n /**\n * Execute operation with resolver or fallback\n */\n async withResolver<T>(\n operation: (resolver: ContentResolverInterface) => Promise<T>,\n fallback: () => Promise<T>,\n ): Promise<T> {\n if (this.resolver) {\n try {\n return await operation(this.resolver);\n } catch (error) {\n this.logger.warn('Resolver operation failed, using fallback:', error);\n return await fallback();\n }\n } else {\n this.logger.warn('No resolver available, using fallback');\n return await fallback();\n }\n }\n}\n\nexport const ContentResolverRegistry =\n ContentResolverRegistryImpl.getInstance();\n"],"names":[],"mappings":";AAUO,MAAM,4BAA4B;AAAA,EAAlC,cAAA;AAEL,SAAQ,WAA4C;AACpD,SAAQ,yBAAyC,CAAA;AACjD,SAAQ,SAAS,OAAO,YAAY,EAAE,QAAQ,2BAA2B;AAAA,EAAA;AAAA,EAEzE,OAAO,cAA2C;AAChD,QAAI,CAAC,4BAA4B,WAAW;AAC1C,kCAA4B,YAAY,IAAI,4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,EACF;AACF;AAEO,MAAM,0BACX,4BAA4B,YAAA;"}
|
|
@@ -1,31 +1,68 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { Logger } from "./standards-sdk.es106.js";
|
|
2
|
+
const REFERENCE_THRESHOLD = 50 * 1024;
|
|
3
|
+
class ContentStoreServiceImpl {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.contentStore = null;
|
|
6
|
+
this.logger = Logger.getInstance({ module: "ContentStoreService" });
|
|
7
|
+
}
|
|
8
|
+
static getInstance() {
|
|
9
|
+
if (!ContentStoreServiceImpl._instance) {
|
|
10
|
+
ContentStoreServiceImpl._instance = new ContentStoreServiceImpl();
|
|
11
|
+
}
|
|
12
|
+
return ContentStoreServiceImpl._instance;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Set the content store instance
|
|
16
|
+
*/
|
|
17
|
+
async setInstance(store) {
|
|
18
|
+
if (this.contentStore) {
|
|
19
|
+
this.logger.warn("Content store already set, replacing");
|
|
20
|
+
}
|
|
21
|
+
this.contentStore = store;
|
|
22
|
+
this.logger.info("Content store instance set");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get the content store instance
|
|
26
|
+
*/
|
|
27
|
+
getInstance() {
|
|
28
|
+
return this.contentStore;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Clear the content store instance
|
|
32
|
+
*/
|
|
33
|
+
dispose() {
|
|
34
|
+
this.contentStore = null;
|
|
35
|
+
this.logger.info("Content store disposed");
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Check if content store is available
|
|
39
|
+
*/
|
|
40
|
+
isAvailable() {
|
|
41
|
+
return this.contentStore !== null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function extractReferenceId(input) {
|
|
45
|
+
const trimmed = input.trim();
|
|
46
|
+
const exactMatch = trimmed.match(/^content-ref:([a-f0-9]+)$/);
|
|
47
|
+
if (exactMatch) {
|
|
48
|
+
return exactMatch[1];
|
|
49
|
+
}
|
|
50
|
+
const embeddedMatch = trimmed.match(/content-ref:([a-f0-9]+)/);
|
|
51
|
+
if (embeddedMatch) {
|
|
52
|
+
return embeddedMatch[1];
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
function shouldUseReference(content) {
|
|
57
|
+
const size = typeof content === "string" ? Buffer.byteLength(content, "utf8") : content.length;
|
|
58
|
+
return size > REFERENCE_THRESHOLD;
|
|
59
|
+
}
|
|
60
|
+
const ContentStoreService = ContentStoreServiceImpl.getInstance();
|
|
10
61
|
export {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
IssuerRegistry,
|
|
17
|
-
ResolverRegistry,
|
|
18
|
-
canonicalizeAgentData,
|
|
19
|
-
createUaid,
|
|
20
|
-
defaultIssuerRegistry,
|
|
21
|
-
defaultResolverRegistry,
|
|
22
|
-
isEip155Caip10,
|
|
23
|
-
isHederaCaip10,
|
|
24
|
-
isHederaNetwork,
|
|
25
|
-
parseHcs14Did,
|
|
26
|
-
parseHederaCaip10,
|
|
27
|
-
registerDefaultResolvers,
|
|
28
|
-
toEip155Caip10,
|
|
29
|
-
toHederaCaip10
|
|
62
|
+
ContentStoreService,
|
|
63
|
+
ContentStoreServiceImpl,
|
|
64
|
+
REFERENCE_THRESHOLD,
|
|
65
|
+
extractReferenceId,
|
|
66
|
+
shouldUseReference
|
|
30
67
|
};
|
|
31
68
|
//# sourceMappingURL=standards-sdk.es144.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es144.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"standards-sdk.es144.js","sources":["../../src/content-store/ContentStoreService.ts"],"sourcesContent":["/**\n * Content Store Service\n *\n * Provides utility functions for content storage and reference handling.\n */\n\nimport type { ContentStoreInterface } from './types';\nimport { Logger } from '../utils/logger';\n\n/**\n * Maximum content size before using references (50KB)\n */\nexport const REFERENCE_THRESHOLD = 50 * 1024;\n\n/**\n * Content store service for managing large content\n */\nexport class ContentStoreServiceImpl {\n private static _instance: ContentStoreServiceImpl;\n private contentStore: ContentStoreInterface | null = null;\n private logger = Logger.getInstance({ module: 'ContentStoreService' });\n\n static getInstance(): ContentStoreServiceImpl {\n if (!ContentStoreServiceImpl._instance) {\n ContentStoreServiceImpl._instance = new ContentStoreServiceImpl();\n }\n return ContentStoreServiceImpl._instance;\n }\n\n /**\n * Set the content store instance\n */\n async setInstance(store: ContentStoreInterface): Promise<void> {\n if (this.contentStore) {\n this.logger.warn('Content store already set, replacing');\n }\n this.contentStore = store;\n this.logger.info('Content store instance set');\n }\n\n /**\n * Get the content store instance\n */\n getInstance(): ContentStoreInterface | null {\n return this.contentStore;\n }\n\n /**\n * Clear the content store instance\n */\n dispose(): void {\n this.contentStore = null;\n this.logger.info('Content store disposed');\n }\n\n /**\n * Check if content store is available\n */\n isAvailable(): boolean {\n return this.contentStore !== null;\n }\n}\n\n/**\n * Extract reference ID from input string\n */\nexport function extractReferenceId(input: string): string | null {\n const trimmed = input.trim();\n\n const exactMatch = trimmed.match(/^content-ref:([a-f0-9]+)$/);\n if (exactMatch) {\n return exactMatch[1];\n }\n\n const embeddedMatch = trimmed.match(/content-ref:([a-f0-9]+)/);\n if (embeddedMatch) {\n return embeddedMatch[1];\n }\n\n return null;\n}\n\n/**\n * Check if content should use reference based on size\n */\nexport function shouldUseReference(content: string | Buffer): boolean {\n const size =\n typeof content === 'string'\n ? Buffer.byteLength(content, 'utf8')\n : content.length;\n\n return size > REFERENCE_THRESHOLD;\n}\n\nexport const ContentStoreService = ContentStoreServiceImpl.getInstance();\n"],"names":[],"mappings":";AAYO,MAAM,sBAAsB,KAAK;AAKjC,MAAM,wBAAwB;AAAA,EAA9B,c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