@hashgraphonline/standards-sdk 0.1.141-canary.7 → 0.1.141-canary.9
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/services/registry-broker/client.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/schemas.d.ts +22 -22
- package/dist/cjs/services/registry-broker/schemas.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/services/registry-broker/client.d.ts.map +1 -1
- package/dist/es/services/registry-broker/schemas.d.ts +22 -22
- package/dist/es/services/registry-broker/schemas.d.ts.map +1 -1
- package/dist/es/standards-sdk.es101.js +1 -1
- package/dist/es/standards-sdk.es103.js +1 -1
- package/dist/es/standards-sdk.es109.js +2 -2
- package/dist/es/standards-sdk.es110.js +5 -5
- package/dist/es/standards-sdk.es12.js +1 -1
- package/dist/es/standards-sdk.es120.js +1 -1
- package/dist/es/standards-sdk.es121.js +1 -1
- package/dist/es/standards-sdk.es122.js +5 -5
- package/dist/es/standards-sdk.es124.js +1 -1
- package/dist/es/standards-sdk.es125.js +1 -1
- package/dist/es/standards-sdk.es127.js +13 -3
- package/dist/es/standards-sdk.es127.js.map +1 -1
- package/dist/es/standards-sdk.es128.js +1 -2
- package/dist/es/standards-sdk.es128.js.map +1 -1
- package/dist/es/standards-sdk.es13.js +1 -1
- package/dist/es/standards-sdk.es135.js +134 -13
- package/dist/es/standards-sdk.es135.js.map +1 -1
- package/dist/es/standards-sdk.es136.js +37 -133
- package/dist/es/standards-sdk.es136.js.map +1 -1
- package/dist/es/standards-sdk.es137.js +50 -36
- package/dist/es/standards-sdk.es137.js.map +1 -1
- package/dist/es/standards-sdk.es138.js +64 -760
- package/dist/es/standards-sdk.es138.js.map +1 -1
- package/dist/es/standards-sdk.es139.js +746 -12254
- package/dist/es/standards-sdk.es139.js.map +1 -1
- package/dist/es/standards-sdk.es140.js +12271 -53
- package/dist/es/standards-sdk.es140.js.map +1 -1
- package/dist/es/standards-sdk.es141.js +161 -53
- package/dist/es/standards-sdk.es141.js.map +1 -1
- package/dist/es/standards-sdk.es142.js +289 -139
- package/dist/es/standards-sdk.es142.js.map +1 -1
- package/dist/es/standards-sdk.es143.js +298 -274
- package/dist/es/standards-sdk.es143.js.map +1 -1
- package/dist/es/standards-sdk.es144.js +369 -262
- package/dist/es/standards-sdk.es144.js.map +1 -1
- package/dist/es/standards-sdk.es145.js +194 -316
- package/dist/es/standards-sdk.es145.js.map +1 -1
- package/dist/es/standards-sdk.es146.js +64 -319
- package/dist/es/standards-sdk.es146.js.map +1 -1
- package/dist/es/standards-sdk.es147.js +15 -74
- package/dist/es/standards-sdk.es147.js.map +1 -1
- package/dist/es/standards-sdk.es17.js +2 -2
- package/dist/es/standards-sdk.es19.js +5 -5
- package/dist/es/standards-sdk.es20.js +3 -3
- package/dist/es/standards-sdk.es23.js +1 -1
- package/dist/es/standards-sdk.es28.js +4 -4
- 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 -3
- 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 -3
- 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 -2
- 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.es87.js +1 -1
- package/dist/es/standards-sdk.es91.js +1 -1
- package/dist/es/standards-sdk.es92.js +1 -1
- package/dist/es/standards-sdk.es97.js +1 -1
- package/dist/es/standards-sdk.es99.js +1 -1
- package/package.json +63 -61
|
@@ -57,8 +57,7 @@ const loadHashgraphSdk = () => {
|
|
|
57
57
|
return cachedSdk;
|
|
58
58
|
}
|
|
59
59
|
const metaUrl = typeof import.meta !== "undefined" && typeof import.meta.url === "string" ? import.meta.url : void 0;
|
|
60
|
-
const
|
|
61
|
-
const loader = globalRequire ?? createRequire(metaUrl ?? `${process.cwd()}/.hol-rb-client.cjs`);
|
|
60
|
+
const loader = createRequire(metaUrl ?? `${process.cwd()}/.hol-rb-client.cjs`);
|
|
62
61
|
try {
|
|
63
62
|
const resolved = loader("@hashgraph/sdk");
|
|
64
63
|
cachedSdk = resolved;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es128.js","sources":["../../src/services/registry-broker/private-key-signer.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport type {\n Signer,\n AccountBalance,\n AccountInfo,\n Transaction,\n TransactionRecord,\n SignerSignature,\n} from '@hashgraph/sdk';\n\nconst unsupported = (method: string): Error =>\n new Error(`${method} is not supported by the in-memory signer`);\n\nexport interface PrivateKeySignerOptions {\n accountId: string;\n privateKey: string;\n network: 'mainnet' | 'testnet';\n}\n\nexport const createPrivateKeySigner = (\n options: PrivateKeySignerOptions,\n): Signer => {\n const sdk = loadHashgraphSdk();\n const { AccountId, LedgerId, PrivateKey, SignerSignature } = sdk;\n if (!options.privateKey) {\n throw new Error('privateKey is required to create a ledger signer.');\n }\n if (!options.accountId) {\n throw new Error('accountId is required to create a ledger signer.');\n }\n const accountId = AccountId.fromString(options.accountId);\n const privateKey = PrivateKey.fromString(options.privateKey);\n const ledgerId = LedgerId.fromString(options.network);\n\n return {\n getLedgerId: () => ledgerId,\n getAccountId: () => accountId,\n getAccountKey: () => privateKey.publicKey,\n getNetwork: () => ({}),\n getMirrorNetwork: () => [],\n sign: async (messages: Uint8Array[]): Promise<SignerSignature[]> =>\n Promise.all(\n messages.map(async message => {\n const signature = await privateKey.sign(message);\n return new SignerSignature({\n publicKey: privateKey.publicKey,\n signature,\n accountId,\n });\n }),\n ),\n getAccountBalance: async (): Promise<AccountBalance> => {\n throw unsupported('getAccountBalance');\n },\n getAccountInfo: async (): Promise<AccountInfo> => {\n throw unsupported('getAccountInfo');\n },\n getAccountRecords: async (): Promise<TransactionRecord[]> => {\n throw unsupported('getAccountRecords');\n },\n signTransaction: async <T extends Transaction>(_: T): Promise<T> => {\n throw unsupported('signTransaction');\n },\n checkTransaction: async <T extends Transaction>(_: T): Promise<T> => {\n throw unsupported('checkTransaction');\n },\n populateTransaction: async <T extends Transaction>(_: T): Promise<T> => {\n throw unsupported('populateTransaction');\n },\n call: async <RequestT, ResponseT, OutputT>(\n _request: unknown,\n ): Promise<OutputT> => {\n throw unsupported('call');\n },\n };\n};\n\ntype HashgraphSdk = typeof import('@hashgraph/sdk');\n\nlet cachedSdk: HashgraphSdk | null = null;\n\nconst loadHashgraphSdk = (): HashgraphSdk => {\n if (cachedSdk) {\n return cachedSdk;\n }\n const metaUrl =\n typeof import.meta !== 'undefined' &&\n typeof (import.meta as { url?: string }).url === 'string'\n ? (import.meta as { url: string }).url\n : undefined;\n const
|
|
1
|
+
{"version":3,"file":"standards-sdk.es128.js","sources":["../../src/services/registry-broker/private-key-signer.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport type {\n Signer,\n AccountBalance,\n AccountInfo,\n Transaction,\n TransactionRecord,\n SignerSignature,\n} from '@hashgraph/sdk';\n\nconst unsupported = (method: string): Error =>\n new Error(`${method} is not supported by the in-memory signer`);\n\nexport interface PrivateKeySignerOptions {\n accountId: string;\n privateKey: string;\n network: 'mainnet' | 'testnet';\n}\n\nexport const createPrivateKeySigner = (\n options: PrivateKeySignerOptions,\n): Signer => {\n const sdk = loadHashgraphSdk();\n const { AccountId, LedgerId, PrivateKey, SignerSignature } = sdk;\n if (!options.privateKey) {\n throw new Error('privateKey is required to create a ledger signer.');\n }\n if (!options.accountId) {\n throw new Error('accountId is required to create a ledger signer.');\n }\n const accountId = AccountId.fromString(options.accountId);\n const privateKey = PrivateKey.fromString(options.privateKey);\n const ledgerId = LedgerId.fromString(options.network);\n\n return {\n getLedgerId: () => ledgerId,\n getAccountId: () => accountId,\n getAccountKey: () => privateKey.publicKey,\n getNetwork: () => ({}),\n getMirrorNetwork: () => [],\n sign: async (messages: Uint8Array[]): Promise<SignerSignature[]> =>\n Promise.all(\n messages.map(async message => {\n const signature = await privateKey.sign(message);\n return new SignerSignature({\n publicKey: privateKey.publicKey,\n signature,\n accountId,\n });\n }),\n ),\n getAccountBalance: async (): Promise<AccountBalance> => {\n throw unsupported('getAccountBalance');\n },\n getAccountInfo: async (): Promise<AccountInfo> => {\n throw unsupported('getAccountInfo');\n },\n getAccountRecords: async (): Promise<TransactionRecord[]> => {\n throw unsupported('getAccountRecords');\n },\n signTransaction: async <T extends Transaction>(_: T): Promise<T> => {\n throw unsupported('signTransaction');\n },\n checkTransaction: async <T extends Transaction>(_: T): Promise<T> => {\n throw unsupported('checkTransaction');\n },\n populateTransaction: async <T extends Transaction>(_: T): Promise<T> => {\n throw unsupported('populateTransaction');\n },\n call: async <RequestT, ResponseT, OutputT>(\n _request: unknown,\n ): Promise<OutputT> => {\n throw unsupported('call');\n },\n };\n};\n\ntype HashgraphSdk = typeof import('@hashgraph/sdk');\n\nlet cachedSdk: HashgraphSdk | null = null;\n\nconst loadHashgraphSdk = (): HashgraphSdk => {\n if (cachedSdk) {\n return cachedSdk;\n }\n const metaUrl =\n typeof import.meta !== 'undefined' &&\n typeof (import.meta as { url?: string }).url === 'string'\n ? (import.meta as { url: string }).url\n : undefined;\n const loader = createRequire(metaUrl ?? `${process.cwd()}/.hol-rb-client.cjs`);\n try {\n const resolved = loader('@hashgraph/sdk') as HashgraphSdk;\n cachedSdk = resolved;\n return resolved;\n } catch (error) {\n const message =\n '@hashgraph/sdk is required for ledger signing. Install it as a dependency to enable createPrivateKeySigner.';\n const err = new Error(message);\n (err as { cause?: unknown }).cause = error;\n throw err;\n }\n};\n"],"names":[],"mappings":";AAUA,MAAM,cAAc,CAAC,WACnB,IAAI,MAAM,GAAG,MAAM,2CAA2C;AAQzD,MAAM,yBAAyB,CACpC,YACW;AACX,QAAM,MAAM,iBAAA;AACZ,QAAM,EAAE,WAAW,UAAU,YAAY,oBAAoB;AAC7D,MAAI,CAAC,QAAQ,YAAY;AACvB,UAAM,IAAI,MAAM,mDAAmD;AAAA,EACrE;AACA,MAAI,CAAC,QAAQ,WAAW;AACtB,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACpE;AACA,QAAM,YAAY,UAAU,WAAW,QAAQ,SAAS;AACxD,QAAM,aAAa,WAAW,WAAW,QAAQ,UAAU;AAC3D,QAAM,WAAW,SAAS,WAAW,QAAQ,OAAO;AAEpD,SAAO;AAAA,IACL,aAAa,MAAM;AAAA,IACnB,cAAc,MAAM;AAAA,IACpB,eAAe,MAAM,WAAW;AAAA,IAChC,YAAY,OAAO,CAAA;AAAA,IACnB,kBAAkB,MAAM,CAAA;AAAA,IACxB,MAAM,OAAO,aACX,QAAQ;AAAA,MACN,SAAS,IAAI,OAAM,YAAW;AAC5B,cAAM,YAAY,MAAM,WAAW,KAAK,OAAO;AAC/C,eAAO,IAAI,gBAAgB;AAAA,UACzB,WAAW,WAAW;AAAA,UACtB;AAAA,UACA;AAAA,QAAA,CACD;AAAA,MACH,CAAC;AAAA,IAAA;AAAA,IAEL,mBAAmB,YAAqC;AACtD,YAAM,YAAY,mBAAmB;AAAA,IACvC;AAAA,IACA,gBAAgB,YAAkC;AAChD,YAAM,YAAY,gBAAgB;AAAA,IACpC;AAAA,IACA,mBAAmB,YAA0C;AAC3D,YAAM,YAAY,mBAAmB;AAAA,IACvC;AAAA,IACA,iBAAiB,OAA8B,MAAqB;AAClE,YAAM,YAAY,iBAAiB;AAAA,IACrC;AAAA,IACA,kBAAkB,OAA8B,MAAqB;AACnE,YAAM,YAAY,kBAAkB;AAAA,IACtC;AAAA,IACA,qBAAqB,OAA8B,MAAqB;AACtE,YAAM,YAAY,qBAAqB;AAAA,IACzC;AAAA,IACA,MAAM,OACJ,aACqB;AACrB,YAAM,YAAY,MAAM;AAAA,IAC1B;AAAA,EAAA;AAEJ;AAIA,IAAI,YAAiC;AAErC,MAAM,mBAAmB,MAAoB;AAC3C,MAAI,WAAW;AACb,WAAO;AAAA,EACT;AACA,QAAM,UACJ,OAAO,gBAAgB,eACvB,OAAQ,YAAiC,QAAQ,WAC5C,YAAgC,MACjC;AACN,QAAM,SAAS,cAAc,WAAW,GAAG,QAAQ,IAAA,CAAK,qBAAqB;AAC7E,MAAI;AACF,UAAM,WAAW,OAAO,gBAAgB;AACxC,gBAAY;AACZ,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,UACJ;AACF,UAAM,MAAM,IAAI,MAAM,OAAO;AAC5B,QAA4B,QAAQ;AACrC,UAAM;AAAA,EACR;AACF;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildTopicCreateTx, buildMessageTx } from "./standards-sdk.
|
|
1
|
+
import { buildTopicCreateTx, buildMessageTx } from "./standards-sdk.es136.js";
|
|
2
2
|
import { HCS7ConfigType, HCS7Operation } from "./standards-sdk.es9.js";
|
|
3
3
|
function buildHcs7CreateRegistryTx(params) {
|
|
4
4
|
const memo = `hcs-7:indexed:${params.ttl}`;
|
|
@@ -1,20 +1,141 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
class
|
|
1
|
+
import { AccountId, Client, PrivateKey } from "@hashgraph/sdk";
|
|
2
|
+
import { detectKeyTypeFromString } from "./standards-sdk.es113.js";
|
|
3
|
+
class NodeOperatorResolver {
|
|
4
|
+
constructor(params) {
|
|
5
|
+
this.mirror = params.mirrorNode;
|
|
6
|
+
this.logger = params.logger;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Best-guess parsing for an operator key without network calls.
|
|
10
|
+
* - If PrivateKey: returns immediately with provided or fallback type.
|
|
11
|
+
* - If string with explicitType: parse directly.
|
|
12
|
+
* - If string without type: detect format; fallback to ECDSA.
|
|
13
|
+
*/
|
|
14
|
+
bestGuessOperatorKey(operatorKeyInput, explicitType) {
|
|
15
|
+
if (typeof operatorKeyInput !== "string") {
|
|
16
|
+
return { keyType: explicitType || "ecdsa", privateKey: operatorKeyInput };
|
|
17
|
+
}
|
|
18
|
+
if (explicitType) {
|
|
19
|
+
const pk = explicitType === "ed25519" ? PrivateKey.fromStringED25519(operatorKeyInput) : PrivateKey.fromStringECDSA(operatorKeyInput);
|
|
20
|
+
return { keyType: explicitType, privateKey: pk };
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const detected = detectKeyTypeFromString(operatorKeyInput);
|
|
24
|
+
return {
|
|
25
|
+
keyType: detected.detectedType,
|
|
26
|
+
privateKey: detected.privateKey
|
|
27
|
+
};
|
|
28
|
+
} catch {
|
|
29
|
+
return {
|
|
30
|
+
keyType: "ecdsa",
|
|
31
|
+
privateKey: PrivateKey.fromStringECDSA(operatorKeyInput)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
4
35
|
/**
|
|
5
|
-
*
|
|
36
|
+
* Resolve an operator key using Mirror Node for key type when possible.
|
|
37
|
+
* - If PrivateKey: return immediately.
|
|
38
|
+
* - If explicitType: parse directly.
|
|
39
|
+
* - Else: query Mirror Node; fallback to local detection.
|
|
6
40
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
41
|
+
async resolveOperatorKey(operatorId, operatorKeyInput, explicitType) {
|
|
42
|
+
if (typeof operatorKeyInput !== "string") {
|
|
43
|
+
return { keyType: explicitType || "ecdsa", privateKey: operatorKeyInput };
|
|
44
|
+
}
|
|
45
|
+
if (explicitType) {
|
|
46
|
+
const pk = explicitType === "ed25519" ? PrivateKey.fromStringED25519(operatorKeyInput) : PrivateKey.fromStringECDSA(operatorKeyInput);
|
|
47
|
+
return { keyType: explicitType, privateKey: pk };
|
|
48
|
+
}
|
|
49
|
+
const account = typeof operatorId === "string" ? operatorId : operatorId.toString();
|
|
50
|
+
try {
|
|
51
|
+
const info = await this.mirror.requestAccount(account);
|
|
52
|
+
const t = info?.key?._type || "";
|
|
53
|
+
const keyType = t.includes("ED25519") ? "ed25519" : "ecdsa";
|
|
54
|
+
const privateKey = keyType === "ed25519" ? PrivateKey.fromStringED25519(operatorKeyInput) : PrivateKey.fromStringECDSA(operatorKeyInput);
|
|
55
|
+
return { keyType, privateKey };
|
|
56
|
+
} catch {
|
|
57
|
+
this.logger.warn(
|
|
58
|
+
"Mirror node key detection failed; using local detection or default ECDSA"
|
|
59
|
+
);
|
|
60
|
+
return this.bestGuessOperatorKey(operatorKeyInput);
|
|
61
|
+
}
|
|
15
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolve a supply key for the given token using Mirror Node token supply_key._type when possible.
|
|
65
|
+
*/
|
|
66
|
+
async resolveSupplyKey(tokenId, keyInput, fallbackType, explicitType) {
|
|
67
|
+
try {
|
|
68
|
+
const info = await this.mirror.getTokenInfo(tokenId);
|
|
69
|
+
const t = info?.supply_key?._type || "";
|
|
70
|
+
if (typeof keyInput !== "string") {
|
|
71
|
+
return keyInput;
|
|
72
|
+
}
|
|
73
|
+
if (explicitType) {
|
|
74
|
+
return explicitType === "ed25519" ? PrivateKey.fromStringED25519(keyInput) : PrivateKey.fromStringECDSA(keyInput);
|
|
75
|
+
}
|
|
76
|
+
if (t.includes("ED25519")) {
|
|
77
|
+
return PrivateKey.fromStringED25519(keyInput);
|
|
78
|
+
}
|
|
79
|
+
if (t.includes("ECDSA")) {
|
|
80
|
+
return PrivateKey.fromStringECDSA(keyInput);
|
|
81
|
+
}
|
|
82
|
+
return fallbackType === "ed25519" ? PrivateKey.fromStringED25519(keyInput) : PrivateKey.fromStringECDSA(keyInput);
|
|
83
|
+
} catch {
|
|
84
|
+
if (typeof keyInput !== "string") {
|
|
85
|
+
return keyInput;
|
|
86
|
+
}
|
|
87
|
+
if (explicitType) {
|
|
88
|
+
return explicitType === "ed25519" ? PrivateKey.fromStringED25519(keyInput) : PrivateKey.fromStringECDSA(keyInput);
|
|
89
|
+
}
|
|
90
|
+
return fallbackType === "ed25519" ? PrivateKey.fromStringED25519(keyInput) : PrivateKey.fromStringECDSA(keyInput);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function createNodeOperatorContext(params) {
|
|
95
|
+
const operatorId = typeof params.operatorId === "string" ? AccountId.fromString(params.operatorId) : params.operatorId;
|
|
96
|
+
const client = params.client ? params.client : params.network === "mainnet" ? Client.forMainnet() : Client.forTestnet();
|
|
97
|
+
const resolver = new NodeOperatorResolver({
|
|
98
|
+
mirrorNode: params.mirrorNode,
|
|
99
|
+
logger: params.logger
|
|
100
|
+
});
|
|
101
|
+
let currentKeyType;
|
|
102
|
+
let currentPrivateKey;
|
|
103
|
+
const guess = resolver.bestGuessOperatorKey(
|
|
104
|
+
params.operatorKey,
|
|
105
|
+
params.keyType
|
|
106
|
+
);
|
|
107
|
+
currentKeyType = guess.keyType;
|
|
108
|
+
currentPrivateKey = guess.privateKey;
|
|
109
|
+
client.setOperator(operatorId.toString(), currentPrivateKey);
|
|
110
|
+
const initPromise = (async () => {
|
|
111
|
+
try {
|
|
112
|
+
const resolved = await resolver.resolveOperatorKey(
|
|
113
|
+
operatorId,
|
|
114
|
+
params.operatorKey,
|
|
115
|
+
params.keyType
|
|
116
|
+
);
|
|
117
|
+
currentKeyType = resolved.keyType;
|
|
118
|
+
currentPrivateKey = resolved.privateKey;
|
|
119
|
+
client.setOperator(operatorId.toString(), currentPrivateKey);
|
|
120
|
+
} catch {
|
|
121
|
+
}
|
|
122
|
+
})();
|
|
123
|
+
return {
|
|
124
|
+
client,
|
|
125
|
+
operatorId,
|
|
126
|
+
get operatorKey() {
|
|
127
|
+
return currentPrivateKey;
|
|
128
|
+
},
|
|
129
|
+
get keyType() {
|
|
130
|
+
return currentKeyType;
|
|
131
|
+
},
|
|
132
|
+
ensureInitialized: async () => {
|
|
133
|
+
await initPromise;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
16
136
|
}
|
|
17
137
|
export {
|
|
18
|
-
|
|
138
|
+
NodeOperatorResolver,
|
|
139
|
+
createNodeOperatorContext
|
|
19
140
|
};
|
|
20
141
|
//# sourceMappingURL=standards-sdk.es135.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es135.js","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"standards-sdk.es135.js","sources":["../../src/common/node-operator-resolver.ts"],"sourcesContent":["import { AccountId, Client, PrivateKey } from '@hashgraph/sdk';\nimport { HederaMirrorNode } from '../services/mirror-node';\nimport { ILogger } from '../utils/logger';\nimport { detectKeyTypeFromString } from '../utils/key-type-detector';\nimport { NetworkType } from '../utils/types';\n\n/**\n * Resolves operator and supply private keys using Mirror Node as source of truth\n * with format-detection fallbacks for string keys.\n */\nexport class NodeOperatorResolver {\n private readonly mirror: HederaMirrorNode;\n private readonly logger: ILogger;\n\n constructor(params: { mirrorNode: HederaMirrorNode; logger: ILogger }) {\n this.mirror = params.mirrorNode;\n this.logger = params.logger;\n }\n\n /**\n * Best-guess parsing for an operator key without network calls.\n * - If PrivateKey: returns immediately with provided or fallback type.\n * - If string with explicitType: parse directly.\n * - If string without type: detect format; fallback to ECDSA.\n */\n bestGuessOperatorKey(\n operatorKeyInput: string | PrivateKey,\n explicitType?: 'ed25519' | 'ecdsa',\n ): { keyType: 'ed25519' | 'ecdsa'; privateKey: PrivateKey } {\n if (typeof operatorKeyInput !== 'string') {\n return { keyType: explicitType || 'ecdsa', privateKey: operatorKeyInput };\n }\n if (explicitType) {\n const pk =\n explicitType === 'ed25519'\n ? PrivateKey.fromStringED25519(operatorKeyInput)\n : PrivateKey.fromStringECDSA(operatorKeyInput);\n return { keyType: explicitType, privateKey: pk };\n }\n try {\n const detected = detectKeyTypeFromString(operatorKeyInput);\n return {\n keyType: detected.detectedType,\n privateKey: detected.privateKey,\n };\n } catch {\n return {\n keyType: 'ecdsa',\n privateKey: PrivateKey.fromStringECDSA(operatorKeyInput),\n };\n }\n }\n\n /**\n * Resolve an operator key using Mirror Node for key type when possible.\n * - If PrivateKey: return immediately.\n * - If explicitType: parse directly.\n * - Else: query Mirror Node; fallback to local detection.\n */\n async resolveOperatorKey(\n operatorId: string | AccountId,\n operatorKeyInput: string | PrivateKey,\n explicitType?: 'ed25519' | 'ecdsa',\n ): Promise<{ keyType: 'ed25519' | 'ecdsa'; privateKey: PrivateKey }> {\n if (typeof operatorKeyInput !== 'string') {\n return { keyType: explicitType || 'ecdsa', privateKey: operatorKeyInput };\n }\n if (explicitType) {\n const pk =\n explicitType === 'ed25519'\n ? PrivateKey.fromStringED25519(operatorKeyInput)\n : PrivateKey.fromStringECDSA(operatorKeyInput);\n return { keyType: explicitType, privateKey: pk };\n }\n const account =\n typeof operatorId === 'string' ? operatorId : operatorId.toString();\n try {\n const info = await this.mirror.requestAccount(account);\n const t = info?.key?._type || '';\n const keyType: 'ed25519' | 'ecdsa' = t.includes('ED25519')\n ? 'ed25519'\n : 'ecdsa';\n const privateKey =\n keyType === 'ed25519'\n ? PrivateKey.fromStringED25519(operatorKeyInput)\n : PrivateKey.fromStringECDSA(operatorKeyInput);\n return { keyType, privateKey };\n } catch {\n this.logger.warn(\n 'Mirror node key detection failed; using local detection or default ECDSA',\n );\n return this.bestGuessOperatorKey(operatorKeyInput);\n }\n }\n\n /**\n * Resolve a supply key for the given token using Mirror Node token supply_key._type when possible.\n */\n async resolveSupplyKey(\n tokenId: string,\n keyInput: string | PrivateKey,\n fallbackType: 'ed25519' | 'ecdsa',\n explicitType?: 'ed25519' | 'ecdsa',\n ): Promise<PrivateKey> {\n try {\n const info = await this.mirror.getTokenInfo(tokenId);\n const t = info?.supply_key?._type || '';\n if (typeof keyInput !== 'string') {\n return keyInput;\n }\n if (explicitType) {\n return explicitType === 'ed25519'\n ? PrivateKey.fromStringED25519(keyInput)\n : PrivateKey.fromStringECDSA(keyInput);\n }\n if (t.includes('ED25519')) {\n return PrivateKey.fromStringED25519(keyInput);\n }\n if (t.includes('ECDSA')) {\n return PrivateKey.fromStringECDSA(keyInput);\n }\n return fallbackType === 'ed25519'\n ? PrivateKey.fromStringED25519(keyInput)\n : PrivateKey.fromStringECDSA(keyInput);\n } catch {\n if (typeof keyInput !== 'string') {\n return keyInput;\n }\n if (explicitType) {\n return explicitType === 'ed25519'\n ? PrivateKey.fromStringED25519(keyInput)\n : PrivateKey.fromStringECDSA(keyInput);\n }\n return fallbackType === 'ed25519'\n ? PrivateKey.fromStringED25519(keyInput)\n : PrivateKey.fromStringECDSA(keyInput);\n }\n }\n}\n\nexport interface NodeOperatorInitParams {\n network: NetworkType;\n operatorId: string | AccountId;\n operatorKey: string | PrivateKey;\n keyType?: 'ed25519' | 'ecdsa';\n mirrorNode: HederaMirrorNode;\n logger: ILogger;\n client?: Client;\n}\n\nexport interface NodeOperatorContext {\n client: Client;\n operatorId: AccountId;\n readonly operatorKey: PrivateKey;\n readonly keyType: 'ed25519' | 'ecdsa';\n ensureInitialized(): Promise<void>;\n}\n\nexport function createNodeOperatorContext(\n params: NodeOperatorInitParams,\n): NodeOperatorContext {\n const operatorId: AccountId =\n typeof params.operatorId === 'string'\n ? AccountId.fromString(params.operatorId)\n : params.operatorId;\n\n const client: Client = params.client\n ? params.client\n : params.network === 'mainnet'\n ? Client.forMainnet()\n : Client.forTestnet();\n\n const resolver = new NodeOperatorResolver({\n mirrorNode: params.mirrorNode,\n logger: params.logger,\n });\n\n let currentKeyType: 'ed25519' | 'ecdsa';\n let currentPrivateKey: PrivateKey;\n\n const guess = resolver.bestGuessOperatorKey(\n params.operatorKey,\n params.keyType,\n );\n currentKeyType = guess.keyType;\n currentPrivateKey = guess.privateKey;\n client.setOperator(operatorId.toString(), currentPrivateKey);\n\n const initPromise = (async () => {\n try {\n const resolved = await resolver.resolveOperatorKey(\n operatorId,\n params.operatorKey,\n params.keyType,\n );\n currentKeyType = resolved.keyType;\n currentPrivateKey = resolved.privateKey;\n client.setOperator(operatorId.toString(), currentPrivateKey);\n } catch {}\n })();\n\n return {\n client,\n operatorId,\n get operatorKey() {\n return currentPrivateKey;\n },\n get keyType() {\n return currentKeyType;\n },\n ensureInitialized: async () => {\n await initPromise;\n },\n };\n}\n"],"names":[],"mappings":";;AAUO,MAAM,qBAAqB;AAAA,EAIhC,YAAY,QAA2D;AACrE,SAAK,SAAS,OAAO;AACrB,SAAK,SAAS,OAAO;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,qBACE,kBACA,cAC0D;AAC1D,QAAI,OAAO,qBAAqB,UAAU;AACxC,aAAO,EAAE,SAAS,gBAAgB,SAAS,YAAY,iBAAA;AAAA,IACzD;AACA,QAAI,cAAc;AAChB,YAAM,KACJ,iBAAiB,YACb,WAAW,kBAAkB,gBAAgB,IAC7C,WAAW,gBAAgB,gBAAgB;AACjD,aAAO,EAAE,SAAS,cAAc,YAAY,GAAA;AAAA,IAC9C;AACA,QAAI;AACF,YAAM,WAAW,wBAAwB,gBAAgB;AACzD,aAAO;AAAA,QACL,SAAS,SAAS;AAAA,QAClB,YAAY,SAAS;AAAA,MAAA;AAAA,IAEzB,QAAQ;AACN,aAAO;AAAA,QACL,SAAS;AAAA,QACT,YAAY,WAAW,gBAAgB,gBAAgB;AAAA,MAAA;AAAA,IAE3D;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,mBACJ,YACA,kBACA,cACmE;AACnE,QAAI,OAAO,qBAAqB,UAAU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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const pk = explicitType === "ed25519" ? PrivateKey.fromStringED25519(operatorKeyInput) : PrivateKey.fromStringECDSA(operatorKeyInput);
|
|
20
|
-
return { keyType: explicitType, privateKey: pk };
|
|
21
|
-
}
|
|
22
|
-
try {
|
|
23
|
-
const detected = detectKeyTypeFromString(operatorKeyInput);
|
|
24
|
-
return {
|
|
25
|
-
keyType: detected.detectedType,
|
|
26
|
-
privateKey: detected.privateKey
|
|
27
|
-
};
|
|
28
|
-
} catch {
|
|
29
|
-
return {
|
|
30
|
-
keyType: "ecdsa",
|
|
31
|
-
privateKey: PrivateKey.fromStringECDSA(operatorKeyInput)
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Resolve an operator key using Mirror Node for key type when possible.
|
|
37
|
-
* - If PrivateKey: return immediately.
|
|
38
|
-
* - If explicitType: parse directly.
|
|
39
|
-
* - Else: query Mirror Node; fallback to local detection.
|
|
40
|
-
*/
|
|
41
|
-
async resolveOperatorKey(operatorId, operatorKeyInput, explicitType) {
|
|
42
|
-
if (typeof operatorKeyInput !== "string") {
|
|
43
|
-
return { keyType: explicitType || "ecdsa", privateKey: operatorKeyInput };
|
|
44
|
-
}
|
|
45
|
-
if (explicitType) {
|
|
46
|
-
const pk = explicitType === "ed25519" ? PrivateKey.fromStringED25519(operatorKeyInput) : PrivateKey.fromStringECDSA(operatorKeyInput);
|
|
47
|
-
return { keyType: explicitType, privateKey: pk };
|
|
48
|
-
}
|
|
49
|
-
const account = typeof operatorId === "string" ? operatorId : operatorId.toString();
|
|
50
|
-
try {
|
|
51
|
-
const info = await this.mirror.requestAccount(account);
|
|
52
|
-
const t = info?.key?._type || "";
|
|
53
|
-
const keyType = t.includes("ED25519") ? "ed25519" : "ecdsa";
|
|
54
|
-
const privateKey = keyType === "ed25519" ? PrivateKey.fromStringED25519(operatorKeyInput) : PrivateKey.fromStringECDSA(operatorKeyInput);
|
|
55
|
-
return { keyType, privateKey };
|
|
56
|
-
} catch {
|
|
57
|
-
this.logger.warn(
|
|
58
|
-
"Mirror node key detection failed; using local detection or default ECDSA"
|
|
59
|
-
);
|
|
60
|
-
return this.bestGuessOperatorKey(operatorKeyInput);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Resolve a supply key for the given token using Mirror Node token supply_key._type when possible.
|
|
65
|
-
*/
|
|
66
|
-
async resolveSupplyKey(tokenId, keyInput, fallbackType, explicitType) {
|
|
67
|
-
try {
|
|
68
|
-
const info = await this.mirror.getTokenInfo(tokenId);
|
|
69
|
-
const t = info?.supply_key?._type || "";
|
|
70
|
-
if (typeof keyInput !== "string") {
|
|
71
|
-
return keyInput;
|
|
72
|
-
}
|
|
73
|
-
if (explicitType) {
|
|
74
|
-
return explicitType === "ed25519" ? PrivateKey.fromStringED25519(keyInput) : PrivateKey.fromStringECDSA(keyInput);
|
|
75
|
-
}
|
|
76
|
-
if (t.includes("ED25519")) {
|
|
77
|
-
return PrivateKey.fromStringED25519(keyInput);
|
|
78
|
-
}
|
|
79
|
-
if (t.includes("ECDSA")) {
|
|
80
|
-
return PrivateKey.fromStringECDSA(keyInput);
|
|
81
|
-
}
|
|
82
|
-
return fallbackType === "ed25519" ? PrivateKey.fromStringED25519(keyInput) : PrivateKey.fromStringECDSA(keyInput);
|
|
83
|
-
} catch {
|
|
84
|
-
if (typeof keyInput !== "string") {
|
|
85
|
-
return keyInput;
|
|
86
|
-
}
|
|
87
|
-
if (explicitType) {
|
|
88
|
-
return explicitType === "ed25519" ? PrivateKey.fromStringED25519(keyInput) : PrivateKey.fromStringECDSA(keyInput);
|
|
1
|
+
import { TopicMessageSubmitTransaction, TopicId, TopicCreateTransaction, PublicKey, KeyList } from "@hashgraph/sdk";
|
|
2
|
+
function encodeHcs2RegistryMemo(indexedFlag, ttl) {
|
|
3
|
+
return `hcs-2:${indexedFlag}:${ttl}`;
|
|
4
|
+
}
|
|
5
|
+
function buildTopicCreateTx(params) {
|
|
6
|
+
const { memo, adminKey, submitKey, operatorPublicKey } = params;
|
|
7
|
+
const tx = new TopicCreateTransaction().setTopicMemo(memo);
|
|
8
|
+
const coerceKey = (k) => {
|
|
9
|
+
if (!k) return void 0;
|
|
10
|
+
if (k instanceof PublicKey || k instanceof KeyList) return k;
|
|
11
|
+
if (typeof k === "boolean") {
|
|
12
|
+
return k ? operatorPublicKey : void 0;
|
|
13
|
+
}
|
|
14
|
+
if (typeof k === "string") {
|
|
15
|
+
try {
|
|
16
|
+
return PublicKey.fromString(k);
|
|
17
|
+
} catch {
|
|
18
|
+
return void 0;
|
|
89
19
|
}
|
|
90
|
-
return fallbackType === "ed25519" ? PrivateKey.fromStringED25519(keyInput) : PrivateKey.fromStringECDSA(keyInput);
|
|
91
20
|
}
|
|
21
|
+
return void 0;
|
|
22
|
+
};
|
|
23
|
+
const admin = coerceKey(adminKey);
|
|
24
|
+
if (admin) {
|
|
25
|
+
tx.setAdminKey(admin);
|
|
92
26
|
}
|
|
27
|
+
const submit = coerceKey(submitKey);
|
|
28
|
+
if (submit) {
|
|
29
|
+
tx.setSubmitKey(submit);
|
|
30
|
+
}
|
|
31
|
+
return tx;
|
|
93
32
|
}
|
|
94
|
-
function
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
-
let currentKeyType;
|
|
102
|
-
let currentPrivateKey;
|
|
103
|
-
const guess = resolver.bestGuessOperatorKey(
|
|
104
|
-
params.operatorKey,
|
|
105
|
-
params.keyType
|
|
106
|
-
);
|
|
107
|
-
currentKeyType = guess.keyType;
|
|
108
|
-
currentPrivateKey = guess.privateKey;
|
|
109
|
-
client.setOperator(operatorId.toString(), currentPrivateKey);
|
|
110
|
-
const initPromise = (async () => {
|
|
111
|
-
try {
|
|
112
|
-
const resolved = await resolver.resolveOperatorKey(
|
|
113
|
-
operatorId,
|
|
114
|
-
params.operatorKey,
|
|
115
|
-
params.keyType
|
|
116
|
-
);
|
|
117
|
-
currentKeyType = resolved.keyType;
|
|
118
|
-
currentPrivateKey = resolved.privateKey;
|
|
119
|
-
client.setOperator(operatorId.toString(), currentPrivateKey);
|
|
120
|
-
} catch {
|
|
121
|
-
}
|
|
122
|
-
})();
|
|
123
|
-
return {
|
|
124
|
-
client,
|
|
125
|
-
operatorId,
|
|
126
|
-
get operatorKey() {
|
|
127
|
-
return currentPrivateKey;
|
|
128
|
-
},
|
|
129
|
-
get keyType() {
|
|
130
|
-
return currentKeyType;
|
|
131
|
-
},
|
|
132
|
-
ensureInitialized: async () => {
|
|
133
|
-
await initPromise;
|
|
134
|
-
}
|
|
135
|
-
};
|
|
33
|
+
function buildMessageTx(params) {
|
|
34
|
+
const tx = new TopicMessageSubmitTransaction().setTopicId(TopicId.fromString(params.topicId)).setMessage(params.message);
|
|
35
|
+
if (params.transactionMemo) {
|
|
36
|
+
tx.setTransactionMemo(params.transactionMemo);
|
|
37
|
+
}
|
|
38
|
+
return tx;
|
|
136
39
|
}
|
|
137
40
|
export {
|
|
138
|
-
|
|
139
|
-
|
|
41
|
+
buildMessageTx,
|
|
42
|
+
buildTopicCreateTx,
|
|
43
|
+
encodeHcs2RegistryMemo
|
|
140
44
|
};
|
|
141
45
|
//# sourceMappingURL=standards-sdk.es136.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es136.js","sources":["../../src/common/
|
|
1
|
+
{"version":3,"file":"standards-sdk.es136.js","sources":["../../src/common/tx/tx-utils.ts"],"sourcesContent":["import {\n TopicCreateTransaction,\n TopicMessageSubmitTransaction,\n PublicKey,\n KeyList,\n TopicId,\n} from '@hashgraph/sdk';\n\nexport type MaybeKey = boolean | string | PublicKey | KeyList | undefined;\n\nexport function encodeHcs2RegistryMemo(\n indexedFlag: 0 | 1,\n ttl: number,\n): string {\n return `hcs-2:${indexedFlag}:${ttl}`;\n}\n\nexport function buildTopicCreateTx(params: {\n memo: string;\n adminKey?: MaybeKey;\n submitKey?: MaybeKey;\n operatorPublicKey?: PublicKey;\n}): TopicCreateTransaction {\n const { memo, adminKey, submitKey, operatorPublicKey } = params;\n const tx = new TopicCreateTransaction().setTopicMemo(memo);\n\n const coerceKey = (k?: MaybeKey): PublicKey | KeyList | undefined => {\n if (!k) return undefined;\n if (k instanceof PublicKey || k instanceof KeyList) return k;\n if (typeof k === 'boolean') {\n return k ? operatorPublicKey : undefined;\n }\n if (typeof k === 'string') {\n try {\n return PublicKey.fromString(k);\n } catch {\n return undefined;\n }\n }\n return undefined;\n };\n\n const admin = coerceKey(adminKey);\n if (admin) {\n tx.setAdminKey(admin);\n }\n\n const submit = coerceKey(submitKey);\n if (submit) {\n tx.setSubmitKey(submit);\n }\n\n return tx;\n}\n\nexport function buildMessageTx(params: {\n topicId: string;\n message: string | Uint8Array;\n transactionMemo?: string;\n}): TopicMessageSubmitTransaction {\n const tx = new TopicMessageSubmitTransaction()\n .setTopicId(TopicId.fromString(params.topicId))\n .setMessage(params.message);\n if (params.transactionMemo) {\n tx.setTransactionMemo(params.transactionMemo);\n }\n return tx;\n}\n"],"names":[],"mappings":";AAUO,SAAS,uBACd,aACA,KACQ;AACR,SAAO,SAAS,WAAW,IAAI,GAAG;AACpC;AAEO,SAAS,mBAAmB,QAKR;AACzB,QAAM,EAAE,MAAM,UAAU,WAAW,sBAAsB;AACzD,QAAM,KAAK,IAAI,yBAAyB,aAAa,IAAI;AAEzD,QAAM,YAAY,CAAC,MAAkD;AACnE,QAAI,CAAC,EAAG,QAAO;AACf,QAAI,aAAa,aAAa,aAAa,QAAS,QAAO;AAC3D,QAAI,OAAO,MAAM,WAAW;AAC1B,aAAO,IAAI,oBAAoB;AAAA,IACjC;AACA,QAAI,OAAO,MAAM,UAAU;AACzB,UAAI;AACF,eAAO,UAAU,WAAW,CAAC;AAAA,MAC/B,QAAQ;AACN,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,UAAU,QAAQ;AAChC,MAAI,OAAO;AACT,OAAG,YAAY,KAAK;AAAA,EACtB;AAEA,QAAM,SAAS,UAAU,SAAS;AAClC,MAAI,QAAQ;AACV,OAAG,aAAa,MAAM;AAAA,EACxB;AAEA,SAAO;AACT;AAEO,SAAS,eAAe,QAIG;AAChC,QAAM,KAAK,IAAI,gCACZ,WAAW,QAAQ,WAAW,OAAO,OAAO,CAAC,EAC7C,WAAW,OAAO,OAAO;AAC5B,MAAI,OAAO,iBAAiB;AAC1B,OAAG,mBAAmB,OAAO,eAAe;AAAA,EAC9C;AACA,SAAO;AACT;"}
|
|
@@ -1,45 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
const ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
2
|
+
const BASE = 58;
|
|
3
|
+
function base58Encode(bytes) {
|
|
4
|
+
if (bytes.length === 0) return "";
|
|
5
|
+
let zeros = 0;
|
|
6
|
+
while (zeros < bytes.length && bytes[zeros] === 0) zeros++;
|
|
7
|
+
if (zeros === bytes.length) return "1".repeat(zeros);
|
|
8
|
+
const digits = [0];
|
|
9
|
+
for (let i = zeros; i < bytes.length; i++) {
|
|
10
|
+
let carry = bytes[i];
|
|
11
|
+
for (let j = 0; j < digits.length; j++) {
|
|
12
|
+
const val = (digits[j] << 8) + carry;
|
|
13
|
+
digits[j] = val % BASE;
|
|
14
|
+
carry = val / BASE | 0;
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} catch {
|
|
18
|
-
return void 0;
|
|
19
|
-
}
|
|
16
|
+
while (carry > 0) {
|
|
17
|
+
digits.push(carry % BASE);
|
|
18
|
+
carry = carry / BASE | 0;
|
|
20
19
|
}
|
|
21
|
-
return void 0;
|
|
22
|
-
};
|
|
23
|
-
const admin = coerceKey(adminKey);
|
|
24
|
-
if (admin) {
|
|
25
|
-
tx.setAdminKey(admin);
|
|
26
|
-
}
|
|
27
|
-
const submit = coerceKey(submitKey);
|
|
28
|
-
if (submit) {
|
|
29
|
-
tx.setSubmitKey(submit);
|
|
30
20
|
}
|
|
31
|
-
|
|
21
|
+
let result = "";
|
|
22
|
+
for (let i = 0; i < zeros; i++) result += "1";
|
|
23
|
+
for (let i = digits.length - 1; i >= 0; i--) result += ALPHABET[digits[i]];
|
|
24
|
+
return result;
|
|
32
25
|
}
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
function base58Decode(text) {
|
|
27
|
+
if (text.length === 0) return new Uint8Array(0);
|
|
28
|
+
let zeros = 0;
|
|
29
|
+
while (zeros < text.length && text[zeros] === "1") zeros++;
|
|
30
|
+
const b256 = [];
|
|
31
|
+
for (let i = zeros; i < text.length; i++) {
|
|
32
|
+
const ch = text[i];
|
|
33
|
+
const val = ALPHABET.indexOf(ch);
|
|
34
|
+
if (val === -1) throw new Error("Invalid Base58 character");
|
|
35
|
+
let carry = val;
|
|
36
|
+
for (let j = 0; j < b256.length; j++) {
|
|
37
|
+
const x = b256[j] * BASE + carry;
|
|
38
|
+
b256[j] = x & 255;
|
|
39
|
+
carry = x >> 8;
|
|
40
|
+
}
|
|
41
|
+
while (carry > 0) {
|
|
42
|
+
b256.push(carry & 255);
|
|
43
|
+
carry >>= 8;
|
|
44
|
+
}
|
|
37
45
|
}
|
|
38
|
-
|
|
46
|
+
for (let i = 0; i < zeros; i++) b256.push(0);
|
|
47
|
+
b256.reverse();
|
|
48
|
+
return Uint8Array.from(b256);
|
|
49
|
+
}
|
|
50
|
+
function multibaseB58btcDecode(zText) {
|
|
51
|
+
if (!zText.startsWith("z")) throw new Error("Invalid multibase base58btc");
|
|
52
|
+
return base58Decode(zText.slice(1));
|
|
39
53
|
}
|
|
40
54
|
export {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
55
|
+
base58Decode,
|
|
56
|
+
base58Encode,
|
|
57
|
+
multibaseB58btcDecode
|
|
44
58
|
};
|
|
45
59
|
//# sourceMappingURL=standards-sdk.es137.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es137.js","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"standards-sdk.es137.js","sources":["../../src/hcs-14/base58.ts"],"sourcesContent":["/**\n * Minimal Base58 encoder/decoder (Bitcoin alphabet) with no external dependencies.\n */\n\nconst ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';\nconst BASE = 58;\n\nfunction countLeadingZeros(bytes: Uint8Array): number {\n let zeros = 0;\n for (let i = 0; i < bytes.length && bytes[i] === 0; i++) {\n zeros++;\n }\n return zeros;\n}\n\nexport function base58Encode(bytes: Uint8Array): string {\n if (bytes.length === 0) return '';\n\n let zeros = 0;\n while (zeros < bytes.length && bytes[zeros] === 0) zeros++;\n\n if (zeros === bytes.length) return '1'.repeat(zeros);\n\n const digits: number[] = [0];\n for (let i = zeros; i < bytes.length; i++) {\n let carry = bytes[i];\n for (let j = 0; j < digits.length; j++) {\n const val = (digits[j] << 8) + carry;\n digits[j] = val % BASE;\n carry = (val / BASE) | 0;\n }\n while (carry > 0) {\n digits.push(carry % BASE);\n carry = (carry / BASE) | 0;\n }\n }\n\n let result = '';\n for (let i = 0; i < zeros; i++) result += '1';\n for (let i = digits.length - 1; i >= 0; i--) result += ALPHABET[digits[i]];\n return result;\n}\n\nexport function base58Decode(text: string): Uint8Array {\n if (text.length === 0) return new Uint8Array(0);\n\n let zeros = 0;\n while (zeros < text.length && text[zeros] === '1') zeros++;\n\n const b256: number[] = [];\n for (let i = zeros; i < text.length; i++) {\n const ch = text[i];\n const val = ALPHABET.indexOf(ch);\n if (val === -1) throw new Error('Invalid Base58 character');\n\n let carry = val;\n for (let j = 0; j < b256.length; j++) {\n const x = b256[j] * BASE + carry;\n b256[j] = x & 0xff;\n carry = x >> 8;\n }\n while (carry > 0) {\n b256.push(carry & 0xff);\n carry >>= 8;\n }\n }\n\n for (let i = 0; i < zeros; i++) b256.push(0);\n b256.reverse();\n return Uint8Array.from(b256);\n}\n\nexport function multibaseB58btcDecode(zText: string): Uint8Array {\n if (!zText.startsWith('z')) throw new Error('Invalid multibase base58btc');\n return base58Decode(zText.slice(1));\n}\n"],"names":[],"mappings":"AAIA,MAAM,WAAW;AACjB,MAAM,OAAO;AAUN,SAAS,aAAa,OAA2B;AACtD,MAAI,MAAM,WAAW,EAAG,QAAO;AAE/B,MAAI,QAAQ;AACZ,SAAO,QAAQ,MAAM,UAAU,MAAM,KAAK,MAAM,EAAG;AAEnD,MAAI,UAAU,MAAM,OAAQ,QAAO,IAAI,OAAO,KAAK;AAEnD,QAAM,SAAmB,CAAC,CAAC;AAC3B,WAAS,IAAI,OAAO,IAAI,MAAM,QAAQ,KAAK;AACzC,QAAI,QAAQ,MAAM,CAAC;AACnB,aAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,YAAM,OAAO,OAAO,CAAC,KAAK,KAAK;AAC/B,aAAO,CAAC,IAAI,MAAM;AAClB,cAAS,MAAM,OAAQ;AAAA,IACzB;AACA,WAAO,QAAQ,GAAG;AAChB,aAAO,KAAK,QAAQ,IAAI;AACxB,cAAS,QAAQ,OAAQ;AAAA,IAC3B;AAAA,EACF;AAEA,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,OAAO,IAAK,WAAU;AAC1C,WAAS,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,IAAK,WAAU,S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