@cheqd/sdk-esm 5.3.4-develop.2

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.
Files changed (68) hide show
  1. package/build/index.d.ts +140 -0
  2. package/build/index.d.ts.map +1 -0
  3. package/build/index.js +182 -0
  4. package/build/index.js.map +1 -0
  5. package/build/modules/_.d.ts +62 -0
  6. package/build/modules/_.d.ts.map +1 -0
  7. package/build/modules/_.js +75 -0
  8. package/build/modules/_.js.map +1 -0
  9. package/build/modules/did.d.ts +386 -0
  10. package/build/modules/did.d.ts.map +1 -0
  11. package/build/modules/did.js +1013 -0
  12. package/build/modules/did.js.map +1 -0
  13. package/build/modules/feeabstraction.d.ts +409 -0
  14. package/build/modules/feeabstraction.d.ts.map +1 -0
  15. package/build/modules/feeabstraction.js +462 -0
  16. package/build/modules/feeabstraction.js.map +1 -0
  17. package/build/modules/feemarket.d.ts +242 -0
  18. package/build/modules/feemarket.d.ts.map +1 -0
  19. package/build/modules/feemarket.js +296 -0
  20. package/build/modules/feemarket.js.map +1 -0
  21. package/build/modules/resource.d.ts +204 -0
  22. package/build/modules/resource.d.ts.map +1 -0
  23. package/build/modules/resource.js +297 -0
  24. package/build/modules/resource.js.map +1 -0
  25. package/build/package.json +64 -0
  26. package/build/querier.d.ts +62 -0
  27. package/build/querier.d.ts.map +1 -0
  28. package/build/querier.js +86 -0
  29. package/build/querier.js.map +1 -0
  30. package/build/registry.d.ts +18 -0
  31. package/build/registry.d.ts.map +1 -0
  32. package/build/registry.js +23 -0
  33. package/build/registry.js.map +1 -0
  34. package/build/signer.d.ts +190 -0
  35. package/build/signer.d.ts.map +1 -0
  36. package/build/signer.js +547 -0
  37. package/build/signer.js.map +1 -0
  38. package/build/types/index.d.ts +140 -0
  39. package/build/types/index.d.ts.map +1 -0
  40. package/build/types/modules/_.d.ts +62 -0
  41. package/build/types/modules/_.d.ts.map +1 -0
  42. package/build/types/modules/did.d.ts +386 -0
  43. package/build/types/modules/did.d.ts.map +1 -0
  44. package/build/types/modules/feeabstraction.d.ts +409 -0
  45. package/build/types/modules/feeabstraction.d.ts.map +1 -0
  46. package/build/types/modules/feemarket.d.ts +242 -0
  47. package/build/types/modules/feemarket.d.ts.map +1 -0
  48. package/build/types/modules/resource.d.ts +204 -0
  49. package/build/types/modules/resource.d.ts.map +1 -0
  50. package/build/types/querier.d.ts +62 -0
  51. package/build/types/querier.d.ts.map +1 -0
  52. package/build/types/registry.d.ts +18 -0
  53. package/build/types/registry.d.ts.map +1 -0
  54. package/build/types/signer.d.ts +190 -0
  55. package/build/types/signer.d.ts.map +1 -0
  56. package/build/types/types.d.ts +196 -0
  57. package/build/types/types.d.ts.map +1 -0
  58. package/build/types/utils.d.ts +223 -0
  59. package/build/types/utils.d.ts.map +1 -0
  60. package/build/types.d.ts +196 -0
  61. package/build/types.d.ts.map +1 -0
  62. package/build/types.js +43 -0
  63. package/build/types.js.map +1 -0
  64. package/build/utils.d.ts +223 -0
  65. package/build/utils.d.ts.map +1 -0
  66. package/build/utils.js +541 -0
  67. package/build/utils.js.map +1 -0
  68. package/package.json +64 -0
package/build/utils.js ADDED
@@ -0,0 +1,541 @@
1
+ import { VerificationMethods, MethodSpecificIdAlgo, CheqdNetwork, ServiceType, } from './types.js';
2
+ import { fromString, toString } from 'uint8arrays';
3
+ import { bases } from 'multiformats/basics';
4
+ import { base64ToBytes } from 'did-jwt';
5
+ import { generateKeyPair, generateKeyPairFromSeed } from '@stablelib/ed25519';
6
+ import { DirectSecp256k1HdWallet, DirectSecp256k1Wallet } from '@cosmjs/proto-signing';
7
+ import { EnglishMnemonic as _, sha256 } from '@cosmjs/crypto';
8
+ import { rawSecp256k1PubkeyToRawAddress } from '@cosmjs/amino';
9
+ import pkg from 'secp256k1';
10
+ import { v4 } from 'uuid';
11
+ import { VerificationMethod as ProtoVerificationMethod, Service as ProtoService, MsgCreateDidDocPayload, MsgDeactivateDidDocPayload, } from '@cheqd/ts-proto/cheqd/did/v2/index.js';
12
+ import { contexts, DIDModule } from './modules/did.js';
13
+ import { MsgCreateResourcePayload } from '@cheqd/ts-proto/cheqd/resource/v2/index.js';
14
+ import { toBech32 } from '@cosmjs/encoding';
15
+ import { StargateClient } from '@cosmjs/stargate';
16
+ import { backOff } from 'exponential-backoff';
17
+ /**
18
+ * Utility object for validating TImportableEd25519Key objects.
19
+ * Provides type guard functionality to ensure key structure integrity.
20
+ */
21
+ export const TImportableEd25519Key = {
22
+ /**
23
+ * Type guard to validate if an object is a valid TImportableEd25519Key.
24
+ *
25
+ * @param key - Object to validate
26
+ * @returns True if the object is a valid TImportableEd25519Key
27
+ */
28
+ isValid(key) {
29
+ return (typeof key === 'object' &&
30
+ key !== null &&
31
+ typeof key.publicKeyHex === 'string' &&
32
+ isHex(key.publicKeyHex) &&
33
+ typeof key.privateKeyHex === 'string' &&
34
+ isHex(key.privateKeyHex) &&
35
+ typeof key.kid === 'string' &&
36
+ key.type === 'Ed25519');
37
+ },
38
+ };
39
+ /** Multicodec header for Ed25519 public keys */
40
+ const MULTICODEC_ED25519_HEADER = new Uint8Array([0xed, 0x01]);
41
+ /**
42
+ * Compares two arrays of key-value pairs for equality.
43
+ *
44
+ * @param kv1 - First array of key-value pairs
45
+ * @param kv2 - Second array of key-value pairs
46
+ * @returns True if both arrays contain identical key-value pairs in the same order
47
+ */
48
+ export function isEqualKeyValuePair(kv1, kv2) {
49
+ return kv1.every((item, index) => item.key === kv2[index].key && item.value === kv2[index].value);
50
+ }
51
+ /**
52
+ * Extended English mnemonic class with additional validation patterns.
53
+ * Provides regex pattern matching for mnemonic phrase validation.
54
+ */
55
+ export class EnglishMnemonic extends _ {
56
+ /** Regular expression pattern for validating English mnemonic phrases */
57
+ static _mnemonicMatcher = /^[a-z]+( [a-z]+)*$/;
58
+ }
59
+ /**
60
+ * Creates signing inputs from an importable Ed25519 key by matching it with verification methods.
61
+ * Supports multiple verification method types and key formats.
62
+ *
63
+ * @param key - The Ed25519 key to create signing inputs from
64
+ * @param verificationMethod - Array of verification methods to match against
65
+ * @returns Signing inputs containing verification method ID and private key
66
+ * @throws Error if key validation fails or no matching verification method is found
67
+ */
68
+ export function createSignInputsFromImportableEd25519Key(key, verificationMethod) {
69
+ if (!TImportableEd25519Key.isValid(key))
70
+ throw new Error(`Key validation failed. Expected ${Object.values(TImportableEd25519Key).join(', ')}`);
71
+ const publicKey = fromString(key.publicKeyHex, 'hex');
72
+ for (const method of verificationMethod) {
73
+ switch (method.type) {
74
+ case VerificationMethods.Ed255192020:
75
+ const publicKeyMultibase = toMultibaseRaw(publicKey);
76
+ if (method.publicKeyMultibase === publicKeyMultibase) {
77
+ return {
78
+ verificationMethodId: method.id,
79
+ privateKeyHex: key.privateKeyHex,
80
+ };
81
+ }
82
+ case VerificationMethods.Ed255192018:
83
+ const publicKeyBase58 = bases['base58btc'].encode(publicKey).slice(1);
84
+ if (method.publicKeyBase58 === publicKeyBase58) {
85
+ return {
86
+ verificationMethodId: method.id,
87
+ privateKeyHex: key.privateKeyHex,
88
+ };
89
+ }
90
+ case VerificationMethods.JWK:
91
+ const publicKeyJwk = {
92
+ crv: 'Ed25519',
93
+ kty: 'OKP',
94
+ x: toString(publicKey, 'base64url'),
95
+ };
96
+ if (JSON.stringify(method.publicKeyJwk) === JSON.stringify(publicKeyJwk)) {
97
+ return {
98
+ verificationMethodId: method.id,
99
+ privateKeyHex: key.privateKeyHex,
100
+ };
101
+ }
102
+ }
103
+ throw new Error(`Unsupported verification method type: ${method.type}. Expected one of: ${Object.values(VerificationMethods).join(', ')}`);
104
+ }
105
+ throw new Error(`No verification method type provided. Expected one of: ${Object.values(VerificationMethods).join(', ')}`);
106
+ }
107
+ /**
108
+ * Creates a raw Ed25519 key pair using the StableLib library.
109
+ *
110
+ * @param seed - Optional seed string for deterministic key generation
111
+ * @returns Raw KeyPair object with publicKey and secretKey as Uint8Arrays
112
+ */
113
+ export function createKeyPairRaw(seed) {
114
+ return seed ? generateKeyPairFromSeed(fromString(seed)) : generateKeyPair();
115
+ }
116
+ /**
117
+ * Creates an Ed25519 key pair with Base64-encoded keys.
118
+ *
119
+ * @param seed - Optional seed string for deterministic key generation
120
+ * @returns Key pair with Base64-encoded public and private keys
121
+ */
122
+ export function createKeyPairBase64(seed) {
123
+ const keyPair = seed ? generateKeyPairFromSeed(fromString(seed)) : generateKeyPair();
124
+ return {
125
+ publicKey: toString(keyPair.publicKey, 'base64'),
126
+ privateKey: toString(keyPair.secretKey, 'base64'),
127
+ };
128
+ }
129
+ /**
130
+ * Creates an Ed25519 key pair with hexadecimal-encoded keys.
131
+ *
132
+ * @param seed - Optional seed string for deterministic key generation
133
+ * @returns Key pair with hexadecimal-encoded public and private keys
134
+ */
135
+ export function createKeyPairHex(seed) {
136
+ const keyPair = createKeyPairRaw(seed);
137
+ return {
138
+ publicKey: toString(keyPair.publicKey, 'hex'),
139
+ privateKey: toString(keyPair.secretKey, 'hex'),
140
+ };
141
+ }
142
+ /**
143
+ * Creates verification keys structure with DID URLs and key identifiers.
144
+ * Supports multiple algorithm types and network configurations.
145
+ *
146
+ * @param publicKey - Public key in base64 or hex format
147
+ * @param algo - Algorithm for method-specific ID generation
148
+ * @param keyFragment - Key fragment for the verification key identifier
149
+ * @param network - Cheqd network (defaults to Testnet)
150
+ * @param methodSpecificId - Optional pre-computed method-specific ID
151
+ * @param didUrl - Optional pre-computed DID URL
152
+ * @returns Verification keys structure with all identifiers
153
+ * @throws Error if public key format is invalid
154
+ */
155
+ export function createVerificationKeys(publicKey, algo, keyFragment, network = CheqdNetwork.Testnet, methodSpecificId, didUrl) {
156
+ if (isHex(publicKey)) {
157
+ publicKey = toString(fromString(publicKey, 'hex'), 'base64');
158
+ }
159
+ else if (!isBase64(publicKey)) {
160
+ throw new Error('publicKey validation failed. PublicKey should be in base64 or hex format');
161
+ }
162
+ switch (algo) {
163
+ case MethodSpecificIdAlgo.Base58:
164
+ methodSpecificId ||= bases['base58btc'].encode(base64ToBytes(publicKey));
165
+ didUrl ||= `did:cheqd:${network}:${bases['base58btc']
166
+ .encode(sha256(base64ToBytes(publicKey)).slice(0, 16))
167
+ .slice(1)}`;
168
+ return {
169
+ methodSpecificId,
170
+ didUrl,
171
+ keyId: `${didUrl}#${keyFragment}`,
172
+ publicKey,
173
+ };
174
+ case MethodSpecificIdAlgo.Uuid:
175
+ methodSpecificId ||= v4();
176
+ didUrl ||= `did:cheqd:${network}:${methodSpecificId}`;
177
+ return {
178
+ methodSpecificId,
179
+ didUrl,
180
+ keyId: `${didUrl}#${keyFragment}`,
181
+ publicKey,
182
+ };
183
+ }
184
+ }
185
+ /**
186
+ * Creates DID verification methods from verification method types and keys.
187
+ * Supports Ed25519 keys in multiple formats (multibase, base58, JWK).
188
+ *
189
+ * @param verificationMethodTypes - Array of verification method types to create
190
+ * @param verificationKeys - Array of verification keys corresponding to each type
191
+ * @returns Array of formatted verification methods for DID documents
192
+ */
193
+ export function createDidVerificationMethod(verificationMethodTypes, verificationKeys) {
194
+ return (verificationMethodTypes.map((type, _) => {
195
+ switch (type) {
196
+ case VerificationMethods.Ed255192020:
197
+ return {
198
+ id: verificationKeys[_].keyId,
199
+ type,
200
+ controller: verificationKeys[_].didUrl,
201
+ publicKeyMultibase: toMultibaseRaw(base64ToBytes(verificationKeys[_].publicKey)),
202
+ };
203
+ case VerificationMethods.Ed255192018:
204
+ return {
205
+ id: verificationKeys[_].keyId,
206
+ type,
207
+ controller: verificationKeys[_].didUrl,
208
+ publicKeyBase58: bases['base58btc']
209
+ .encode(base64ToBytes(verificationKeys[_].publicKey))
210
+ .slice(1),
211
+ };
212
+ case VerificationMethods.JWK:
213
+ return {
214
+ id: verificationKeys[_].keyId,
215
+ type,
216
+ controller: verificationKeys[_].didUrl,
217
+ publicKeyJwk: {
218
+ crv: 'Ed25519',
219
+ kty: 'OKP',
220
+ x: toString(fromString(verificationKeys[_].publicKey, 'base64pad'), 'base64url'),
221
+ },
222
+ };
223
+ }
224
+ }) ?? []);
225
+ }
226
+ /**
227
+ * Creates a complete DID document payload with verification methods and controllers.
228
+ *
229
+ * @param verificationMethods - Array of verification methods for the DID
230
+ * @param verificationKeys - Array of verification keys for authentication
231
+ * @param controller - Optional array of controller DIDs (defaults to self-controlled)
232
+ * @returns Complete DID document with all required fields
233
+ * @throws Error if verification methods or keys are missing
234
+ */
235
+ export function createDidPayload(verificationMethods, verificationKeys, controller = []) {
236
+ if (!verificationMethods || verificationMethods.length === 0)
237
+ throw new Error('No verification methods provided');
238
+ if (!verificationKeys || verificationKeys.length === 0)
239
+ throw new Error('No verification keys provided');
240
+ const did = verificationKeys[0].didUrl;
241
+ return {
242
+ id: did,
243
+ controller: controller.length ? controller : Array.from(new Set(verificationKeys.map((key) => key.didUrl))),
244
+ verificationMethod: verificationMethods,
245
+ authentication: verificationKeys.map((key) => key.keyId),
246
+ assertionMethod: verificationKeys.map((key) => key.keyId),
247
+ };
248
+ }
249
+ /**
250
+ * Validates a DID document against the Cheqd specification and converts to protobuf format.
251
+ * Ensures all required fields are present and verification methods are supported.
252
+ *
253
+ * @param didDocument - DID document to validate
254
+ * @returns Validation result with protobuf conversion or error details
255
+ */
256
+ export function validateSpecCompliantPayload(didDocument) {
257
+ // id is required, validated on both compile and runtime
258
+ if (!didDocument?.id)
259
+ return { valid: false, error: 'id is required' };
260
+ // verificationMethod is required
261
+ if (!didDocument?.verificationMethod)
262
+ return { valid: false, error: 'verificationMethod is required' };
263
+ // verificationMethod must be an array
264
+ if (!Array.isArray(didDocument?.verificationMethod))
265
+ return { valid: false, error: 'verificationMethod must be an array' };
266
+ // verificationMethod types must be supported
267
+ const protoVerificationMethod = didDocument.verificationMethod.map((vm) => {
268
+ switch (vm?.type) {
269
+ case VerificationMethods.Ed255192020:
270
+ if (!vm.publicKeyMultibase)
271
+ throw new Error('publicKeyMultibase is required');
272
+ return ProtoVerificationMethod.fromPartial({
273
+ id: vm.id,
274
+ controller: vm.controller,
275
+ verificationMethodType: VerificationMethods.Ed255192020,
276
+ verificationMaterial: vm.publicKeyMultibase,
277
+ });
278
+ case VerificationMethods.JWK:
279
+ if (!vm.publicKeyJwk)
280
+ throw new Error('publicKeyJwk is required');
281
+ return ProtoVerificationMethod.fromPartial({
282
+ id: vm.id,
283
+ controller: vm.controller,
284
+ verificationMethodType: VerificationMethods.JWK,
285
+ verificationMaterial: JSON.stringify(vm.publicKeyJwk),
286
+ });
287
+ case VerificationMethods.Ed255192018:
288
+ if (!vm.publicKeyBase58)
289
+ throw new Error('publicKeyBase58 is required');
290
+ return ProtoVerificationMethod.fromPartial({
291
+ id: vm.id,
292
+ controller: vm.controller,
293
+ verificationMethodType: VerificationMethods.Ed255192018,
294
+ verificationMaterial: vm.publicKeyBase58,
295
+ });
296
+ default:
297
+ throw new Error(`Unsupported verificationMethod type: ${vm?.type}`);
298
+ }
299
+ });
300
+ const protoService = normalizeService(didDocument);
301
+ return { valid: true, protobufVerificationMethod: protoVerificationMethod, protobufService: protoService };
302
+ }
303
+ /**
304
+ * Creates a Cosmos wallet from a seed phrase or private key.
305
+ * Supports both HD wallets from mnemonics and direct key wallets.
306
+ *
307
+ * @param cosmosPayerSeed - Mnemonic phrase or private key hex string
308
+ * @returns Promise resolving to either HD wallet or direct key wallet
309
+ */
310
+ export function createCosmosPayerWallet(cosmosPayerSeed) {
311
+ return EnglishMnemonic._mnemonicMatcher.test(cosmosPayerSeed)
312
+ ? DirectSecp256k1HdWallet.fromMnemonic(cosmosPayerSeed, { prefix: 'cheqd' })
313
+ : DirectSecp256k1Wallet.fromKey(fromString(cosmosPayerSeed.replace(/^0x/, ''), 'hex'), 'cheqd');
314
+ }
315
+ /**
316
+ * Converts a raw Ed25519 public key to multibase format with proper multicodec header.
317
+ *
318
+ * @param key - Raw Ed25519 public key as Uint8Array
319
+ * @returns Multibase-encoded string with Ed25519 multicodec prefix
320
+ */
321
+ export function toMultibaseRaw(key) {
322
+ const multibase = new Uint8Array(MULTICODEC_ED25519_HEADER.length + key.length);
323
+ multibase.set(MULTICODEC_ED25519_HEADER);
324
+ multibase.set(key, MULTICODEC_ED25519_HEADER.length);
325
+ return bases['base58btc'].encode(multibase);
326
+ }
327
+ /**
328
+ * Creates a MsgCreateDidDoc payload ready for signing.
329
+ * Validates the DID document and converts it to protobuf format.
330
+ *
331
+ * @param didPayload - DID document to create message payload from
332
+ * @param versionId - Version identifier for the DID document
333
+ * @returns Encoded message payload bytes ready for signing
334
+ */
335
+ export async function createMsgCreateDidDocPayloadToSign(didPayload, versionId) {
336
+ const { protobufVerificationMethod, protobufService } = await DIDModule.validateSpecCompliantPayload(didPayload);
337
+ return MsgCreateDidDocPayload.encode(MsgCreateDidDocPayload.fromPartial({
338
+ context: didPayload?.['@context'],
339
+ id: didPayload.id,
340
+ controller: didPayload.controller,
341
+ verificationMethod: protobufVerificationMethod,
342
+ authentication: didPayload.authentication,
343
+ assertionMethod: didPayload.assertionMethod,
344
+ capabilityInvocation: didPayload.capabilityInvocation,
345
+ capabilityDelegation: didPayload.capabilityDelegation,
346
+ keyAgreement: didPayload.keyAgreement,
347
+ service: protobufService,
348
+ alsoKnownAs: didPayload.alsoKnownAs,
349
+ versionId,
350
+ })).finish();
351
+ }
352
+ /** Alias for createMsgCreateDidDocPayloadToSign - used for DID document updates */
353
+ export const createMsgUpdateDidDocPayloadToSign = createMsgCreateDidDocPayloadToSign;
354
+ /**
355
+ * Creates a MsgDeactivateDidDoc payload ready for signing.
356
+ *
357
+ * @param didPayload - DID document containing the ID to deactivate
358
+ * @param versionId - Optional version identifier for the DID document
359
+ * @returns Encoded message payload bytes ready for signing
360
+ */
361
+ export function createMsgDeactivateDidDocPayloadToSign(didPayload, versionId) {
362
+ return MsgDeactivateDidDocPayload.encode(MsgDeactivateDidDocPayload.fromPartial({
363
+ id: didPayload.id,
364
+ versionId,
365
+ })).finish();
366
+ }
367
+ /**
368
+ * Creates a resource payload ready for signing.
369
+ *
370
+ * @param payload - Resource payload to encode
371
+ * @returns Encoded resource payload bytes ready for signing
372
+ */
373
+ export function createMsgResourcePayloadToSign(payload) {
374
+ return MsgCreateResourcePayload.encode(MsgCreateResourcePayload.fromPartial(payload)).finish();
375
+ }
376
+ /**
377
+ * Converts a public key to a Cosmos account address.
378
+ *
379
+ * @param publicKeyHex - Public key in hexadecimal format
380
+ * @returns Bech32-encoded Cosmos account address with 'cheqd' prefix
381
+ */
382
+ export function getCosmosAccount(publicKeyHex) {
383
+ const { publicKeyConvert } = pkg;
384
+ return toBech32('cheqd', rawSecp256k1PubkeyToRawAddress(publicKeyConvert(fromString(publicKeyHex, 'hex'), true)));
385
+ }
386
+ /**
387
+ * Checks the balance of all coins for a given address on the blockchain.
388
+ *
389
+ * @param address - Bech32-encoded account address to check balance for
390
+ * @param rpcAddress - RPC endpoint URL of the blockchain node
391
+ * @returns Promise resolving to array of coin balances
392
+ */
393
+ export async function checkBalance(address, rpcAddress) {
394
+ const client = await StargateClient.connect(rpcAddress);
395
+ return await client.getAllBalances(address);
396
+ }
397
+ /**
398
+ * Checks if a given input is valid JSON.
399
+ *
400
+ * @param input - Input to validate as JSON
401
+ * @returns True if the input is a valid JSON string
402
+ */
403
+ export function isJSON(input) {
404
+ if (typeof input !== 'string')
405
+ return false;
406
+ try {
407
+ JSON.parse(input);
408
+ return true;
409
+ }
410
+ catch (e) {
411
+ return false;
412
+ }
413
+ }
414
+ /** Default configuration options for exponential backoff retry logic */
415
+ export const DefaultBackoffOptions = {
416
+ jitter: 'full',
417
+ timeMultiple: 1,
418
+ delayFirstAttempt: false,
419
+ maxDelay: 100,
420
+ startingDelay: 100,
421
+ numOfAttempts: 3,
422
+ };
423
+ export async function retry(fn, options) {
424
+ // set default options
425
+ if (!options) {
426
+ options = DefaultBackoffOptions;
427
+ }
428
+ else {
429
+ // overwrite defaults with user supplied options
430
+ options = { ...DefaultBackoffOptions, ...options };
431
+ }
432
+ let result;
433
+ try {
434
+ result = await backOff(fn, options);
435
+ }
436
+ catch (e) {
437
+ console.error(e);
438
+ }
439
+ return result;
440
+ }
441
+ function isBase64(str) {
442
+ // Quick pattern check to filter obvious non-base64 strings
443
+ const base64Pattern = /^[A-Za-z0-9+/]*={0,3}$/;
444
+ if (!base64Pattern.test(str)) {
445
+ return false;
446
+ }
447
+ try {
448
+ return toString(fromString(str, 'base64'), 'base64') === str;
449
+ }
450
+ catch (e) {
451
+ return false;
452
+ }
453
+ }
454
+ function isHex(str) {
455
+ // Quick pattern check to filter obvious non-hex strings
456
+ const hexPattern = /^[0-9a-fA-F]*$/;
457
+ if (!hexPattern.test(str)) {
458
+ return false;
459
+ }
460
+ try {
461
+ return toString(fromString(str, 'hex'), 'hex') === str;
462
+ }
463
+ catch {
464
+ return false;
465
+ }
466
+ }
467
+ /**
468
+ * Normalizes the authentication property of a DID document to an array of strings.
469
+ * Extracts authentication method identifiers from mixed string/object format.
470
+ *
471
+ * @param didDocument - DID document to normalize authentication for
472
+ * @returns Array of authentication method identifiers
473
+ * @throws Error if authentication section is missing
474
+ */
475
+ export function normalizeAuthentication(didDocument) {
476
+ if (!didDocument.authentication)
477
+ throw new Error('Invalid DID Document: Authentication section is required in DID Document');
478
+ const authArray = Array.isArray(didDocument.authentication)
479
+ ? didDocument.authentication
480
+ : [didDocument.authentication];
481
+ return authArray.map((a) => (typeof a === 'string' ? a : a.id));
482
+ }
483
+ /**
484
+ * Normalizes the controller property of a DID document to an array of strings.
485
+ * Defaults to self-controlled if no controller is specified.
486
+ *
487
+ * @param didDocument - DID document to normalize controller for
488
+ * @returns Array of controller DID identifiers
489
+ */
490
+ export function normalizeController(didDocument) {
491
+ if (!didDocument.controller)
492
+ return [didDocument.id];
493
+ return Array.isArray(didDocument.controller) ? didDocument.controller : [didDocument.controller];
494
+ }
495
+ /**
496
+ * Normalizes DID document services to protobuf format.
497
+ * Converts service endpoints to arrays and includes optional properties.
498
+ *
499
+ * @param didDocument - DID document containing services to normalize
500
+ * @returns Array of protobuf-formatted services or undefined if no services
501
+ */
502
+ export function normalizeService(didDocument) {
503
+ return didDocument.service?.map((s) => {
504
+ return ProtoService.fromPartial({
505
+ id: s?.id,
506
+ serviceType: s?.type,
507
+ serviceEndpoint: s ? (Array.isArray(s.serviceEndpoint) ? s.serviceEndpoint : [s.serviceEndpoint]) : [],
508
+ ...(s?.recipientKeys && { recipientKeys: s.recipientKeys }),
509
+ ...(s?.routingKeys && { routingKeys: s.routingKeys }),
510
+ ...(s?.accept && { accept: s.accept }),
511
+ ...(s?.priority !== undefined && { priority: s.priority }),
512
+ });
513
+ });
514
+ }
515
+ /**
516
+ * Converts protobuf services back to standard DID document service format.
517
+ * Handles special context requirements for LinkedDomains services.
518
+ *
519
+ * @param didDocument - Protobuf DID document containing services to denormalize
520
+ * @returns Array of standard DID document services
521
+ */
522
+ export function denormalizeService(didDocument) {
523
+ return didDocument.service.map((s) => {
524
+ if (s.serviceType === ServiceType.LinkedDomains)
525
+ didDocument.context = [...didDocument.context, contexts.LinkedDomainsContext];
526
+ return {
527
+ id: s.id,
528
+ type: s.serviceType,
529
+ serviceEndpoint: Array.isArray(s.serviceEndpoint)
530
+ ? s.serviceEndpoint.length === 1
531
+ ? s.serviceEndpoint[0]
532
+ : s.serviceEndpoint
533
+ : s?.serviceEndpoint,
534
+ ...(s.recipientKeys && { recipientKeys: s.recipientKeys }),
535
+ ...(s.routingKeys && { routingKeys: s.routingKeys }),
536
+ ...(s.accept && { accept: s.accept }),
537
+ ...(s.priority !== undefined && { priority: s.priority }),
538
+ };
539
+ });
540
+ }
541
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,mBAAmB,EAEnB,oBAAoB,EAGpB,YAAY,EAOZ,WAAW,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,eAA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CAAC,aAAa,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC,aAAa,EAAE,CAAC;YAC1D,GAAG,CAAC,CAAC,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;YACpD,GAAG,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;YACrC,GAAG,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;SACzD,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@cheqd/sdk-esm",
3
+ "version": "5.3.4-develop.2",
4
+ "description": "A TypeScript SDK built with CosmJS to interact with cheqd network ledger",
5
+ "license": "Apache-2.0",
6
+ "author": "Cheqd Foundation Limited (https://github.com/cheqd)",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./build/types/index.d.ts",
11
+ "import": "./build/index.js",
12
+ "default": "./build/index.js"
13
+ },
14
+ "./*": {
15
+ "types": "./build/types/*.d.ts",
16
+ "import": "./build/*.js",
17
+ "default": "./build/*.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "build"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "scripts": {
27
+ "test": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest --colors --passWithNoTests --maxWorkers 1 --maxConcurrency 1",
28
+ "test:watch": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest --colors --passWithNoTests --maxWorkers 1 --maxConcurrency 1 --watch",
29
+ "build": "npm run build:types && npm run build:esm",
30
+ "build:types": "tsc -p tsconfig.types.json",
31
+ "build:esm": "tsc -p tsconfig.json",
32
+ "format": "prettier --write '**/*.{js,ts,cjs,mjs,json}'"
33
+ },
34
+ "dependencies": {
35
+ "@cheqd/ts-proto": "^4.1.1",
36
+ "@cosmjs/amino": "^0.33.1",
37
+ "@cosmjs/crypto": "^0.33.1",
38
+ "@cosmjs/encoding": "^0.33.1",
39
+ "@cosmjs/math": "^0.33.1",
40
+ "@cosmjs/proto-signing": "^0.33.1",
41
+ "@cosmjs/stargate": "^0.33.1",
42
+ "@cosmjs/tendermint-rpc": "^0.33.1",
43
+ "@cosmjs/utils": "^0.33.1",
44
+ "@stablelib/ed25519": "^2.0.2",
45
+ "@types/secp256k1": "^4.0.6",
46
+ "cosmjs-types": "^0.9.0",
47
+ "did-jwt": "^8.0.16",
48
+ "did-resolver": "^4.1.0",
49
+ "exponential-backoff": "^3.1.2",
50
+ "file-type": "^21.0.0",
51
+ "multiformats": "^13.3.6",
52
+ "secp256k1": "^5.0.1",
53
+ "uint8arrays": "^5.1.0",
54
+ "uuid": "^11.1.0"
55
+ },
56
+ "devDependencies": {
57
+ "@types/node": "^22.15.30",
58
+ "@types/uuid": "^10.0.0",
59
+ "cross-env": "^7.0.3"
60
+ },
61
+ "engines": {
62
+ "node": ">=22.0.0"
63
+ }
64
+ }