diff --git a/.pnp.cjs b/.pnp.cjs index 90b9c4f147a..c663d0f1304 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -190,7 +190,7 @@ const RAW_RUNTIME_STATE = ["@apidevtools/json-schema-ref-parser", "npm:8.0.0"],\ ["@jsdevtools/ono", "npm:7.1.3"],\ ["call-me-maybe", "npm:1.0.1"],\ - ["js-yaml", "npm:3.14.1"]\ + ["js-yaml", "npm:4.1.1"]\ ],\ "linkType": "HARD"\ }]\ @@ -3295,7 +3295,7 @@ const RAW_RUNTIME_STATE = ["globals", "npm:13.23.0"],\ ["ignore", "npm:5.2.0"],\ ["import-fresh", "npm:3.3.0"],\ - ["js-yaml", "npm:4.1.0"],\ + ["js-yaml", "npm:4.1.1"],\ ["minimatch", "npm:3.1.2"],\ ["strip-json-comments", "npm:3.1.1"]\ ],\ @@ -3487,7 +3487,7 @@ const RAW_RUNTIME_STATE = ["camelcase", "npm:5.3.1"],\ ["find-up", "npm:4.1.0"],\ ["get-package-type", "npm:0.1.0"],\ - ["js-yaml", "npm:3.14.1"],\ + ["js-yaml", "npm:4.1.1"],\ ["resolve-from", "npm:5.0.0"]\ ],\ "linkType": "HARD"\ @@ -3950,7 +3950,7 @@ const RAW_RUNTIME_STATE = ["hyperlinker", "npm:1.0.0"],\ ["indent-string", "npm:4.0.0"],\ ["is-wsl", "npm:2.2.0"],\ - ["js-yaml", "npm:3.14.1"],\ + ["js-yaml", "npm:4.1.1"],\ ["natural-orderby", "npm:2.0.3"],\ ["object-treeify", "npm:1.1.33"],\ ["password-prompt", "npm:1.1.2"],\ @@ -3984,7 +3984,7 @@ const RAW_RUNTIME_STATE = ["hyperlinker", "npm:1.0.0"],\ ["indent-string", "npm:4.0.0"],\ ["is-wsl", "npm:2.2.0"],\ - ["js-yaml", "npm:3.14.1"],\ + ["js-yaml", "npm:4.1.1"],\ ["natural-orderby", "npm:2.0.3"],\ ["object-treeify", "npm:1.1.33"],\ ["password-prompt", "npm:1.1.2"],\ @@ -4019,7 +4019,7 @@ const RAW_RUNTIME_STATE = ["hyperlinker", "npm:1.0.0"],\ ["indent-string", "npm:4.0.0"],\ ["is-wsl", "npm:2.2.0"],\ - ["js-yaml", "npm:3.14.1"],\ + ["js-yaml", "npm:4.1.1"],\ ["minimatch", "npm:9.0.5"],\ ["natural-orderby", "npm:2.0.3"],\ ["object-treeify", "npm:1.1.33"],\ @@ -5909,7 +5909,7 @@ const RAW_RUNTIME_STATE = "packageLocation": "./.yarn/cache/@yarnpkg-parsers-npm-3.0.0-rc.42-ee17ab0275-3488f9dba1.zip/node_modules/@yarnpkg/parsers/",\ "packageDependencies": [\ ["@yarnpkg/parsers", "npm:3.0.0-rc.42"],\ - ["js-yaml", "npm:3.14.1"],\ + ["js-yaml", "npm:4.1.1"],\ ["tslib", "npm:2.6.2"]\ ],\ "linkType": "HARD"\ @@ -8943,7 +8943,7 @@ const RAW_RUNTIME_STATE = ["hasbin", "npm:1.2.3"],\ ["is-wsl", "npm:2.2.0"],\ ["jayson", "npm:4.1.0"],\ - ["js-yaml", "npm:4.1.0"],\ + ["js-yaml", "npm:4.1.1"],\ ["listr2", "virtual:880cda903c2a2be387819a3f857d21494004437a03c92969b9853f7bdeebdfed08d417e68364ee9e158338603a6d78d690c457a55ab11e56398bc10f0ad232fc#npm:5.0.7"],\ ["lodash", "npm:4.17.21"],\ ["memory-streams", "npm:0.1.3"],\ @@ -10161,7 +10161,7 @@ const RAW_RUNTIME_STATE = ["imurmurhash", "npm:0.1.4"],\ ["is-glob", "npm:4.0.3"],\ ["is-path-inside", "npm:3.0.3"],\ - ["js-yaml", "npm:4.1.0"],\ + ["js-yaml", "npm:4.1.1"],\ ["json-stable-stringify-without-jsonify", "npm:1.0.1"],\ ["levn", "npm:0.4.1"],\ ["lodash.merge", "npm:4.6.2"],\ @@ -13127,28 +13127,10 @@ const RAW_RUNTIME_STATE = }]\ ]],\ ["js-yaml", [\ - ["npm:3.13.1", {\ - "packageLocation": "./.yarn/cache/js-yaml-npm-3.13.1-3a28ff3b75-cec89175b0.zip/node_modules/js-yaml/",\ - "packageDependencies": [\ - ["js-yaml", "npm:3.13.1"],\ - ["argparse", "npm:1.0.10"],\ - ["esprima", "npm:4.0.1"]\ - ],\ - "linkType": "HARD"\ - }],\ - ["npm:3.14.1", {\ - "packageLocation": "./.yarn/cache/js-yaml-npm-3.14.1-b968c6095e-9e22d80b4d.zip/node_modules/js-yaml/",\ - "packageDependencies": [\ - ["js-yaml", "npm:3.14.1"],\ - ["argparse", "npm:1.0.10"],\ - ["esprima", "npm:4.0.1"]\ - ],\ - "linkType": "HARD"\ - }],\ - ["npm:4.1.0", {\ - "packageLocation": "./.yarn/cache/js-yaml-npm-4.1.0-3606f32312-c138a34a3f.zip/node_modules/js-yaml/",\ + ["npm:4.1.1", {\ + "packageLocation": "./.yarn/cache/js-yaml-npm-4.1.1-86ec786790-a52d0519f0.zip/node_modules/js-yaml/",\ "packageDependencies": [\ - ["js-yaml", "npm:4.1.0"],\ + ["js-yaml", "npm:4.1.1"],\ ["argparse", "npm:2.0.1"]\ ],\ "linkType": "HARD"\ @@ -13263,7 +13245,7 @@ const RAW_RUNTIME_STATE = "packageDependencies": [\ ["json-schema-ref-parser", "npm:7.1.4"],\ ["call-me-maybe", "npm:1.0.1"],\ - ["js-yaml", "npm:3.14.1"],\ + ["js-yaml", "npm:4.1.1"],\ ["ono", "npm:6.0.1"]\ ],\ "linkType": "HARD"\ @@ -13818,7 +13800,7 @@ const RAW_RUNTIME_STATE = "packageDependencies": [\ ["load-yaml-file", "npm:0.2.0"],\ ["graceful-fs", "npm:4.2.10"],\ - ["js-yaml", "npm:3.14.1"],\ + ["js-yaml", "npm:4.1.1"],\ ["pify", "npm:4.0.1"],\ ["strip-bom", "npm:3.0.0"]\ ],\ @@ -14841,7 +14823,7 @@ const RAW_RUNTIME_STATE = ["find-up", "npm:5.0.0"],\ ["glob", "npm:10.4.5"],\ ["he", "npm:1.2.0"],\ - ["js-yaml", "npm:4.1.0"],\ + ["js-yaml", "npm:4.1.1"],\ ["log-symbols", "npm:4.1.0"],\ ["minimatch", "npm:5.1.6"],\ ["ms", "npm:2.1.3"],\ @@ -18717,7 +18699,7 @@ const RAW_RUNTIME_STATE = ["commander", "npm:4.0.1"],\ ["doctrine", "npm:3.0.0"],\ ["glob", "npm:7.1.6"],\ - ["js-yaml", "npm:3.13.1"],\ + ["js-yaml", "npm:4.1.1"],\ ["swagger-parser", "npm:8.0.4"]\ ],\ "linkType": "HARD"\ diff --git a/.yarn/cache/fsevents-patch-19706e7e35-10.zip b/.yarn/cache/fsevents-patch-19706e7e35-10.zip new file mode 100644 index 00000000000..aff1ab12ce5 Binary files /dev/null and b/.yarn/cache/fsevents-patch-19706e7e35-10.zip differ diff --git a/.yarn/cache/js-yaml-npm-3.13.1-3a28ff3b75-cec89175b0.zip b/.yarn/cache/js-yaml-npm-3.13.1-3a28ff3b75-cec89175b0.zip deleted file mode 100644 index a3ef4910356..00000000000 Binary files a/.yarn/cache/js-yaml-npm-3.13.1-3a28ff3b75-cec89175b0.zip and /dev/null differ diff --git a/.yarn/cache/js-yaml-npm-3.14.1-b968c6095e-9e22d80b4d.zip b/.yarn/cache/js-yaml-npm-3.14.1-b968c6095e-9e22d80b4d.zip deleted file mode 100644 index 431983ca881..00000000000 Binary files a/.yarn/cache/js-yaml-npm-3.14.1-b968c6095e-9e22d80b4d.zip and /dev/null differ diff --git a/.yarn/cache/js-yaml-npm-4.1.0-3606f32312-c138a34a3f.zip b/.yarn/cache/js-yaml-npm-4.1.0-3606f32312-c138a34a3f.zip deleted file mode 100644 index b5be50a1221..00000000000 Binary files a/.yarn/cache/js-yaml-npm-4.1.0-3606f32312-c138a34a3f.zip and /dev/null differ diff --git a/.yarn/cache/js-yaml-npm-4.1.1-86ec786790-a52d0519f0.zip b/.yarn/cache/js-yaml-npm-4.1.1-86ec786790-a52d0519f0.zip new file mode 100644 index 00000000000..b32cf91aeb0 Binary files /dev/null and b/.yarn/cache/js-yaml-npm-4.1.1-86ec786790-a52d0519f0.zip differ diff --git a/package.json b/package.json index 910627aff86..bfcff6b6549 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,8 @@ "brace-expansion": "^2.0.2", "cipher-base": "^1.0.5", "sha.js": "^2.4.12", - "tmp": "^0.2.4" + "tmp": "^0.2.4", + "js-yaml": "^4.1.1" }, "dependencies": { "dompurify": "^3.2.6", diff --git a/packages/dashmate/package.json b/packages/dashmate/package.json index f29fd6b6a98..6dbcd95927b 100644 --- a/packages/dashmate/package.json +++ b/packages/dashmate/package.json @@ -79,7 +79,7 @@ "hasbin": "^1.2.3", "is-wsl": "2.2.0", "jayson": "^4.1.0", - "js-yaml": "^4.1.0", + "js-yaml": "^4.1.1", "listr2": "5.0.7", "lodash": "^4.17.21", "memory-streams": "^0.1.3", diff --git a/packages/js-evo-sdk/src/contracts/facade.ts b/packages/js-evo-sdk/src/contracts/facade.ts index 952e3ed19a3..d044bd1cb60 100644 --- a/packages/js-evo-sdk/src/contracts/facade.ts +++ b/packages/js-evo-sdk/src/contracts/facade.ts @@ -14,27 +14,27 @@ export class ContractsFacade { return w.getDataContract(contractId); } - async fetchWithProof(contractId: wasm.IdentifierLike): Promise { + async fetchWithProof(contractId: wasm.IdentifierLike): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getDataContractWithProofInfo(contractId); } - async getHistory(query: wasm.DataContractHistoryQuery): Promise { + async getHistory(query: wasm.DataContractHistoryQuery): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getDataContractHistory(query); } - async getHistoryWithProof(query: wasm.DataContractHistoryQuery): Promise { + async getHistoryWithProof(query: wasm.DataContractHistoryQuery): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getDataContractHistoryWithProofInfo(query); } - async getMany(contractIds: wasm.IdentifierLike[]): Promise { + async getMany(contractIds: wasm.IdentifierLike[]): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getDataContracts(contractIds); } - async getManyWithProof(contractIds: wasm.IdentifierLike[]): Promise { + async getManyWithProof(contractIds: wasm.IdentifierLike[]): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getDataContractsWithProofInfo(contractIds); } diff --git a/packages/js-evo-sdk/src/documents/facade.ts b/packages/js-evo-sdk/src/documents/facade.ts index 64545defa0a..0c7d9e370e0 100644 --- a/packages/js-evo-sdk/src/documents/facade.ts +++ b/packages/js-evo-sdk/src/documents/facade.ts @@ -10,22 +10,22 @@ export class DocumentsFacade { } // Query many documents - async query(query: wasm.DocumentsQuery): Promise { + async query(query: wasm.DocumentsQuery): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getDocuments(query); } - async queryWithProof(query: wasm.DocumentsQuery): Promise { + async queryWithProof(query: wasm.DocumentsQuery): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getDocumentsWithProofInfo(query); } - async get(contractId: wasm.IdentifierLike, type: string, documentId: wasm.IdentifierLike): Promise { + async get(contractId: wasm.IdentifierLike, type: string, documentId: wasm.IdentifierLike): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getDocument(contractId, type, documentId); } - async getWithProof(contractId: wasm.IdentifierLike, type: string, documentId: wasm.IdentifierLike): Promise { + async getWithProof(contractId: wasm.IdentifierLike, type: string, documentId: wasm.IdentifierLike): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getDocumentWithProofInfo(contractId, type, documentId); } diff --git a/packages/js-evo-sdk/src/dpns/facade.ts b/packages/js-evo-sdk/src/dpns/facade.ts index 3392554df34..d2daa0c8fcf 100644 --- a/packages/js-evo-sdk/src/dpns/facade.ts +++ b/packages/js-evo-sdk/src/dpns/facade.ts @@ -28,43 +28,43 @@ export class DpnsFacade { return w.dpnsIsNameAvailable(label); } - async resolveName(name: string): Promise { + async resolveName(name: string): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.dpnsResolveName(name); } - async registerName(args: { label: string; identityId: wasm.IdentifierLike; publicKeyId: number; privateKeyWif: string; onPreorder?: Function }): Promise { + async registerName(args: { label: string; identityId: wasm.IdentifierLike; publicKeyId: number; privateKeyWif: string; onPreorder?: Function }): Promise { const { label, identityId, publicKeyId, privateKeyWif, onPreorder } = args; const w = await this.sdk.getWasmSdkConnected(); return w.dpnsRegisterName(label, identityId, publicKeyId, privateKeyWif, onPreorder ?? null); } - async usernames(query: wasm.DpnsUsernamesQuery): Promise { + async usernames(query: wasm.DpnsUsernamesQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getDpnsUsernames(query); } - async username(identityId: wasm.IdentifierLike): Promise { + async username(identityId: wasm.IdentifierLike): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getDpnsUsername(identityId); } - async usernamesWithProof(query: wasm.DpnsUsernamesQuery): Promise { + async usernamesWithProof(query: wasm.DpnsUsernamesQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getDpnsUsernamesWithProofInfo(query); } - async usernameWithProof(identityId: wasm.IdentifierLike): Promise { + async usernameWithProof(identityId: wasm.IdentifierLike): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getDpnsUsernameWithProofInfo(identityId); } - async getUsernameByName(username: string): Promise { + async getUsernameByName(username: string): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getDpnsUsernameByName(username); } - async getUsernameByNameWithProof(username: string): Promise { + async getUsernameByNameWithProof(username: string): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getDpnsUsernameByNameWithProofInfo(username); } diff --git a/packages/js-evo-sdk/src/epoch/facade.ts b/packages/js-evo-sdk/src/epoch/facade.ts index f6f6ecfafe0..a7a49b9ab1f 100644 --- a/packages/js-evo-sdk/src/epoch/facade.ts +++ b/packages/js-evo-sdk/src/epoch/facade.ts @@ -1,3 +1,4 @@ +import * as wasm from '../wasm.js'; import type { EvoSDK } from '../sdk.js'; import type { EpochsQuery, @@ -9,45 +10,48 @@ export class EpochFacade { private sdk: EvoSDK; constructor(sdk: EvoSDK) { this.sdk = sdk; } - async epochsInfo(query: EpochsQuery = {}): Promise { + async epochsInfo(query: EpochsQuery = {}): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getEpochsInfo(query); } - async epochsInfoWithProof(query: EpochsQuery = {}): Promise { + async epochsInfoWithProof(query: EpochsQuery = {}): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getEpochsInfoWithProofInfo(query); } - async finalizedInfos(query: FinalizedEpochsQuery): Promise { + async finalizedInfos(query: FinalizedEpochsQuery): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getFinalizedEpochInfos(query); } - async finalizedInfosWithProof(query: FinalizedEpochsQuery): Promise { + async finalizedInfosWithProof(query: FinalizedEpochsQuery): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getFinalizedEpochInfosWithProofInfo(query); } - async current(): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getCurrentEpoch(); } - async currentWithProof(): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getCurrentEpochWithProofInfo(); } + async current(): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getCurrentEpoch(); } + async currentWithProof(): Promise> { + const w = await this.sdk.getWasmSdkConnected(); + return w.getCurrentEpochWithProofInfo(); + } - async evonodesProposedBlocksByIds(epoch: number, ids: string[]): Promise { + async evonodesProposedBlocksByIds(epoch: number, ids: string[]): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getEvonodesProposedEpochBlocksByIds(epoch, ids); } - async evonodesProposedBlocksByIdsWithProof(epoch: number, ids: string[]): Promise { + async evonodesProposedBlocksByIdsWithProof(epoch: number, ids: string[]): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getEvonodesProposedEpochBlocksByIdsWithProofInfo(epoch, ids); } - async evonodesProposedBlocksByRange(query: EvonodeProposedBlocksRangeQuery): Promise { + async evonodesProposedBlocksByRange(query: EvonodeProposedBlocksRangeQuery): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getEvonodesProposedEpochBlocksByRange(query); } - async evonodesProposedBlocksByRangeWithProof(query: EvonodeProposedBlocksRangeQuery): Promise { + async evonodesProposedBlocksByRangeWithProof(query: EvonodeProposedBlocksRangeQuery): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getEvonodesProposedEpochBlocksByRangeWithProofInfo(query); } diff --git a/packages/js-evo-sdk/src/group/facade.ts b/packages/js-evo-sdk/src/group/facade.ts index cae5291b4a3..fa6338b0a07 100644 --- a/packages/js-evo-sdk/src/group/facade.ts +++ b/packages/js-evo-sdk/src/group/facade.ts @@ -5,92 +5,92 @@ export class GroupFacade { private sdk: EvoSDK; constructor(sdk: EvoSDK) { this.sdk = sdk; } - async info(contractId: wasm.IdentifierLike, groupContractPosition: number): Promise { + async info(contractId: wasm.IdentifierLike, groupContractPosition: number): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getGroupInfo(contractId, groupContractPosition); } - async infoWithProof(contractId: wasm.IdentifierLike, groupContractPosition: number): Promise { + async infoWithProof(contractId: wasm.IdentifierLike, groupContractPosition: number): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getGroupInfoWithProofInfo(contractId, groupContractPosition); } - async infos(query: wasm.GroupInfosQuery): Promise { + async infos(query: wasm.GroupInfosQuery): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getGroupInfos(query); } - async infosWithProof(query: wasm.GroupInfosQuery): Promise { + async infosWithProof(query: wasm.GroupInfosQuery): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getGroupInfosWithProofInfo(query); } - async members(query: wasm.GroupMembersQuery): Promise { + async members(query: wasm.GroupMembersQuery): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getGroupMembers(query); } - async membersWithProof(query: wasm.GroupMembersQuery): Promise { + async membersWithProof(query: wasm.GroupMembersQuery): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getGroupMembersWithProofInfo(query); } - async identityGroups(query: wasm.IdentityGroupsQuery): Promise { + async identityGroups(query: wasm.IdentityGroupsQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityGroups(query); } - async identityGroupsWithProof(query: wasm.IdentityGroupsQuery): Promise { + async identityGroupsWithProof(query: wasm.IdentityGroupsQuery): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityGroupsWithProofInfo(query); } - async actions(query: wasm.GroupActionsQuery): Promise { + async actions(query: wasm.GroupActionsQuery): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getGroupActions(query); } - async actionsWithProof(query: wasm.GroupActionsQuery): Promise { + async actionsWithProof(query: wasm.GroupActionsQuery): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getGroupActionsWithProofInfo(query); } - async actionSigners(query: wasm.GroupActionSignersQuery): Promise { + async actionSigners(query: wasm.GroupActionSignersQuery): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getGroupActionSigners(query); } - async actionSignersWithProof(query: wasm.GroupActionSignersQuery): Promise { + async actionSignersWithProof(query: wasm.GroupActionSignersQuery): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getGroupActionSignersWithProofInfo(query); } - async groupsDataContracts(dataContractIds: wasm.IdentifierLike[]): Promise { + async groupsDataContracts(dataContractIds: wasm.IdentifierLike[]): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getGroupsDataContracts(dataContractIds); } - async groupsDataContractsWithProof(dataContractIds: wasm.IdentifierLike[]): Promise { + async groupsDataContractsWithProof(dataContractIds: wasm.IdentifierLike[]): Promise>>> { const w = await this.sdk.getWasmSdkConnected(); return w.getGroupsDataContractsWithProofInfo(dataContractIds); } - async contestedResources(query: wasm.VotePollsByDocumentTypeQuery): Promise { + async contestedResources(query: wasm.VotePollsByDocumentTypeQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getContestedResources(query); } - async contestedResourcesWithProof(query: wasm.VotePollsByDocumentTypeQuery): Promise { + async contestedResourcesWithProof(query: wasm.VotePollsByDocumentTypeQuery): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getContestedResourcesWithProofInfo(query); } - async contestedResourceVotersForIdentity(query: wasm.ContestedResourceVotersForIdentityQuery): Promise { + async contestedResourceVotersForIdentity(query: wasm.ContestedResourceVotersForIdentityQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getContestedResourceVotersForIdentity(query); } - async contestedResourceVotersForIdentityWithProof(query: wasm.ContestedResourceVotersForIdentityQuery): Promise { + async contestedResourceVotersForIdentityWithProof(query: wasm.ContestedResourceVotersForIdentityQuery): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getContestedResourceVotersForIdentityWithProofInfo(query); } diff --git a/packages/js-evo-sdk/src/identities/facade.ts b/packages/js-evo-sdk/src/identities/facade.ts index 6a356ef36ef..3ad1ccaa312 100644 --- a/packages/js-evo-sdk/src/identities/facade.ts +++ b/packages/js-evo-sdk/src/identities/facade.ts @@ -14,7 +14,7 @@ export class IdentitiesFacade { return w.getIdentity(identityId); } - async fetchWithProof(identityId: wasm.IdentifierLike): Promise { + async fetchWithProof(identityId: wasm.IdentifierLike): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityWithProofInfo(identityId); } @@ -24,62 +24,62 @@ export class IdentitiesFacade { return w.getIdentityUnproved(identityId); } - async getKeys(query: wasm.IdentityKeysQuery): Promise { + async getKeys(query: wasm.IdentityKeysQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityKeys(query); } - async getKeysWithProof(query: wasm.IdentityKeysQuery): Promise { + async getKeysWithProof(query: wasm.IdentityKeysQuery): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityKeysWithProofInfo(query); } - async nonce(identityId: wasm.IdentifierLike): Promise { + async nonce(identityId: wasm.IdentifierLike): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityNonce(identityId); } - async nonceWithProof(identityId: wasm.IdentifierLike): Promise { + async nonceWithProof(identityId: wasm.IdentifierLike): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityNonceWithProofInfo(identityId); } - async contractNonce(identityId: wasm.IdentifierLike, contractId: wasm.IdentifierLike): Promise { + async contractNonce(identityId: wasm.IdentifierLike, contractId: wasm.IdentifierLike): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityContractNonce(identityId, contractId); } - async contractNonceWithProof(identityId: wasm.IdentifierLike, contractId: wasm.IdentifierLike): Promise { + async contractNonceWithProof(identityId: wasm.IdentifierLike, contractId: wasm.IdentifierLike): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityContractNonceWithProofInfo(identityId, contractId); } - async balance(identityId: wasm.IdentifierLike): Promise { + async balance(identityId: wasm.IdentifierLike): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityBalance(identityId); } - async balanceWithProof(identityId: wasm.IdentifierLike): Promise { + async balanceWithProof(identityId: wasm.IdentifierLike): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityBalanceWithProofInfo(identityId); } - async balances(identityIds: wasm.IdentifierLike[]): Promise { + async balances(identityIds: wasm.IdentifierLike[]): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentitiesBalances(identityIds); } - async balancesWithProof(identityIds: wasm.IdentifierLike[]): Promise { + async balancesWithProof(identityIds: wasm.IdentifierLike[]): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentitiesBalancesWithProofInfo(identityIds); } - async balanceAndRevision(identityId: wasm.IdentifierLike): Promise { + async balanceAndRevision(identityId: wasm.IdentifierLike): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityBalanceAndRevision(identityId); } - async balanceAndRevisionWithProof(identityId: wasm.IdentifierLike): Promise { + async balanceAndRevisionWithProof(identityId: wasm.IdentifierLike): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityBalanceAndRevisionWithProofInfo(identityId); } @@ -89,37 +89,37 @@ export class IdentitiesFacade { return w.getIdentityByPublicKeyHash(publicKeyHash); } - async byPublicKeyHashWithProof(publicKeyHash: string | Uint8Array): Promise { + async byPublicKeyHashWithProof(publicKeyHash: string | Uint8Array): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityByPublicKeyHashWithProofInfo(publicKeyHash); } - async byNonUniquePublicKeyHash(publicKeyHash: string | Uint8Array, startAfter?: wasm.IdentifierLike): Promise { + async byNonUniquePublicKeyHash(publicKeyHash: string | Uint8Array, startAfter?: wasm.IdentifierLike): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityByNonUniquePublicKeyHash(publicKeyHash, startAfter); } - async byNonUniquePublicKeyHashWithProof(publicKeyHash: string | Uint8Array, startAfter?: wasm.IdentifierLike): Promise { + async byNonUniquePublicKeyHashWithProof(publicKeyHash: string | Uint8Array, startAfter?: wasm.IdentifierLike): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityByNonUniquePublicKeyHashWithProofInfo(publicKeyHash, startAfter || undefined); } - async contractKeys(query: wasm.IdentitiesContractKeysQuery): Promise { + async contractKeys(query: wasm.IdentitiesContractKeysQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentitiesContractKeys(query); } - async contractKeysWithProof(query: wasm.IdentitiesContractKeysQuery): Promise { + async contractKeysWithProof(query: wasm.IdentitiesContractKeysQuery): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentitiesContractKeysWithProofInfo(query); } - async tokenBalances(identityId: wasm.IdentifierLike, tokenIds: wasm.IdentifierLike[]): Promise { + async tokenBalances(identityId: wasm.IdentifierLike, tokenIds: wasm.IdentifierLike[]): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityTokenBalances(identityId, tokenIds); } - async tokenBalancesWithProof(identityId: wasm.IdentifierLike, tokenIds: wasm.IdentifierLike[]): Promise { + async tokenBalancesWithProof(identityId: wasm.IdentifierLike, tokenIds: wasm.IdentifierLike[]): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityTokenBalancesWithProofInfo(identityId, tokenIds); } diff --git a/packages/js-evo-sdk/src/protocol/facade.ts b/packages/js-evo-sdk/src/protocol/facade.ts index 353a05c289a..abc00076330 100644 --- a/packages/js-evo-sdk/src/protocol/facade.ts +++ b/packages/js-evo-sdk/src/protocol/facade.ts @@ -1,18 +1,25 @@ import type { EvoSDK } from '../sdk.js'; +import * as wasm from '../wasm.js'; export class ProtocolFacade { private sdk: EvoSDK; constructor(sdk: EvoSDK) { this.sdk = sdk; } - async versionUpgradeState(): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getProtocolVersionUpgradeState(); } - async versionUpgradeStateWithProof(): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getProtocolVersionUpgradeStateWithProofInfo(); } + async versionUpgradeState(): Promise { + const w = await this.sdk.getWasmSdkConnected(); + return w.getProtocolVersionUpgradeState(); + } + async versionUpgradeStateWithProof(): Promise> { + const w = await this.sdk.getWasmSdkConnected(); + return w.getProtocolVersionUpgradeStateWithProofInfo(); + } - async versionUpgradeVoteStatus(startProTxHash: string | Uint8Array, count: number): Promise { + async versionUpgradeVoteStatus(startProTxHash: string | Uint8Array, count: number): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getProtocolVersionUpgradeVoteStatus(startProTxHash, count); } - async versionUpgradeVoteStatusWithProof(startProTxHash: string | Uint8Array, count: number): Promise { + async versionUpgradeVoteStatusWithProof(startProTxHash: string | Uint8Array, count: number): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getProtocolVersionUpgradeVoteStatusWithProofInfo(startProTxHash, count); } diff --git a/packages/js-evo-sdk/src/system/facade.ts b/packages/js-evo-sdk/src/system/facade.ts index 8b82be3d77b..cc05526f00d 100644 --- a/packages/js-evo-sdk/src/system/facade.ts +++ b/packages/js-evo-sdk/src/system/facade.ts @@ -5,13 +5,48 @@ export class SystemFacade { private sdk: EvoSDK; constructor(sdk: EvoSDK) { this.sdk = sdk; } - async status(): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getStatus(); } - async currentQuorumsInfo(): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getCurrentQuorumsInfo(); } - async totalCreditsInPlatform(): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getTotalCreditsInPlatform(); } - async totalCreditsInPlatformWithProof(): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getTotalCreditsInPlatformWithProofInfo(); } - async prefundedSpecializedBalance(identityId: wasm.IdentifierLike): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getPrefundedSpecializedBalance(identityId); } - async prefundedSpecializedBalanceWithProof(identityId: wasm.IdentifierLike): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getPrefundedSpecializedBalanceWithProofInfo(identityId); } - async waitForStateTransitionResult(stateTransitionHash: string): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.waitForStateTransitionResult(stateTransitionHash); } - async pathElements(path: string[], keys: string[]): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getPathElements(path, keys); } - async pathElementsWithProof(path: string[], keys: string[]): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getPathElementsWithProofInfo(path, keys); } + async status(): Promise { + const w = await this.sdk.getWasmSdkConnected(); + return w.getStatus(); + } + + async currentQuorumsInfo(): Promise { + const w = await this.sdk.getWasmSdkConnected(); + return w.getCurrentQuorumsInfo(); + } + + async totalCreditsInPlatform(): Promise { + const w = await this.sdk.getWasmSdkConnected(); + return w.getTotalCreditsInPlatform(); + } + + async totalCreditsInPlatformWithProof(): Promise> { + const w = await this.sdk.getWasmSdkConnected(); + return w.getTotalCreditsInPlatformWithProofInfo(); + } + + async prefundedSpecializedBalance(identityId: wasm.IdentifierLike): Promise { + const w = await this.sdk.getWasmSdkConnected(); + return w.getPrefundedSpecializedBalance(identityId); + } + + async prefundedSpecializedBalanceWithProof(identityId: wasm.IdentifierLike): Promise> { + const w = await this.sdk.getWasmSdkConnected(); + return w.getPrefundedSpecializedBalanceWithProofInfo(identityId); + } + + async waitForStateTransitionResult(stateTransitionHash: string): Promise { + const w = await this.sdk.getWasmSdkConnected(); + return w.waitForStateTransitionResult(stateTransitionHash); + } + + async pathElements(path: string[], keys: string[]): Promise { + const w = await this.sdk.getWasmSdkConnected(); + return w.getPathElements(path, keys); + } + + async pathElementsWithProof(path: string[], keys: string[]): Promise> { + const w = await this.sdk.getWasmSdkConnected(); + return w.getPathElementsWithProofInfo(path, keys); + } } diff --git a/packages/js-evo-sdk/src/tokens/facade.ts b/packages/js-evo-sdk/src/tokens/facade.ts index 50e8c9b90b2..ee2d3289e36 100644 --- a/packages/js-evo-sdk/src/tokens/facade.ts +++ b/packages/js-evo-sdk/src/tokens/facade.ts @@ -15,97 +15,97 @@ export class TokensFacade { } // Queries - async priceByContract(contractId: wasm.IdentifierLike, tokenPosition: number): Promise { + async priceByContract(contractId: wasm.IdentifierLike, tokenPosition: number): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getTokenPriceByContract(contractId, tokenPosition); } - async totalSupply(tokenId: wasm.IdentifierLike): Promise { + async totalSupply(tokenId: wasm.IdentifierLike): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getTokenTotalSupply(tokenId); } - async totalSupplyWithProof(tokenId: wasm.IdentifierLike): Promise { + async totalSupplyWithProof(tokenId: wasm.IdentifierLike): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getTokenTotalSupplyWithProofInfo(tokenId); } - async statuses(tokenIds: wasm.IdentifierLike[]): Promise { + async statuses(tokenIds: wasm.IdentifierLike[]): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getTokenStatuses(tokenIds); } - async statusesWithProof(tokenIds: wasm.IdentifierLike[]): Promise { + async statusesWithProof(tokenIds: wasm.IdentifierLike[]): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getTokenStatusesWithProofInfo(tokenIds); } - async balances(identityIds: wasm.IdentifierLike[], tokenId: wasm.IdentifierLike): Promise { + async balances(identityIds: wasm.IdentifierLike[], tokenId: wasm.IdentifierLike): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentitiesTokenBalances(identityIds, tokenId); } - async balancesWithProof(identityIds: wasm.IdentifierLike[], tokenId: wasm.IdentifierLike): Promise { + async balancesWithProof(identityIds: wasm.IdentifierLike[], tokenId: wasm.IdentifierLike): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentitiesTokenBalancesWithProofInfo(identityIds, tokenId); } - async identityBalances(identityId: wasm.IdentifierLike, tokenIds: wasm.IdentifierLike[]): Promise { + async identityBalances(identityId: wasm.IdentifierLike, tokenIds: wasm.IdentifierLike[]): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityTokenBalances(identityId, tokenIds); } - async identityBalancesWithProof(identityId: wasm.IdentifierLike, tokenIds: wasm.IdentifierLike[]): Promise { + async identityBalancesWithProof(identityId: wasm.IdentifierLike, tokenIds: wasm.IdentifierLike[]): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityTokenBalancesWithProofInfo(identityId, tokenIds); } - async identityTokenInfos(identityId: wasm.IdentifierLike, tokenIds: wasm.IdentifierLike[]): Promise { + async identityTokenInfos(identityId: wasm.IdentifierLike, tokenIds: wasm.IdentifierLike[]): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityTokenInfos(identityId, tokenIds); } - async identitiesTokenInfos(identityIds: wasm.IdentifierLike[], tokenId: wasm.IdentifierLike): Promise { + async identitiesTokenInfos(identityIds: wasm.IdentifierLike[], tokenId: wasm.IdentifierLike): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentitiesTokenInfos(identityIds, tokenId); } - async identityTokenInfosWithProof(identityId: wasm.IdentifierLike, tokenIds: wasm.IdentifierLike[]): Promise { + async identityTokenInfosWithProof(identityId: wasm.IdentifierLike, tokenIds: wasm.IdentifierLike[]): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityTokenInfosWithProofInfo(identityId, tokenIds); } - async identitiesTokenInfosWithProof(identityIds: wasm.IdentifierLike[], tokenId: wasm.IdentifierLike): Promise { + async identitiesTokenInfosWithProof(identityIds: wasm.IdentifierLike[], tokenId: wasm.IdentifierLike): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentitiesTokenInfosWithProofInfo(identityIds, tokenId); } - async directPurchasePrices(tokenIds: wasm.IdentifierLike[]): Promise { + async directPurchasePrices(tokenIds: wasm.IdentifierLike[]): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getTokenDirectPurchasePrices(tokenIds); } - async directPurchasePricesWithProof(tokenIds: wasm.IdentifierLike[]): Promise { + async directPurchasePricesWithProof(tokenIds: wasm.IdentifierLike[]): Promise>> { const w = await this.sdk.getWasmSdkConnected(); return w.getTokenDirectPurchasePricesWithProofInfo(tokenIds); } - async contractInfo(contractId: wasm.IdentifierLike): Promise { + async contractInfo(contractId: wasm.IdentifierLike): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getTokenContractInfo(contractId); } - async contractInfoWithProof(contractId: wasm.IdentifierLike): Promise { + async contractInfoWithProof(contractId: wasm.IdentifierLike): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getTokenContractInfoWithProofInfo(contractId); } - async perpetualDistributionLastClaim(identityId: wasm.IdentifierLike, tokenId: wasm.IdentifierLike): Promise { + async perpetualDistributionLastClaim(identityId: wasm.IdentifierLike, tokenId: wasm.IdentifierLike): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getTokenPerpetualDistributionLastClaim(identityId, tokenId); } - async perpetualDistributionLastClaimWithProof(identityId: wasm.IdentifierLike, tokenId: wasm.IdentifierLike): Promise { + async perpetualDistributionLastClaimWithProof(identityId: wasm.IdentifierLike, tokenId: wasm.IdentifierLike): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getTokenPerpetualDistributionLastClaimWithProofInfo(identityId, tokenId); } diff --git a/packages/js-evo-sdk/src/voting/facade.ts b/packages/js-evo-sdk/src/voting/facade.ts index 63f2aaed89a..4f3ae8c3629 100644 --- a/packages/js-evo-sdk/src/voting/facade.ts +++ b/packages/js-evo-sdk/src/voting/facade.ts @@ -6,33 +6,33 @@ export class VotingFacade { private sdk: EvoSDK; constructor(sdk: EvoSDK) { this.sdk = sdk; } - async contestedResourceVoteState(query: wasm.ContestedResourceVoteStateQuery): Promise { + async contestedResourceVoteState(query: wasm.ContestedResourceVoteStateQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getContestedResourceVoteState(query); } - async contestedResourceVoteStateWithProof(query: wasm.ContestedResourceVoteStateQuery): Promise { + async contestedResourceVoteStateWithProof(query: wasm.ContestedResourceVoteStateQuery): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getContestedResourceVoteStateWithProofInfo(query); } - async contestedResourceIdentityVotes(query: wasm.ContestedResourceIdentityVotesQuery): Promise { + async contestedResourceIdentityVotes(query: wasm.ContestedResourceIdentityVotesQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getContestedResourceIdentityVotes(query); } - async contestedResourceIdentityVotesWithProof(query: wasm.ContestedResourceIdentityVotesQuery): Promise { + async contestedResourceIdentityVotesWithProof(query: wasm.ContestedResourceIdentityVotesQuery): Promise }>> { const w = await this.sdk.getWasmSdkConnected(); return w.getContestedResourceIdentityVotesWithProofInfo(query); } - async votePollsByEndDate(query?: wasm.VotePollsByEndDateQuery): Promise { + async votePollsByEndDate(query?: wasm.VotePollsByEndDateQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getVotePollsByEndDate(query ?? null); } - async votePollsByEndDateWithProof(query?: wasm.VotePollsByEndDateQuery): Promise { + async votePollsByEndDateWithProof(query?: wasm.VotePollsByEndDateQuery): Promise> { const w = await this.sdk.getWasmSdkConnected(); return w.getVotePollsByEndDateWithProofInfo(query ?? null); diff --git a/packages/js-evo-sdk/src/wallet/functions.ts b/packages/js-evo-sdk/src/wallet/functions.ts index bd9aa0c97eb..b4f3c5716da 100644 --- a/packages/js-evo-sdk/src/wallet/functions.ts +++ b/packages/js-evo-sdk/src/wallet/functions.ts @@ -16,52 +16,52 @@ export namespace wallet { return wasm.WasmSdk.mnemonicToSeed(mnemonic, passphrase ?? null); } - export async function deriveKeyFromSeedPhrase(params: wasm.DeriveKeyFromSeedPhraseParams): Promise { + export async function deriveKeyFromSeedPhrase(params: wasm.DeriveKeyFromSeedPhraseParams): Promise { await wasm.ensureInitialized(); return wasm.WasmSdk.deriveKeyFromSeedPhrase(params); } - export async function deriveKeyFromSeedWithPath(params: wasm.DeriveKeyFromSeedWithPathParams): Promise { + export async function deriveKeyFromSeedWithPath(params: wasm.DeriveKeyFromSeedWithPathParams): Promise { await wasm.ensureInitialized(); return wasm.WasmSdk.deriveKeyFromSeedWithPath(params); } - export async function deriveKeyFromSeedWithExtendedPath(params: wasm.DeriveKeyFromSeedWithExtendedPathParams): Promise { + export async function deriveKeyFromSeedWithExtendedPath(params: wasm.DeriveKeyFromSeedWithExtendedPathParams): Promise { await wasm.ensureInitialized(); return wasm.WasmSdk.deriveKeyFromSeedWithExtendedPath(params); } - export async function deriveDashpayContactKey(params: wasm.DeriveDashpayContactKeyParams): Promise { + export async function deriveDashpayContactKey(params: wasm.DeriveDashpayContactKeyParams): Promise { await wasm.ensureInitialized(); return wasm.WasmSdk.deriveDashpayContactKey(params); } - export async function derivationPathBip44Mainnet(account: number, change: number, index: number): Promise { + export async function derivationPathBip44Mainnet(account: number, change: number, index: number): Promise { await wasm.ensureInitialized(); return wasm.WasmSdk.derivationPathBip44Mainnet(account, change, index); } - export async function derivationPathBip44Testnet(account: number, change: number, index: number): Promise { + export async function derivationPathBip44Testnet(account: number, change: number, index: number): Promise { await wasm.ensureInitialized(); return wasm.WasmSdk.derivationPathBip44Testnet(account, change, index); } - export async function derivationPathDip9Mainnet(featureType: number, account: number, index: number): Promise { + export async function derivationPathDip9Mainnet(featureType: number, account: number, index: number): Promise { await wasm.ensureInitialized(); return wasm.WasmSdk.derivationPathDip9Mainnet(featureType, account, index); } - export async function derivationPathDip9Testnet(featureType: number, account: number, index: number): Promise { + export async function derivationPathDip9Testnet(featureType: number, account: number, index: number): Promise { await wasm.ensureInitialized(); return wasm.WasmSdk.derivationPathDip9Testnet(featureType, account, index); } - export async function derivationPathDip13Mainnet(account: number): Promise { + export async function derivationPathDip13Mainnet(account: number): Promise { await wasm.ensureInitialized(); return wasm.WasmSdk.derivationPathDip13Mainnet(account); } - export async function derivationPathDip13Testnet(account: number): Promise { + export async function derivationPathDip13Testnet(account: number): Promise { await wasm.ensureInitialized(); return wasm.WasmSdk.derivationPathDip13Testnet(account); } @@ -76,22 +76,22 @@ export namespace wallet { return wasm.WasmSdk.xprvToXpub(xprv); } - export async function generateKeyPair(network: string): Promise { + export async function generateKeyPair(network: string): Promise { await wasm.ensureInitialized(); return wasm.WasmSdk.generateKeyPair(network); } - export async function generateKeyPairs(network: string, count: number): Promise { + export async function generateKeyPairs(network: string, count: number): Promise { await wasm.ensureInitialized(); return wasm.WasmSdk.generateKeyPairs(network, count); } - export async function keyPairFromWif(privateKeyWif: string): Promise { + export async function keyPairFromWif(privateKeyWif: string): Promise { await wasm.ensureInitialized(); return wasm.WasmSdk.keyPairFromWif(privateKeyWif); } - export async function keyPairFromHex(privateKeyHex: string, network: string): Promise { + export async function keyPairFromHex(privateKeyHex: string, network: string): Promise { await wasm.ensureInitialized(); return wasm.WasmSdk.keyPairFromHex(privateKeyHex, network); } diff --git a/packages/wasm-sdk/src/dpns.rs b/packages/wasm-sdk/src/dpns.rs index 7af536d4af4..63ac7086701 100644 --- a/packages/wasm-sdk/src/dpns.rs +++ b/packages/wasm-sdk/src/dpns.rs @@ -16,23 +16,30 @@ use drive_proof_verifier::types::Documents; use js_sys::Array; use serde::{Deserialize, Serialize}; use simple_signer::SingleKeySigner; -use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::*; use wasm_dpp2::identifier::IdentifierWasm; -#[derive(Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] + +#[wasm_bindgen(js_name = "RegisterDpnsNameResult")] +#[derive(Clone)] pub struct RegisterDpnsNameResult { + #[wasm_bindgen(getter_with_clone, js_name = "preorderDocumentId")] pub preorder_document_id: String, + #[wasm_bindgen(getter_with_clone, js_name = "domainDocumentId")] pub domain_document_id: String, + #[wasm_bindgen(getter_with_clone, js_name = "fullDomainName")] pub full_domain_name: String, } -#[derive(Serialize, Deserialize, Debug)] +#[wasm_bindgen(js_name = "DpnsUsernameInfo")] +#[derive(Clone, Serialize)] #[serde(rename_all = "camelCase")] -struct DpnsUsernameInfo { - username: String, - identity_id: String, - document_id: String, +pub struct DpnsUsernameInfo { + #[wasm_bindgen(getter_with_clone)] + pub username: String, + #[wasm_bindgen(getter_with_clone, js_name = "identityId")] + pub identity_id: String, + #[wasm_bindgen(getter_with_clone, js_name = "documentId")] + pub document_id: String, } const DEFAULT_DPNS_USERNAMES_LIMIT: u32 = 10; @@ -225,7 +232,7 @@ impl WasmSdk { #[wasm_bindgen(js_name = "publicKeyId")] public_key_id: u32, #[wasm_bindgen(js_name = "privateKeyWif")] private_key_wif: &str, #[wasm_bindgen(js_name = "preorderCallback")] preorder_callback: Option, - ) -> Result { + ) -> Result { let identity_id_parsed = identifier_from_js(&identity_id, "identity ID")?; let identity = Identity::fetch(self.as_ref(), identity_id_parsed) @@ -291,16 +298,11 @@ impl WasmSdk { *cb.borrow_mut() = None; }); - let js_result = RegisterDpnsNameResult { + Ok(RegisterDpnsNameResult { preorder_document_id: result.preorder_document.id().to_string(Encoding::Base58), domain_document_id: result.domain_document.id().to_string(Encoding::Base58), full_domain_name: result.full_domain_name, - }; - - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - js_result - .serialize(&serializer) - .map_err(|e| WasmSdkError::serialization(format!("Failed to serialize result: {}", e))) + }) } #[wasm_bindgen(js_name = "dpnsIsNameAvailable")] @@ -312,17 +314,17 @@ impl WasmSdk { } #[wasm_bindgen(js_name = "dpnsResolveName")] - pub async fn dpns_resolve_name(&self, name: &str) -> Result { + pub async fn dpns_resolve_name(&self, name: &str) -> Result, WasmSdkError> { let result = self.as_ref().resolve_dpns_name(name).await?; - match result { - Some(identity_id) => Ok(JsValue::from_str(&identity_id.to_string(Encoding::Base58))), - None => Ok(JsValue::NULL), - } + Ok(result.map(|identity_id| identity_id.to_string(Encoding::Base58))) } #[wasm_bindgen(js_name = "getDpnsUsernameByName")] - pub async fn get_dpns_username_by_name(&self, username: &str) -> Result { + pub async fn get_dpns_username_by_name( + &self, + username: &str, + ) -> Result { const DPNS_CONTRACT_ID: &str = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec"; const DPNS_DOCUMENT_TYPE: &str = "domain"; @@ -362,14 +364,10 @@ impl WasmSdk { let documents = Document::fetch_many(self.as_ref(), query).await?; if let Some((_, Some(document))) = documents.into_iter().next() { - let result = DpnsUsernameInfo { + Ok(DpnsUsernameInfo { username: username.to_string(), identity_id: document.owner_id().to_string(Encoding::Base58), document_id: document.id().to_string(Encoding::Base58), - }; - - serde_wasm_bindgen::to_value(&result).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) }) } else { Err(WasmSdkError::not_found(format!( @@ -379,11 +377,14 @@ impl WasmSdk { } } - #[wasm_bindgen(js_name = "getDpnsUsernameByNameWithProofInfo")] + #[wasm_bindgen( + js_name = "getDpnsUsernameByNameWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_dpns_username_by_name_with_proof_info( &self, username: &str, - ) -> Result { + ) -> Result { const DPNS_CONTRACT_ID: &str = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec"; const DPNS_DOCUMENT_TYPE: &str = "domain"; @@ -437,7 +438,7 @@ impl WasmSdk { let response = ProofMetadataResponseWasm::from_parts(data, metadata.into(), proof.into()); - Ok(JsValue::from(response)) + Ok(response) } else { Err(WasmSdkError::not_found(format!( "Username '{}' not found", @@ -446,16 +447,14 @@ impl WasmSdk { } } - #[wasm_bindgen(js_name = "getDpnsUsernames")] + #[wasm_bindgen(js_name = "getDpnsUsernames", unchecked_return_type = "Array")] pub async fn get_dpns_usernames( &self, query: DpnsUsernamesQueryJs, - ) -> Result { + ) -> Result { let params = parse_dpns_usernames_query(query)?; - let usernames = self - .fetch_dpns_usernames(params.identity_id, params.limit) - .await?; - Ok(usernames.into()) + self.fetch_dpns_usernames(params.identity_id, params.limit) + .await } #[wasm_bindgen(js_name = "getDpnsUsername")] @@ -464,18 +463,22 @@ impl WasmSdk { #[wasm_bindgen(js_name = "identityId")] #[wasm_bindgen(unchecked_param_type = "IdentifierLike")] identity_id: JsValue, - ) -> Result { + ) -> Result, WasmSdkError> { let identity_id_parsed = identifier_from_js(&identity_id, "identity ID")?; let array = self .fetch_dpns_usernames(identity_id_parsed, Some(1)) .await?; - if array.length() > 0 { - Ok(array.get(0)) - } else { - Ok(JsValue::NULL) + if array.length() == 0 { + return Ok(None); } + + array + .get(0) + .as_string() + .map(Some) + .ok_or_else(|| WasmSdkError::generic("DPNS username is not a string")) } #[wasm_bindgen(js_name = "getDpnsUsernamesWithProofInfo")] pub async fn get_dpns_usernames_with_proof_info( diff --git a/packages/wasm-sdk/src/queries/data_contract.rs b/packages/wasm-sdk/src/queries/data_contract.rs index cc144cb31e3..b9b79c1fe85 100644 --- a/packages/wasm-sdk/src/queries/data_contract.rs +++ b/packages/wasm-sdk/src/queries/data_contract.rs @@ -1,5 +1,5 @@ use crate::queries::utils::deserialize_required_query; -use crate::queries::{ProofInfoWasm, ResponseMetadataWasm}; +use crate::queries::ProofMetadataResponseWasm; use crate::sdk::WasmSdk; use crate::WasmSdkError; use dash_sdk::platform::query::LimitQuery; @@ -12,39 +12,6 @@ use wasm_bindgen::JsValue; use wasm_dpp2::identifier::IdentifierWasm; use wasm_dpp2::DataContractWasm; -#[wasm_bindgen(js_name = "DataContractProofResponse")] -#[derive(Clone)] -pub struct DataContractProofResponseWasm { - #[wasm_bindgen(getter_with_clone)] - pub contract: DataContractWasm, - #[wasm_bindgen(getter_with_clone)] - pub metadata: ResponseMetadataWasm, - #[wasm_bindgen(getter_with_clone)] - pub proof: ProofInfoWasm, -} - -#[wasm_bindgen(js_name = "DataContractHistoryProofResponse")] -#[derive(Clone)] -pub struct DataContractHistoryProofResponseWasm { - #[wasm_bindgen(getter_with_clone)] - pub history: Map, - #[wasm_bindgen(getter_with_clone)] - pub metadata: ResponseMetadataWasm, - #[wasm_bindgen(getter_with_clone)] - pub proof: ProofInfoWasm, -} - -#[wasm_bindgen(js_name = "DataContractsProofResponse")] -#[derive(Clone)] -pub struct DataContractsProofResponseWasm { - #[wasm_bindgen(getter_with_clone)] - pub contracts: Map, - #[wasm_bindgen(getter_with_clone)] - pub metadata: ResponseMetadataWasm, - #[wasm_bindgen(getter_with_clone)] - pub proof: ProofInfoWasm, -} - #[wasm_bindgen(typescript_custom_section)] const DATA_CONTRACT_HISTORY_QUERY_TS: &'static str = r#" /** @@ -145,13 +112,16 @@ impl WasmSdk { Ok(data_contract) } - #[wasm_bindgen(js_name = "getDataContractWithProofInfo")] + #[wasm_bindgen( + js_name = "getDataContractWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_data_contract_with_proof_info( &self, #[wasm_bindgen(js_name = "contractId")] #[wasm_bindgen(unchecked_param_type = "Identifier | Uint8Array | string")] contract_id: JsValue, - ) -> Result { + ) -> Result { let id: Identifier = IdentifierWasm::try_from(&contract_id) .map_err(|err| { WasmSdkError::invalid_argument(format!("Invalid data contract ID: {}", err)) @@ -161,17 +131,21 @@ impl WasmSdk { let (contract, metadata, proof) = DataContract::fetch_with_metadata_and_proof(self.as_ref(), id, None).await?; - match contract { - Some(contract) => Ok(DataContractProofResponseWasm { - contract: DataContractWasm::from(contract), - metadata: metadata.into(), - proof: proof.into(), - }), - None => Err(WasmSdkError::not_found("Data contract not found")), - } + contract + .map(|contract| { + ProofMetadataResponseWasm::from_parts( + JsValue::from(DataContractWasm::from(contract)), + metadata.into(), + proof.into(), + ) + }) + .ok_or_else(|| WasmSdkError::not_found("Data contract not found")) } - #[wasm_bindgen(js_name = "getDataContractHistory")] + #[wasm_bindgen( + js_name = "getDataContractHistory", + unchecked_return_type = "Map" + )] pub async fn get_data_contract_history( &self, query: DataContractHistoryQueryJs, @@ -195,7 +169,10 @@ impl WasmSdk { Ok(history_map) } - #[wasm_bindgen(js_name = "getDataContracts")] + #[wasm_bindgen( + js_name = "getDataContracts", + unchecked_return_type = "Map" + )] pub async fn get_data_contracts( &self, #[wasm_bindgen(unchecked_param_type = "Array")] ids: Vec< @@ -232,11 +209,14 @@ impl WasmSdk { // Proof info versions for data contract queries - #[wasm_bindgen(js_name = "getDataContractHistoryWithProofInfo")] + #[wasm_bindgen( + js_name = "getDataContractHistoryWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_data_contract_history_with_proof_info( &self, query: DataContractHistoryQueryJs, - ) -> Result { + ) -> Result { let params = parse_data_contract_history_query(query)?; let limit_query = build_limit_query(¶ms); @@ -255,20 +235,23 @@ impl WasmSdk { } } - Ok(DataContractHistoryProofResponseWasm { - history: history_map, - metadata: metadata.into(), - proof: proof.into(), - }) + Ok(ProofMetadataResponseWasm::from_parts( + JsValue::from(history_map), + metadata.into(), + proof.into(), + )) } - #[wasm_bindgen(js_name = "getDataContractsWithProofInfo")] + #[wasm_bindgen( + js_name = "getDataContractsWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_data_contracts_with_proof_info( &self, #[wasm_bindgen(unchecked_param_type = "Array")] ids: Vec< JsValue, >, - ) -> Result { + ) -> Result { // Parse all contract IDs let identifiers: Result, WasmSdkError> = ids .into_iter() @@ -296,10 +279,10 @@ impl WasmSdk { contracts_map.set(&key, &JsValue::from(value)); } - Ok(DataContractsProofResponseWasm { - contracts: contracts_map, - metadata: metadata.into(), - proof: proof.into(), - }) + Ok(ProofMetadataResponseWasm::from_parts( + JsValue::from(contracts_map), + metadata.into(), + proof.into(), + )) } } diff --git a/packages/wasm-sdk/src/queries/document.rs b/packages/wasm-sdk/src/queries/document.rs index aa61b74505d..e8452b9ea29 100644 --- a/packages/wasm-sdk/src/queries/document.rs +++ b/packages/wasm-sdk/src/queries/document.rs @@ -1,5 +1,5 @@ use crate::queries::utils::deserialize_required_query; -use crate::queries::{ProofInfoWasm, ResponseMetadataWasm}; +use crate::queries::ProofMetadataResponseWasm; use crate::sdk::WasmSdk; use crate::WasmSdkError; use dash_sdk::dpp::data_contract::accessors::v0::DataContractV0Getters; @@ -18,28 +18,6 @@ use wasm_bindgen::JsValue; use wasm_dpp2::data_contract::document::DocumentWasm; use wasm_dpp2::identifier::IdentifierWasm; -#[wasm_bindgen(js_name = "DocumentProofResponse")] -#[derive(Clone)] -pub struct DocumentProofResponseWasm { - #[wasm_bindgen(getter_with_clone)] - pub document: Option, - #[wasm_bindgen(getter_with_clone)] - pub metadata: ResponseMetadataWasm, - #[wasm_bindgen(getter_with_clone)] - pub proof: ProofInfoWasm, -} - -#[wasm_bindgen(js_name = "DocumentsProofResponse")] -#[derive(Clone)] -pub struct DocumentsProofResponseWasm { - #[wasm_bindgen(getter_with_clone)] - pub documents: Map, - #[wasm_bindgen(getter_with_clone)] - pub metadata: ResponseMetadataWasm, - #[wasm_bindgen(getter_with_clone)] - pub proof: ProofInfoWasm, -} - #[wasm_bindgen(typescript_custom_section)] const DOCUMENTS_QUERY_TS: &'static str = r#" /** @@ -340,7 +318,10 @@ fn json_to_platform_value(json_val: &JsonValue) -> Result { #[wasm_bindgen] impl WasmSdk { - #[wasm_bindgen(js_name = "getDocuments")] + #[wasm_bindgen( + js_name = "getDocuments", + unchecked_return_type = "Map" + )] pub async fn get_documents(&self, query: DocumentsQueryJs) -> Result { use dash_sdk::platform::FetchMany; use drive_proof_verifier::types::Documents; @@ -372,11 +353,14 @@ impl WasmSdk { Ok(documents_map) } - #[wasm_bindgen(js_name = "getDocumentsWithProofInfo")] + #[wasm_bindgen( + js_name = "getDocumentsWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_documents_with_proof_info( &self, query: DocumentsQueryJs, - ) -> Result { + ) -> Result { let query = parse_documents_query(self, query).await?; let contract_id = query.data_contract.id(); let document_type_name = query.document_type_name.clone(); @@ -402,11 +386,11 @@ impl WasmSdk { } } - Ok(DocumentsProofResponseWasm { - documents: documents_map, - metadata: metadata.into(), - proof: proof.into(), - }) + Ok(ProofMetadataResponseWasm::from_parts( + JsValue::from(documents_map), + metadata.into(), + proof.into(), + )) } #[wasm_bindgen(js_name = "getDocument")] @@ -456,7 +440,10 @@ impl WasmSdk { Ok(document) } - #[wasm_bindgen(js_name = "getDocumentWithProofInfo")] + #[wasm_bindgen( + js_name = "getDocumentWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_document_with_proof_info( &self, #[wasm_bindgen(js_name = "dataContractId")] @@ -466,7 +453,7 @@ impl WasmSdk { #[wasm_bindgen(js_name = "documentId")] #[wasm_bindgen(unchecked_param_type = "Identifier | Uint8Array | string")] document_id: JsValue, - ) -> Result { + ) -> Result { use dash_sdk::platform::documents::document_query::DocumentQuery; // Parse IDs @@ -499,12 +486,13 @@ impl WasmSdk { let (document_result, metadata, proof) = Document::fetch_with_metadata_and_proof(self.as_ref(), query, None).await?; - Ok(DocumentProofResponseWasm { - document: document_result.map(|doc| { - DocumentWasm::from_batch(doc, contract_id, document_type.to_string(), None) - }), - metadata: metadata.into(), - proof: proof.into(), - }) + let document_js = document_result + .map(|doc| DocumentWasm::from_batch(doc, contract_id, document_type.to_string(), None)); + + Ok(ProofMetadataResponseWasm::from_parts( + JsValue::from(document_js), + metadata.into(), + proof.into(), + )) } } diff --git a/packages/wasm-sdk/src/queries/epoch.rs b/packages/wasm-sdk/src/queries/epoch.rs index 451fae37aff..5ab5ca36b58 100644 --- a/packages/wasm-sdk/src/queries/epoch.rs +++ b/packages/wasm-sdk/src/queries/epoch.rs @@ -1,6 +1,6 @@ use crate::error::WasmSdkError; use crate::queries::utils::deserialize_required_query; -use crate::queries::{ProofInfoWasm, ResponseMetadataWasm}; +use crate::queries::ProofMetadataResponseWasm; use crate::sdk::WasmSdk; use dash_sdk::dpp::block::extended_epoch_info::ExtendedEpochInfo; use dash_sdk::dpp::dashcore::hashes::Hash; @@ -16,39 +16,6 @@ use wasm_bindgen::JsValue; use wasm_dpp2::epoch::{ExtendedEpochInfoWasm, FinalizedEpochInfoWasm}; use wasm_dpp2::identifier::IdentifierWasm; -#[wasm_bindgen(js_name = "EpochsProofResponse")] -#[derive(Clone)] -pub struct EpochsProofResponseWasm { - #[wasm_bindgen(getter_with_clone)] - pub epochs: Map, - #[wasm_bindgen(getter_with_clone)] - pub metadata: ResponseMetadataWasm, - #[wasm_bindgen(getter_with_clone)] - pub proof: ProofInfoWasm, -} - -#[wasm_bindgen(js_name = "EpochProofResponse")] -#[derive(Clone)] -pub struct EpochProofResponseWasm { - #[wasm_bindgen(getter_with_clone)] - pub epoch: ExtendedEpochInfoWasm, - #[wasm_bindgen(getter_with_clone)] - pub metadata: ResponseMetadataWasm, - #[wasm_bindgen(getter_with_clone)] - pub proof: ProofInfoWasm, -} - -#[wasm_bindgen(js_name = "FinalizedEpochsProofResponse")] -#[derive(Clone)] -pub struct FinalizedEpochsProofResponseWasm { - #[wasm_bindgen(getter_with_clone)] - pub epochs: Map, - #[wasm_bindgen(getter_with_clone)] - pub metadata: ResponseMetadataWasm, - #[wasm_bindgen(getter_with_clone)] - pub proof: ProofInfoWasm, -} - #[wasm_bindgen(typescript_custom_section)] const EPOCHS_QUERY_TS: &'static str = r#" /** @@ -262,7 +229,10 @@ fn parse_evonode_range_query( #[wasm_bindgen] impl WasmSdk { - #[wasm_bindgen(js_name = "getEpochsInfo")] + #[wasm_bindgen( + js_name = "getEpochsInfo", + unchecked_return_type = "Map" + )] pub async fn get_epochs_info(&self, query: EpochsQueryJs) -> Result { use dash_sdk::platform::types::epoch::EpochQuery; @@ -295,7 +265,10 @@ impl WasmSdk { Ok(epochs_map) } - #[wasm_bindgen(js_name = "getFinalizedEpochInfos")] + #[wasm_bindgen( + js_name = "getFinalizedEpochInfos", + unchecked_return_type = "Map" + )] pub async fn get_finalized_epoch_infos( &self, query: FinalizedEpochsQueryJs, @@ -349,7 +322,10 @@ impl WasmSdk { Ok(epochs_map) } - #[wasm_bindgen(js_name = "getEvonodesProposedEpochBlocksByIds")] + #[wasm_bindgen( + js_name = "getEvonodesProposedEpochBlocksByIds", + unchecked_return_type = "Map" + )] pub async fn get_evonodes_proposed_epoch_blocks_by_ids( &self, epoch: u16, @@ -384,7 +360,10 @@ impl WasmSdk { Ok(map) } - #[wasm_bindgen(js_name = "getEvonodesProposedEpochBlocksByRange")] + #[wasm_bindgen( + js_name = "getEvonodesProposedEpochBlocksByRange", + unchecked_return_type = "Map" + )] pub async fn get_evonodes_proposed_epoch_blocks_by_range( &self, query: EvonodeProposedBlocksRangeQueryJs, @@ -424,11 +403,14 @@ impl WasmSdk { Ok(ExtendedEpochInfoWasm::from(epoch)) } - #[wasm_bindgen(js_name = "getEpochsInfoWithProofInfo")] + #[wasm_bindgen( + js_name = "getEpochsInfoWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_epochs_info_with_proof_info( &self, query: EpochsQueryJs, - ) -> Result { + ) -> Result { use dash_sdk::platform::types::epoch::EpochQuery; let EpochsQueryParsed { @@ -457,34 +439,40 @@ impl WasmSdk { epochs_map.set(&key.into(), &JsValue::from(value)); } - Ok(EpochsProofResponseWasm { - epochs: epochs_map, - metadata: metadata.into(), - proof: proof.into(), - }) + Ok(ProofMetadataResponseWasm::from_parts( + JsValue::from(epochs_map), + metadata.into(), + proof.into(), + )) } - #[wasm_bindgen(js_name = "getCurrentEpochWithProofInfo")] + #[wasm_bindgen( + js_name = "getCurrentEpochWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_current_epoch_with_proof_info( &self, - ) -> Result { + ) -> Result { let (epoch, metadata, proof) = ExtendedEpochInfo::fetch_current_with_metadata_and_proof(self.as_ref()).await?; - Ok(EpochProofResponseWasm { - epoch: ExtendedEpochInfoWasm::from(epoch), - metadata: metadata.into(), - proof: proof.into(), - }) + Ok(ProofMetadataResponseWasm::from_parts( + JsValue::from(ExtendedEpochInfoWasm::from(epoch)), + metadata.into(), + proof.into(), + )) } // Additional proof info versions for epoch queries - #[wasm_bindgen(js_name = "getFinalizedEpochInfosWithProofInfo")] + #[wasm_bindgen( + js_name = "getFinalizedEpochInfosWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_finalized_epoch_infos_with_proof_info( &self, query: FinalizedEpochsQueryJs, - ) -> Result { + ) -> Result { use dash_sdk::platform::types::finalized_epoch::FinalizedEpochQuery; let FinalizedEpochsQueryParsed { @@ -526,11 +514,11 @@ impl WasmSdk { epochs_map.set(&key.into(), &JsValue::from(value)); } - Ok(FinalizedEpochsProofResponseWasm { - epochs: epochs_map, - metadata: metadata.into(), - proof: proof.into(), - }) + Ok(ProofMetadataResponseWasm::from_parts( + JsValue::from(epochs_map), + metadata.into(), + proof.into(), + )) } #[wasm_bindgen(js_name = "getEvonodesProposedEpochBlocksByIdsWithProofInfo")] diff --git a/packages/wasm-sdk/src/queries/group.rs b/packages/wasm-sdk/src/queries/group.rs index dc69541b7ed..d49163be015 100644 --- a/packages/wasm-sdk/src/queries/group.rs +++ b/packages/wasm-sdk/src/queries/group.rs @@ -614,7 +614,10 @@ impl WasmSdk { Ok(group.map(Into::into)) } - #[wasm_bindgen(js_name = "getGroupMembers")] + #[wasm_bindgen( + js_name = "getGroupMembers", + unchecked_return_type = "Map" + )] pub async fn get_group_members(&self, query: GroupMembersQueryJs) -> Result { let params = parse_group_members_query(query)?; @@ -643,7 +646,10 @@ impl WasmSdk { Ok(Map::new()) } - #[wasm_bindgen(js_name = "getIdentityGroups")] + #[wasm_bindgen( + js_name = "getIdentityGroups", + unchecked_return_type = "Array" + )] pub async fn get_identity_groups( &self, query: IdentityGroupsQueryJs, @@ -699,7 +705,10 @@ impl WasmSdk { Ok(groups_array) } - #[wasm_bindgen(js_name = "getGroupInfos")] + #[wasm_bindgen( + js_name = "getGroupInfos", + unchecked_return_type = "Map" + )] pub async fn get_group_infos(&self, query: GroupInfosQueryJs) -> Result { let params = parse_group_infos_query(query)?; @@ -724,7 +733,10 @@ impl WasmSdk { Ok(infos_map) } - #[wasm_bindgen(js_name = "getGroupActions")] + #[wasm_bindgen( + js_name = "getGroupActions", + unchecked_return_type = "Map" + )] pub async fn get_group_actions(&self, query: GroupActionsQueryJs) -> Result { let params = parse_group_actions_query(query)?; @@ -750,7 +762,10 @@ impl WasmSdk { Ok(actions_map) } - #[wasm_bindgen(js_name = "getGroupActionSigners")] + #[wasm_bindgen( + js_name = "getGroupActionSigners", + unchecked_return_type = "Map" + )] pub async fn get_group_action_signers( &self, query: GroupActionSignersQueryJs, @@ -780,7 +795,10 @@ impl WasmSdk { Ok(signers_map) } - #[wasm_bindgen(js_name = "getGroupsDataContracts")] + #[wasm_bindgen( + js_name = "getGroupsDataContracts", + unchecked_return_type = "Map>" + )] pub async fn get_groups_data_contracts( &self, #[wasm_bindgen(js_name = "dataContractIds")] @@ -823,7 +841,10 @@ impl WasmSdk { // Proof versions for group queries - #[wasm_bindgen(js_name = "getGroupInfoWithProofInfo")] + #[wasm_bindgen( + js_name = "getGroupInfoWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_group_info_with_proof_info( &self, #[wasm_bindgen(js_name = "dataContractId")] @@ -855,7 +876,10 @@ impl WasmSdk { Ok(response) } - #[wasm_bindgen(js_name = "getGroupInfosWithProofInfo")] + #[wasm_bindgen( + js_name = "getGroupInfosWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_group_infos_with_proof_info( &self, query: GroupInfosQueryJs, @@ -887,7 +911,10 @@ impl WasmSdk { // Additional proof info versions for remaining group queries - #[wasm_bindgen(js_name = "getGroupMembersWithProofInfo")] + #[wasm_bindgen( + js_name = "getGroupMembersWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_group_members_with_proof_info( &self, query: GroupMembersQueryJs, @@ -923,7 +950,10 @@ impl WasmSdk { Ok(response) } - #[wasm_bindgen(js_name = "getIdentityGroupsWithProofInfo")] + #[wasm_bindgen( + js_name = "getIdentityGroupsWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_identity_groups_with_proof_info( &self, query: IdentityGroupsQueryJs, @@ -992,7 +1022,10 @@ impl WasmSdk { Ok(response) } - #[wasm_bindgen(js_name = "getGroupActionsWithProofInfo")] + #[wasm_bindgen( + js_name = "getGroupActionsWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_group_actions_with_proof_info( &self, query: GroupActionsQueryJs, @@ -1024,7 +1057,10 @@ impl WasmSdk { Ok(response) } - #[wasm_bindgen(js_name = "getGroupActionSignersWithProofInfo")] + #[wasm_bindgen( + js_name = "getGroupActionSignersWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_group_action_signers_with_proof_info( &self, query: GroupActionSignersQueryJs, @@ -1056,7 +1092,10 @@ impl WasmSdk { Ok(response) } - #[wasm_bindgen(js_name = "getGroupsDataContractsWithProofInfo")] + #[wasm_bindgen( + js_name = "getGroupsDataContractsWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>>" + )] pub async fn get_groups_data_contracts_with_proof_info( &self, #[wasm_bindgen(js_name = "dataContractIds")] diff --git a/packages/wasm-sdk/src/queries/identity.rs b/packages/wasm-sdk/src/queries/identity.rs index 31d5b014f41..8dc71227d9d 100644 --- a/packages/wasm-sdk/src/queries/identity.rs +++ b/packages/wasm-sdk/src/queries/identity.rs @@ -1,6 +1,6 @@ use crate::error::WasmSdkError; use crate::queries::utils::deserialize_required_query; -use crate::queries::{ProofInfoWasm, ProofMetadataResponseWasm, ResponseMetadataWasm}; +use crate::queries::ProofMetadataResponseWasm; use crate::sdk::WasmSdk; use dash_sdk::dpp::identity::identity_public_key::accessors::v0::IdentityPublicKeyGettersV0; use dash_sdk::dpp::identity::identity_public_key::IdentityPublicKey; @@ -194,28 +194,6 @@ impl IdentityNonceWasm { BigInt::from(self.nonce) } } - -#[wasm_bindgen(js_name = "IdentityProofResponse")] -#[derive(Clone)] -pub struct IdentityProofResponseWasm { - #[wasm_bindgen(getter_with_clone)] - pub identity: Option, - #[wasm_bindgen(getter_with_clone)] - pub metadata: ResponseMetadataWasm, - #[wasm_bindgen(getter_with_clone)] - pub proof: ProofInfoWasm, -} - -#[wasm_bindgen(js_name = "IdentityKeysProofResponse")] -#[derive(Clone)] -pub struct IdentityKeysProofResponseWasm { - #[wasm_bindgen(getter_with_clone)] - pub keys: Array, - #[wasm_bindgen(getter_with_clone)] - pub metadata: ResponseMetadataWasm, - #[wasm_bindgen(getter_with_clone)] - pub proof: ProofInfoWasm, -} #[wasm_bindgen(typescript_custom_section)] const IDENTITIES_CONTRACT_KEYS_QUERY_TS: &'static str = r#" /** @@ -239,11 +217,13 @@ export interface IdentitiesContractKeysQuery { purposes?: number[]; } "#; + #[wasm_bindgen] extern "C" { #[wasm_bindgen(typescript_type = "IdentitiesContractKeysQuery")] pub type IdentitiesContractKeysQueryJs; } + #[derive(Deserialize)] #[serde(rename_all = "camelCase")] struct IdentitiesContractKeysQueryInput { @@ -254,11 +234,13 @@ struct IdentitiesContractKeysQueryInput { #[serde(default)] purposes: Option>, } + struct IdentitiesContractKeysQueryParsed { identity_ids: Vec, contract_id: Identifier, purposes: Option>, } + fn parse_identities_contract_keys_query( query: IdentitiesContractKeysQueryJs, ) -> Result { @@ -277,6 +259,7 @@ fn parse_identities_contract_keys_query( purposes: input.purposes, }) } + #[wasm_bindgen(typescript_custom_section)] const IDENTITY_KEYS_QUERY_TS: &'static str = r#" /** @@ -445,13 +428,16 @@ impl WasmSdk { Ok(identity.map(IdentityWasm::from)) } - #[wasm_bindgen(js_name = "getIdentityWithProofInfo")] + #[wasm_bindgen( + js_name = "getIdentityWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_identity_with_proof_info( &self, #[wasm_bindgen(js_name = "identityId")] #[wasm_bindgen(unchecked_param_type = "Identifier | Uint8Array | string")] identity_id: JsValue, - ) -> Result { + ) -> Result { let id: Identifier = IdentifierWasm::try_from(&identity_id) .map_err(|err| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", err)))? .into(); @@ -459,14 +445,15 @@ impl WasmSdk { let (identity, metadata, proof) = Identity::fetch_with_metadata_and_proof(self.as_ref(), id, None).await?; - match identity { - Some(identity) => Ok(IdentityProofResponseWasm { - identity: Some(IdentityWasm::from(identity)), - metadata: metadata.into(), - proof: proof.into(), - }), - None => Err(WasmSdkError::not_found("Identity not found")), - } + identity + .map(|identity| { + ProofMetadataResponseWasm::from_parts( + JsValue::from(IdentityWasm::from(identity)), + metadata.into(), + proof.into(), + ) + }) + .ok_or_else(|| WasmSdkError::not_found("Identity not found")) } #[wasm_bindgen(js_name = "getIdentityUnproved")] @@ -521,7 +508,10 @@ impl WasmSdk { } } - #[wasm_bindgen(js_name = "getIdentityKeys")] + #[wasm_bindgen( + js_name = "getIdentityKeys", + unchecked_return_type = "Array" + )] pub async fn get_identity_keys( &self, query: IdentityKeysQueryJs, @@ -679,7 +669,10 @@ impl WasmSdk { Ok(IdentityNonceWasm::new(nonce)) } - #[wasm_bindgen(js_name = "getIdentityNonceWithProofInfo")] + #[wasm_bindgen( + js_name = "getIdentityNonceWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_identity_nonce_with_proof_info( &self, #[wasm_bindgen(js_name = "identityId")] @@ -738,7 +731,10 @@ impl WasmSdk { Ok(IdentityNonceWasm::new(nonce)) } - #[wasm_bindgen(js_name = "getIdentityContractNonceWithProofInfo")] + #[wasm_bindgen( + js_name = "getIdentityContractNonceWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_identity_contract_nonce_with_proof_info( &self, #[wasm_bindgen(js_name = "identityId")] @@ -799,7 +795,10 @@ impl WasmSdk { .ok_or_else(|| WasmSdkError::not_found("Identity balance not found")) } - #[wasm_bindgen(js_name = "getIdentitiesBalances")] + #[wasm_bindgen( + js_name = "getIdentitiesBalances", + unchecked_return_type = "Array" + )] pub async fn get_identities_balances( &self, #[wasm_bindgen(js_name = "identityIds")] @@ -891,7 +890,10 @@ impl WasmSdk { .map(Into::into) } - #[wasm_bindgen(js_name = "getIdentitiesContractKeys")] + #[wasm_bindgen( + js_name = "getIdentitiesContractKeys", + unchecked_return_type = "Array" + )] pub async fn get_identities_contract_keys( &self, query: IdentitiesContractKeysQueryJs, @@ -958,7 +960,10 @@ impl WasmSdk { Ok(array) } - #[wasm_bindgen(js_name = "getIdentityByNonUniquePublicKeyHash")] + #[wasm_bindgen( + js_name = "getIdentityByNonUniquePublicKeyHash", + unchecked_return_type = "Array" + )] pub async fn get_identity_by_non_unique_public_key_hash( &self, #[wasm_bindgen(js_name = "publicKeyHash")] @@ -1017,7 +1022,10 @@ impl WasmSdk { Ok(js_array) } - #[wasm_bindgen(js_name = "getIdentityTokenBalances")] + #[wasm_bindgen( + js_name = "getIdentityTokenBalances", + unchecked_return_type = "Map" + )] pub async fn get_identity_token_balances( &self, #[wasm_bindgen(js_name = "identityId")] @@ -1069,11 +1077,14 @@ impl WasmSdk { // Proof info versions for identity queries - #[wasm_bindgen(js_name = "getIdentityKeysWithProofInfo")] + #[wasm_bindgen( + js_name = "getIdentityKeysWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_identity_keys_with_proof_info( &self, query: IdentityKeysQueryJs, - ) -> Result { + ) -> Result { let IdentityKeysQueryParsed { identity_id, request, @@ -1122,14 +1133,17 @@ impl WasmSdk { } } - Ok(IdentityKeysProofResponseWasm { - keys: keys_array, - metadata: metadata.into(), - proof: proof.into(), - }) + Ok(ProofMetadataResponseWasm::from_parts( + JsValue::from(keys_array), + metadata.into(), + proof.into(), + )) } - #[wasm_bindgen(js_name = "getIdentityBalanceWithProofInfo")] + #[wasm_bindgen( + js_name = "getIdentityBalanceWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_identity_balance_with_proof_info( &self, #[wasm_bindgen(js_name = "identityId")] @@ -1158,7 +1172,10 @@ impl WasmSdk { .ok_or_else(|| WasmSdkError::not_found("Identity balance not found")) } - #[wasm_bindgen(js_name = "getIdentitiesBalancesWithProofInfo")] + #[wasm_bindgen( + js_name = "getIdentitiesBalancesWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_identities_balances_with_proof_info( &self, #[wasm_bindgen(js_name = "identityIds")] @@ -1207,7 +1224,10 @@ impl WasmSdk { )) } - #[wasm_bindgen(js_name = "getIdentityBalanceAndRevisionWithProofInfo")] + #[wasm_bindgen( + js_name = "getIdentityBalanceAndRevisionWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_identity_balance_and_revision_with_proof_info( &self, #[wasm_bindgen(js_name = "identityId")] @@ -1236,13 +1256,16 @@ impl WasmSdk { .ok_or_else(|| WasmSdkError::not_found("Identity balance and revision not found")) } - #[wasm_bindgen(js_name = "getIdentityByPublicKeyHashWithProofInfo")] + #[wasm_bindgen( + js_name = "getIdentityByPublicKeyHashWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_identity_by_public_key_hash_with_proof_info( &self, #[wasm_bindgen(js_name = "publicKeyHash")] #[wasm_bindgen(unchecked_param_type = "string | Uint8Array")] public_key_hash: JsValue, - ) -> Result { + ) -> Result { use dash_sdk::platform::types::identity::PublicKeyHash; let hash_bytes: Vec = if let Some(hex_str) = public_key_hash.as_string() { hex::decode(&hex_str).map_err(|e| { @@ -1265,19 +1288,21 @@ impl WasmSdk { Identity::fetch_with_metadata_and_proof(self.as_ref(), PublicKeyHash(hash_array), None) .await?; - match result { - Some(identity) => Ok(IdentityProofResponseWasm { - identity: Some(IdentityWasm::from(identity)), - metadata: metadata.into(), - proof: proof.into(), - }), - None => Err(WasmSdkError::not_found( - "Identity not found for public key hash", - )), - } + result + .map(|identity| { + ProofMetadataResponseWasm::from_parts( + JsValue::from(IdentityWasm::from(identity)), + metadata.into(), + proof.into(), + ) + }) + .ok_or_else(|| WasmSdkError::not_found("Identity not found for public key hash")) } - #[wasm_bindgen(js_name = "getIdentityByNonUniquePublicKeyHashWithProofInfo")] + #[wasm_bindgen( + js_name = "getIdentityByNonUniquePublicKeyHashWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_identity_by_non_unique_public_key_hash_with_proof_info( &self, #[wasm_bindgen(js_name = "publicKeyHash")] @@ -1344,7 +1369,10 @@ impl WasmSdk { } // TODO: This method returns proof only for first identity - #[wasm_bindgen(js_name = "getIdentitiesContractKeysWithProofInfo")] + #[wasm_bindgen( + js_name = "getIdentitiesContractKeysWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_identities_contract_keys_with_proof_info( &self, query: IdentitiesContractKeysQueryJs, @@ -1428,7 +1456,10 @@ impl WasmSdk { )) } - #[wasm_bindgen(js_name = "getIdentityTokenBalancesWithProofInfo")] + #[wasm_bindgen( + js_name = "getIdentityTokenBalancesWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_identity_token_balances_with_proof_info( &self, #[wasm_bindgen(js_name = "identityId")] diff --git a/packages/wasm-sdk/src/queries/mod.rs b/packages/wasm-sdk/src/queries/mod.rs index 38aa9a77ca2..e9d6536be84 100644 --- a/packages/wasm-sdk/src/queries/mod.rs +++ b/packages/wasm-sdk/src/queries/mod.rs @@ -212,6 +212,11 @@ pub struct ProofMetadataResponseWasm { proof: ProofInfoWasm, } +#[wasm_bindgen(typescript_custom_section)] +const PROOF_METADATA_TYPED_TS: &'static str = r#" +export type ProofMetadataResponseTyped = ProofMetadataResponse & { data: T }; +"#; + #[wasm_bindgen(js_class = ProofMetadataResponse)] impl ProofMetadataResponseWasm { #[wasm_bindgen(constructor)] diff --git a/packages/wasm-sdk/src/queries/protocol.rs b/packages/wasm-sdk/src/queries/protocol.rs index 402ac87abae..7fc9d00a8a2 100644 --- a/packages/wasm-sdk/src/queries/protocol.rs +++ b/packages/wasm-sdk/src/queries/protocol.rs @@ -133,7 +133,10 @@ impl WasmSdk { )) } - #[wasm_bindgen(js_name = "getProtocolVersionUpgradeVoteStatus")] + #[wasm_bindgen( + js_name = "getProtocolVersionUpgradeVoteStatus", + unchecked_return_type = "Map" + )] pub async fn get_protocol_version_upgrade_vote_status( &self, #[wasm_bindgen(js_name = "startProTxHash")] @@ -192,7 +195,10 @@ impl WasmSdk { // Proof versions for protocol queries - #[wasm_bindgen(js_name = "getProtocolVersionUpgradeStateWithProofInfo")] + #[wasm_bindgen( + js_name = "getProtocolVersionUpgradeStateWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_protocol_version_upgrade_state_with_proof_info( &self, ) -> Result { diff --git a/packages/wasm-sdk/src/queries/system.rs b/packages/wasm-sdk/src/queries/system.rs index 075324f8905..e76cece65ea 100644 --- a/packages/wasm-sdk/src/queries/system.rs +++ b/packages/wasm-sdk/src/queries/system.rs @@ -847,7 +847,10 @@ impl WasmSdk { )) } - #[wasm_bindgen(js_name = "getPathElements")] + #[wasm_bindgen( + js_name = "getPathElements", + unchecked_return_type = "Array" + )] pub async fn get_path_elements( &self, path: Vec, @@ -905,7 +908,10 @@ impl WasmSdk { // Proof versions for system queries - #[wasm_bindgen(js_name = "getTotalCreditsInPlatformWithProofInfo")] + #[wasm_bindgen( + js_name = "getTotalCreditsInPlatformWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_total_credits_in_platform_with_proof_info( &self, ) -> Result { @@ -927,7 +933,10 @@ impl WasmSdk { )) } - #[wasm_bindgen(js_name = "getPrefundedSpecializedBalanceWithProofInfo")] + #[wasm_bindgen( + js_name = "getPrefundedSpecializedBalanceWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_prefunded_specialized_balance_with_proof_info( &self, #[wasm_bindgen(js_name = "identityId")] @@ -962,7 +971,10 @@ impl WasmSdk { )) } - #[wasm_bindgen(js_name = "getPathElementsWithProofInfo")] + #[wasm_bindgen( + js_name = "getPathElementsWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_path_elements_with_proof_info( &self, path: Vec, diff --git a/packages/wasm-sdk/src/queries/token.rs b/packages/wasm-sdk/src/queries/token.rs index 78901e4703b..3c06aac02a2 100644 --- a/packages/wasm-sdk/src/queries/token.rs +++ b/packages/wasm-sdk/src/queries/token.rs @@ -228,7 +228,10 @@ impl WasmSdk { } } - #[wasm_bindgen(js_name = "getIdentitiesTokenBalances")] + #[wasm_bindgen( + js_name = "getIdentitiesTokenBalances", + unchecked_return_type = "Map" + )] pub async fn get_identities_token_balances( &self, #[wasm_bindgen(js_name = "identityIds")] @@ -269,7 +272,10 @@ impl WasmSdk { Ok(balances_map) } - #[wasm_bindgen(js_name = "getIdentityTokenInfos")] + #[wasm_bindgen( + js_name = "getIdentityTokenInfos", + unchecked_return_type = "Map" + )] pub async fn get_identity_token_infos( &self, #[wasm_bindgen(js_name = "identityId")] @@ -311,7 +317,10 @@ impl WasmSdk { Ok(infos_map) } - #[wasm_bindgen(js_name = "getIdentitiesTokenInfos")] + #[wasm_bindgen( + js_name = "getIdentitiesTokenInfos", + unchecked_return_type = "Map" + )] pub async fn get_identities_token_infos( &self, #[wasm_bindgen(js_name = "identityIds")] @@ -353,7 +362,10 @@ impl WasmSdk { Ok(infos_map) } - #[wasm_bindgen(js_name = "getTokenStatuses")] + #[wasm_bindgen( + js_name = "getTokenStatuses", + unchecked_return_type = "Map" + )] pub async fn get_token_statuses( &self, #[wasm_bindgen(js_name = "tokenIds")] @@ -381,7 +393,10 @@ impl WasmSdk { Ok(statuses_map) } - #[wasm_bindgen(js_name = "getTokenDirectPurchasePrices")] + #[wasm_bindgen( + js_name = "getTokenDirectPurchasePrices", + unchecked_return_type = "Map" + )] pub async fn get_token_direct_purchase_prices( &self, #[wasm_bindgen(js_name = "tokenIds")] @@ -654,7 +669,10 @@ impl WasmSdk { // Proof versions for token queries - #[wasm_bindgen(js_name = "getIdentitiesTokenBalancesWithProofInfo")] + #[wasm_bindgen( + js_name = "getIdentitiesTokenBalancesWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_identities_token_balances_with_proof_info( &self, #[wasm_bindgen(js_name = "identityIds")] @@ -701,7 +719,10 @@ impl WasmSdk { )) } - #[wasm_bindgen(js_name = "getTokenStatusesWithProofInfo")] + #[wasm_bindgen( + js_name = "getTokenStatusesWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_token_statuses_with_proof_info( &self, #[wasm_bindgen(js_name = "tokenIds")] @@ -732,7 +753,10 @@ impl WasmSdk { )) } - #[wasm_bindgen(js_name = "getTokenTotalSupplyWithProofInfo")] + #[wasm_bindgen( + js_name = "getTokenTotalSupplyWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_token_total_supply_with_proof_info( &self, #[wasm_bindgen(js_name = "tokenId")] @@ -765,7 +789,10 @@ impl WasmSdk { // Additional proof info versions for remaining token queries - #[wasm_bindgen(js_name = "getIdentityTokenInfosWithProofInfo")] + #[wasm_bindgen( + js_name = "getIdentityTokenInfosWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_identity_token_infos_with_proof_info( &self, #[wasm_bindgen(js_name = "identityId")] @@ -810,7 +837,10 @@ impl WasmSdk { )) } - #[wasm_bindgen(js_name = "getIdentitiesTokenInfosWithProofInfo")] + #[wasm_bindgen( + js_name = "getIdentitiesTokenInfosWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_identities_token_infos_with_proof_info( &self, #[wasm_bindgen(js_name = "identityIds")] @@ -855,7 +885,10 @@ impl WasmSdk { )) } - #[wasm_bindgen(js_name = "getTokenDirectPurchasePricesWithProofInfo")] + #[wasm_bindgen( + js_name = "getTokenDirectPurchasePricesWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_token_direct_purchase_prices_with_proof_info( &self, #[wasm_bindgen(js_name = "tokenIds")] @@ -912,7 +945,10 @@ impl WasmSdk { )) } - #[wasm_bindgen(js_name = "getTokenContractInfoWithProofInfo")] + #[wasm_bindgen( + js_name = "getTokenContractInfoWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_token_contract_info_with_proof_info( &self, #[wasm_bindgen(js_name = "dataContractId")] @@ -939,7 +975,10 @@ impl WasmSdk { )) } - #[wasm_bindgen(js_name = "getTokenPerpetualDistributionLastClaimWithProofInfo")] + #[wasm_bindgen( + js_name = "getTokenPerpetualDistributionLastClaimWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_token_perpetual_distribution_last_claim_with_proof_info( &self, #[wasm_bindgen(js_name = "identityId")] diff --git a/packages/wasm-sdk/src/queries/voting/polls.rs b/packages/wasm-sdk/src/queries/voting/polls.rs index b3485447f82..929c7e0657f 100644 --- a/packages/wasm-sdk/src/queries/voting/polls.rs +++ b/packages/wasm-sdk/src/queries/voting/polls.rs @@ -213,7 +213,10 @@ fn vote_polls_grouped_to_entries(grouped: VotePollsGroupedByTimestamp) -> Array #[wasm_bindgen] impl WasmSdk { - #[wasm_bindgen(js_name = "getVotePollsByEndDate")] + #[wasm_bindgen( + js_name = "getVotePollsByEndDate", + unchecked_return_type = "Array" + )] pub async fn get_vote_polls_by_end_date( &self, query: Option, @@ -223,7 +226,10 @@ impl WasmSdk { Ok(vote_polls_grouped_to_entries(polls)) } - #[wasm_bindgen(js_name = "getVotePollsByEndDateWithProofInfo")] + #[wasm_bindgen( + js_name = "getVotePollsByEndDateWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_vote_polls_by_end_date_with_proof_info( &self, query: Option, diff --git a/packages/wasm-sdk/src/queries/voting/resources.rs b/packages/wasm-sdk/src/queries/voting/resources.rs index 85bef7a2dfa..7c3316987fb 100644 --- a/packages/wasm-sdk/src/queries/voting/resources.rs +++ b/packages/wasm-sdk/src/queries/voting/resources.rs @@ -204,7 +204,10 @@ fn parse_vote_polls_by_document_type_query( #[wasm_bindgen] impl WasmSdk { - #[wasm_bindgen(js_name = "getContestedResources")] + #[wasm_bindgen( + js_name = "getContestedResources", + unchecked_return_type = "Array" + )] pub async fn get_contested_resources( &self, query: VotePollsByDocumentTypeQueryJs, @@ -220,7 +223,10 @@ impl WasmSdk { } // Proof info versions for voting queries - #[wasm_bindgen(js_name = "getContestedResourcesWithProofInfo")] + #[wasm_bindgen( + js_name = "getContestedResourcesWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_contested_resources_with_proof_info( &self, query: VotePollsByDocumentTypeQueryJs, diff --git a/packages/wasm-sdk/src/queries/voting/state.rs b/packages/wasm-sdk/src/queries/voting/state.rs index 9f26d517645..bff33ea675c 100644 --- a/packages/wasm-sdk/src/queries/voting/state.rs +++ b/packages/wasm-sdk/src/queries/voting/state.rs @@ -339,7 +339,10 @@ impl WasmSdk { Ok(convert_contenders(contenders)) } - #[wasm_bindgen(js_name = "getContestedResourceVoteStateWithProofInfo")] + #[wasm_bindgen( + js_name = "getContestedResourceVoteStateWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped" + )] pub async fn get_contested_resource_vote_state_with_proof_info( &self, query: ContestedResourceVoteStateQueryJs, diff --git a/packages/wasm-sdk/src/queries/voting/voters.rs b/packages/wasm-sdk/src/queries/voting/voters.rs index f250cb9de0d..616356ecb97 100644 --- a/packages/wasm-sdk/src/queries/voting/voters.rs +++ b/packages/wasm-sdk/src/queries/voting/voters.rs @@ -161,7 +161,10 @@ fn parse_contested_resource_voters_query( #[wasm_bindgen] impl WasmSdk { - #[wasm_bindgen(js_name = "getContestedResourceVotersForIdentity")] + #[wasm_bindgen( + js_name = "getContestedResourceVotersForIdentity", + unchecked_return_type = "Array" + )] pub async fn get_contested_resource_voters_for_identity( &self, query: ContestedResourceVotersQueryJs, @@ -181,7 +184,10 @@ impl WasmSdk { Ok(array) } - #[wasm_bindgen(js_name = "getContestedResourceVotersForIdentityWithProofInfo")] + #[wasm_bindgen( + js_name = "getContestedResourceVotersForIdentityWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped>" + )] pub async fn get_contested_resource_voters_for_identity_with_proof_info( &self, query: ContestedResourceVotersQueryJs, diff --git a/packages/wasm-sdk/src/queries/voting/votes.rs b/packages/wasm-sdk/src/queries/voting/votes.rs index 9abe448064e..b73a30b1881 100644 --- a/packages/wasm-sdk/src/queries/voting/votes.rs +++ b/packages/wasm-sdk/src/queries/voting/votes.rs @@ -192,7 +192,10 @@ fn resource_votes_to_json( #[wasm_bindgen] impl WasmSdk { - #[wasm_bindgen(js_name = "getContestedResourceIdentityVotes")] + #[wasm_bindgen( + js_name = "getContestedResourceIdentityVotes", + unchecked_return_type = "Array" + )] pub async fn get_contested_resource_identity_votes( &self, query: ContestedResourceIdentityVotesQueryJs, @@ -216,7 +219,10 @@ impl WasmSdk { Ok(array) } - #[wasm_bindgen(js_name = "getContestedResourceIdentityVotesWithProofInfo")] + #[wasm_bindgen( + js_name = "getContestedResourceIdentityVotesWithProofInfo", + unchecked_return_type = "ProofMetadataResponseTyped<{ votes: Array }>" + )] pub async fn get_contested_resource_identity_votes_with_proof_info( &self, query: ContestedResourceIdentityVotesQueryJs, diff --git a/packages/wasm-sdk/src/wallet/key_derivation.rs b/packages/wasm-sdk/src/wallet/key_derivation.rs index 0e9f0a5f9c0..c91399f4d6b 100644 --- a/packages/wasm-sdk/src/wallet/key_derivation.rs +++ b/packages/wasm-sdk/src/wallet/key_derivation.rs @@ -197,6 +197,69 @@ impl DerivationPath { } } +#[wasm_bindgen(js_name = "DerivationPathInfo", getter_with_clone)] +#[derive(Clone)] +pub struct DerivationPathWasm { + pub path: String, + pub purpose: u32, + #[wasm_bindgen(js_name = "coinType")] + pub coin_type: u32, + pub account: u32, + pub change: u32, + pub index: u32, +} + +impl From for DerivationPathWasm { + fn from(path: DerivationPath) -> Self { + Self { + path: path.to_string(), + purpose: path.purpose, + coin_type: path.coin_type, + account: path.account, + change: path.change, + index: path.index, + } + } +} + +#[wasm_bindgen(getter_with_clone, js_name = "Dip13DerivationPathInfo")] +#[derive(Clone)] +pub struct Dip13DerivationPathWasm { + pub path: String, + pub purpose: u32, + #[wasm_bindgen(js_name = "coinType")] + pub coin_type: u32, + pub account: u32, + pub description: String, +} + +#[wasm_bindgen(getter_with_clone, js_name = "SeedPhraseKeyInfo")] +#[derive(Clone)] +pub struct SeedPhraseKeyInfoWasm { + #[wasm_bindgen(js_name = "privateKeyWif")] + pub private_key_wif: String, + #[wasm_bindgen(js_name = "privateKeyHex")] + pub private_key_hex: String, + #[wasm_bindgen(js_name = "publicKey")] + pub public_key: String, + pub address: String, + pub network: String, +} + +#[wasm_bindgen(getter_with_clone, js_name = "PathDerivedKeyInfo")] +#[derive(Clone)] +pub struct PathDerivedKeyInfoWasm { + pub path: String, + #[wasm_bindgen(js_name = "privateKeyWif")] + pub private_key_wif: String, + #[wasm_bindgen(js_name = "privateKeyHex")] + pub private_key_hex: String, + #[wasm_bindgen(js_name = "publicKey")] + pub public_key: String, + pub address: String, + pub network: String, +} + /// HD Key information #[derive(Debug, Clone, Serialize, Deserialize)] pub struct HDKeyInfo { @@ -322,7 +385,7 @@ impl WasmSdk { #[wasm_bindgen(js_name = "deriveKeyFromSeedPhrase")] pub fn derive_key_from_seed_phrase( params: DeriveKeyFromSeedPhraseParamsJs, - ) -> Result { + ) -> Result { let DeriveFromSeedPhraseInput { mnemonic, passphrase, @@ -332,8 +395,6 @@ impl WasmSdk { "Options object is required", "deriveKeyFromSeedPhrase options", )?; - use crate::wallet::key_generation::KeyPair; - // Get seed from mnemonic let seed = Self::mnemonic_to_seed(&mnemonic, passphrase)?; @@ -369,16 +430,12 @@ impl WasmSdk { // Get address let address = dashcore::Address::p2pkh(&public_key, net); - let key_pair = KeyPair { + Ok(SeedPhraseKeyInfoWasm { private_key_wif: private_key.to_wif(), private_key_hex: hex::encode(key_bytes), public_key: hex::encode(public_key_bytes), address: address.to_string(), network, - }; - - serde_wasm_bindgen::to_value(&key_pair).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize key pair: {}", e)) }) } @@ -386,7 +443,7 @@ impl WasmSdk { #[wasm_bindgen(js_name = "deriveKeyFromSeedWithPath")] pub fn derive_key_from_seed_with_path( params: DeriveKeyFromSeedWithPathParamsJs, - ) -> Result { + ) -> Result { use dash_sdk::dpp::key_wallet::{DerivationPath, ExtendedPrivKey}; // Types decoded in parse step are defined at module scope @@ -435,62 +492,34 @@ impl WasmSdk { // Get address let address = dashcore::Address::p2pkh(&public_key, net); - // Create a JavaScript object directly - let obj = js_sys::Object::new(); - - js_sys::Reflect::set(&obj, &JsValue::from_str("path"), &JsValue::from_str(&path)) - .map_err(|_| WasmSdkError::generic("Failed to set path property"))?; - - js_sys::Reflect::set( - &obj, - &JsValue::from_str("private_key_wif"), - &JsValue::from_str(&private_key.to_wif()), - ) - .map_err(|_| WasmSdkError::generic("Failed to set private_key_wif property"))?; - - js_sys::Reflect::set( - &obj, - &JsValue::from_str("private_key_hex"), - &JsValue::from_str(&hex::encode(private_key.inner.secret_bytes())), - ) - .map_err(|_| WasmSdkError::generic("Failed to set private_key_hex property"))?; - - js_sys::Reflect::set( - &obj, - &JsValue::from_str("public_key"), - &JsValue::from_str(&hex::encode(public_key.to_bytes())), - ) - .map_err(|_| WasmSdkError::generic("Failed to set public_key property"))?; - - js_sys::Reflect::set( - &obj, - &JsValue::from_str("address"), - &JsValue::from_str(&address.to_string()), - ) - .map_err(|_| WasmSdkError::generic("Failed to set address property"))?; - - js_sys::Reflect::set( - &obj, - &JsValue::from_str("network"), - &JsValue::from_str(&network), - ) - .map_err(|_| WasmSdkError::generic("Failed to set network property"))?; - - Ok(obj.into()) + Ok(PathDerivedKeyInfoWasm { + path, + private_key_wif: private_key.to_wif(), + private_key_hex: hex::encode(private_key.inner.secret_bytes()), + public_key: hex::encode(public_key.to_bytes()), + address: address.to_string(), + network, + }) } /// Create a BIP44 mainnet derivation path #[wasm_bindgen(js_name = "derivationPathBip44Mainnet")] - pub fn derivation_path_bip44_mainnet(account: u32, change: u32, index: u32) -> JsValue { - let path = DerivationPath::new_bip44_mainnet(account, change, index); - serde_wasm_bindgen::to_value(&path).unwrap_or(JsValue::NULL) + pub fn derivation_path_bip44_mainnet( + account: u32, + change: u32, + index: u32, + ) -> DerivationPathWasm { + DerivationPathWasm::from(DerivationPath::new_bip44_mainnet(account, change, index)) } /// Create a BIP44 testnet derivation path #[wasm_bindgen(js_name = "derivationPathBip44Testnet")] - pub fn derivation_path_bip44_testnet(account: u32, change: u32, index: u32) -> JsValue { - let path = DerivationPath::new_bip44_testnet(account, change, index); - serde_wasm_bindgen::to_value(&path).unwrap_or(JsValue::NULL) + pub fn derivation_path_bip44_testnet( + account: u32, + change: u32, + index: u32, + ) -> DerivationPathWasm { + DerivationPathWasm::from(DerivationPath::new_bip44_testnet(account, change, index)) } /// Create a DIP9 mainnet derivation path @@ -499,9 +528,12 @@ impl WasmSdk { #[wasm_bindgen(js_name = "featureType")] feature_type: u32, account: u32, index: u32, - ) -> JsValue { - let path = DerivationPath::new_dip9_mainnet(feature_type, account, index); - serde_wasm_bindgen::to_value(&path).unwrap_or(JsValue::NULL) + ) -> DerivationPathWasm { + DerivationPathWasm::from(DerivationPath::new_dip9_mainnet( + feature_type, + account, + index, + )) } /// Create a DIP9 testnet derivation path @@ -510,101 +542,42 @@ impl WasmSdk { #[wasm_bindgen(js_name = "featureType")] feature_type: u32, account: u32, index: u32, - ) -> JsValue { - let path = DerivationPath::new_dip9_testnet(feature_type, account, index); - serde_wasm_bindgen::to_value(&path).unwrap_or(JsValue::NULL) + ) -> DerivationPathWasm { + DerivationPathWasm::from(DerivationPath::new_dip9_testnet( + feature_type, + account, + index, + )) } /// Create a DIP13 mainnet derivation path (for HD masternode keys) #[wasm_bindgen(js_name = "derivationPathDip13Mainnet")] - pub fn derivation_path_dip13_mainnet(account: u32) -> JsValue { + pub fn derivation_path_dip13_mainnet(account: u32) -> Dip13DerivationPathWasm { // DIP13 uses m/9'/5'/account' format (DIP13 uses purpose 9, not 13) let path_str = format!("m/{}'/{}'/{}'", DIP13_PURPOSE, DASH_COIN_TYPE, account); - let obj = js_sys::Object::new(); - - js_sys::Reflect::set( - &obj, - &JsValue::from_str("path"), - &JsValue::from_str(&path_str), - ) - .unwrap(); - - js_sys::Reflect::set( - &obj, - &JsValue::from_str("purpose"), - &JsValue::from_f64(DIP13_PURPOSE as f64), - ) - .unwrap(); - - js_sys::Reflect::set( - &obj, - &JsValue::from_str("coin_type"), - &JsValue::from_f64(DASH_COIN_TYPE as f64), - ) - .unwrap(); - - js_sys::Reflect::set( - &obj, - &JsValue::from_str("account"), - &JsValue::from_f64(account as f64), - ) - .unwrap(); - - js_sys::Reflect::set( - &obj, - &JsValue::from_str("description"), - &JsValue::from_str("DIP13 HD identity key path"), - ) - .unwrap(); - - obj.into() + Dip13DerivationPathWasm { + path: path_str, + purpose: DIP13_PURPOSE, + coin_type: DASH_COIN_TYPE, + account, + description: "DIP13 HD identity key path".to_string(), + } } /// Create a DIP13 testnet derivation path (for HD masternode keys) #[wasm_bindgen(js_name = "derivationPathDip13Testnet")] - pub fn derivation_path_dip13_testnet(account: u32) -> JsValue { + pub fn derivation_path_dip13_testnet(account: u32) -> Dip13DerivationPathWasm { // DIP13 uses m/9'/1'/account' format for testnet let path_str = format!("m/{}'/{}'/{}'", DIP13_PURPOSE, TESTNET_COIN_TYPE, account); - let obj = js_sys::Object::new(); - - js_sys::Reflect::set( - &obj, - &JsValue::from_str("path"), - &JsValue::from_str(&path_str), - ) - .unwrap(); - - js_sys::Reflect::set( - &obj, - &JsValue::from_str("purpose"), - &JsValue::from_f64(DIP13_PURPOSE as f64), - ) - .unwrap(); - - js_sys::Reflect::set( - &obj, - &JsValue::from_str("coin_type"), - &JsValue::from_f64(TESTNET_COIN_TYPE as f64), - ) - .unwrap(); - - js_sys::Reflect::set( - &obj, - &JsValue::from_str("account"), - &JsValue::from_f64(account as f64), - ) - .unwrap(); - - js_sys::Reflect::set( - &obj, - &JsValue::from_str("description"), - &JsValue::from_str("DIP13 HD identity key path (testnet)"), - ) - .unwrap(); - - obj.into() + Dip13DerivationPathWasm { + path: path_str, + purpose: DIP13_PURPOSE, + coin_type: TESTNET_COIN_TYPE, + account, + description: "DIP13 HD identity key path (testnet)".to_string(), + } } /// Get child public key from extended public key diff --git a/packages/wasm-sdk/src/wallet/key_generation.rs b/packages/wasm-sdk/src/wallet/key_generation.rs index 248565dfdaf..f453a4e09df 100644 --- a/packages/wasm-sdk/src/wallet/key_generation.rs +++ b/packages/wasm-sdk/src/wallet/key_generation.rs @@ -7,12 +7,11 @@ use crate::sdk::WasmSdk; use dash_sdk::dpp::dashcore::hashes::{sha256, Hash}; use dash_sdk::dpp::dashcore::secp256k1::{Secp256k1, SecretKey}; use dash_sdk::dpp::dashcore::{Address, Network, PrivateKey, PublicKey}; -use serde::{Deserialize, Serialize}; use std::str::FromStr; use wasm_bindgen::prelude::*; /// Key pair information -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone)] pub struct KeyPair { /// Private key in WIF format pub private_key_wif: String, @@ -26,11 +25,57 @@ pub struct KeyPair { pub network: String, } +#[wasm_bindgen(js_name = "KeyPair")] +#[derive(Clone)] +pub struct KeyPairWasm { + #[wasm_bindgen(getter_with_clone, js_name = "privateKeyWif")] + pub private_key_wif: String, + #[wasm_bindgen(getter_with_clone, js_name = "privateKeyHex")] + pub private_key_hex: String, + #[wasm_bindgen(getter_with_clone, js_name = "publicKey")] + pub public_key: String, + #[wasm_bindgen(getter_with_clone)] + pub address: String, + #[wasm_bindgen(getter_with_clone)] + pub network: String, +} + +impl From for KeyPairWasm { + fn from(value: KeyPair) -> Self { + Self { + private_key_wif: value.private_key_wif, + private_key_hex: value.private_key_hex, + public_key: value.public_key, + address: value.address, + network: value.network, + } + } +} + #[wasm_bindgen] impl WasmSdk { + fn build_key_pair( + private_key: &PrivateKey, + network: Network, + network_label: &str, + ) -> Result { + let secp = Secp256k1::new(); + let public_key = private_key.public_key(&secp); + let public_key_bytes = public_key.inner.serialize(); + let address = Address::p2pkh(&public_key, network); + + Ok(KeyPair { + private_key_wif: private_key.to_wif(), + private_key_hex: hex::encode(private_key.inner.secret_bytes()), + public_key: hex::encode(public_key_bytes), + address: address.to_string(), + network: network_label.to_string(), + }) + } + /// Generate a new random key pair #[wasm_bindgen(js_name = "generateKeyPair")] - pub fn generate_key_pair(network: &str) -> Result { + pub fn generate_key_pair(network: &str) -> Result { let net = match network { "mainnet" => Network::Dash, "testnet" => Network::Testnet, @@ -51,38 +96,17 @@ impl WasmSdk { let private_key = PrivateKey::from_byte_array(&key_bytes, net) .map_err(|e| WasmSdkError::generic(format!("Failed to create private key: {}", e)))?; - // Get public key - let secp = Secp256k1::new(); - let secret_key = SecretKey::from_slice(&key_bytes) + // Ensure secret key is valid before building info + SecretKey::from_slice(&key_bytes) .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid secret key: {}", e)))?; - let public_key = - dash_sdk::dpp::dashcore::secp256k1::PublicKey::from_secret_key(&secp, &secret_key); - let public_key_bytes = public_key.serialize(); - - // Get address - let address = Address::p2pkh( - &PublicKey::from_slice(&public_key_bytes).map_err(|e| { - WasmSdkError::generic(format!("Failed to create public key: {}", e)) - })?, - net, - ); - - let key_pair = KeyPair { - private_key_wif: private_key.to_wif(), - private_key_hex: hex::encode(key_bytes), - public_key: hex::encode(public_key_bytes), - address: address.to_string(), - network: network.to_string(), - }; - serde_wasm_bindgen::to_value(&key_pair).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize key pair: {}", e)) - }) + let key_pair = Self::build_key_pair(&private_key, net, network)?; + Ok(KeyPairWasm::from(key_pair)) } /// Generate multiple key pairs #[wasm_bindgen(js_name = "generateKeyPairs")] - pub fn generate_key_pairs(network: &str, count: u32) -> Result, WasmSdkError> { + pub fn generate_key_pairs(network: &str, count: u32) -> Result, WasmSdkError> { if count == 0 || count > 100 { return Err(WasmSdkError::invalid_argument( "Count must be between 1 and 100", @@ -100,7 +124,7 @@ impl WasmSdk { #[wasm_bindgen(js_name = "keyPairFromWif")] pub fn key_pair_from_wif( #[wasm_bindgen(js_name = "privateKeyWif")] private_key_wif: &str, - ) -> Result { + ) -> Result { let private_key = PrivateKey::from_wif(private_key_wif) .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid WIF: {}", e)))?; @@ -110,33 +134,8 @@ impl WasmSdk { _ => return Err(WasmSdkError::invalid_argument("Unsupported network")), }; - // Get public key - let secp = Secp256k1::new(); - let secret_key = SecretKey::from_slice(&private_key.inner.secret_bytes()) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid secret key: {}", e)))?; - let public_key = - dash_sdk::dpp::dashcore::secp256k1::PublicKey::from_secret_key(&secp, &secret_key); - let public_key_bytes = public_key.serialize(); - - // Get address - let address = Address::p2pkh( - &PublicKey::from_slice(&public_key_bytes).map_err(|e| { - WasmSdkError::generic(format!("Failed to create public key: {}", e)) - })?, - private_key.network, - ); - - let key_pair = KeyPair { - private_key_wif: private_key_wif.to_string(), - private_key_hex: hex::encode(private_key.inner.secret_bytes()), - public_key: hex::encode(public_key_bytes), - address: address.to_string(), - network: network.to_string(), - }; - - serde_wasm_bindgen::to_value(&key_pair).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize key pair: {}", e)) - }) + let key_pair = Self::build_key_pair(&private_key, private_key.network, network)?; + Ok(KeyPairWasm::from(key_pair)) } /// Create key pair from private key hex @@ -144,7 +143,7 @@ impl WasmSdk { pub fn key_pair_from_hex( #[wasm_bindgen(js_name = "privateKeyHex")] private_key_hex: &str, network: &str, - ) -> Result { + ) -> Result { if private_key_hex.len() != 64 { return Err(WasmSdkError::invalid_argument( "Private key hex must be exactly 64 characters", @@ -170,7 +169,8 @@ impl WasmSdk { let private_key = PrivateKey::from_byte_array(&key_array, net) .map_err(|e| WasmSdkError::generic(format!("Failed to create private key: {}", e)))?; - Self::key_pair_from_wif(&private_key.to_wif()) + let key_pair = Self::build_key_pair(&private_key, net, network)?; + Ok(KeyPairWasm::from(key_pair)) } /// Get address from public key diff --git a/packages/wasm-sdk/tests/unit/derivation.spec.mjs b/packages/wasm-sdk/tests/unit/derivation.spec.mjs index 698ccf87254..8a7c8c434b7 100644 --- a/packages/wasm-sdk/tests/unit/derivation.spec.mjs +++ b/packages/wasm-sdk/tests/unit/derivation.spec.mjs @@ -9,30 +9,30 @@ describe('Key derivation', () => { it('BIP44 mainnet/testnet', () => { const m = sdk.WasmSdk.derivationPathBip44Mainnet(0, 0, 0); expect(m.purpose).to.equal(44); - expect(m.coin_type).to.equal(5); + expect(m.coinType).to.equal(5); expect(m.account).to.equal(0); expect(m.change).to.equal(0); expect(m.index).to.equal(0); - const expectedMain = `m/${m.purpose}'/${m.coin_type}'/${m.account}'/${m.change}/${m.index}`; + const expectedMain = `m/${m.purpose}'/${m.coinType}'/${m.account}'/${m.change}/${m.index}`; expect(expectedMain).to.equal("m/44'/5'/0'/0/0"); const t = sdk.WasmSdk.derivationPathBip44Testnet(0, 0, 0); - expect(t.coin_type).to.equal(1); - const expectedTest = `m/${t.purpose}'/${t.coin_type}'/${t.account}'/${t.change}/${t.index}`; + expect(t.coinType).to.equal(1); + const expectedTest = `m/${t.purpose}'/${t.coinType}'/${t.account}'/${t.change}/${t.index}`; expect(expectedTest).to.equal("m/44'/1'/0'/0/0"); }); it('DIP9 mainnet/testnet', () => { const m = sdk.WasmSdk.derivationPathDip9Mainnet(5, 0, 0); expect(m.purpose).to.equal(9); - expect(m.coin_type).to.equal(5); + expect(m.coinType).to.equal(5); expect(m.account).to.equal(5); - const expectedMain = `m/${m.purpose}'/${m.coin_type}'/${m.account}'/${m.change}/${m.index}`; + const expectedMain = `m/${m.purpose}'/${m.coinType}'/${m.account}'/${m.change}/${m.index}`; expect(expectedMain).to.equal("m/9'/5'/5'/0/0"); const t = sdk.WasmSdk.derivationPathDip9Testnet(5, 0, 0); - expect(t.coin_type).to.equal(1); - const expectedTest = `m/${t.purpose}'/${t.coin_type}'/${t.account}'/${t.change}/${t.index}`; + expect(t.coinType).to.equal(1); + const expectedTest = `m/${t.purpose}'/${t.coinType}'/${t.account}'/${t.change}/${t.index}`; expect(expectedTest).to.equal("m/9'/1'/5'/0/0"); }); @@ -68,7 +68,7 @@ describe('Key derivation', () => { }); expect(r).to.exist(); expect(r.path).to.equal(path); - expect(r.private_key_wif).to.be.a('string'); + expect(r.privateKeyWif).to.be.a('string'); expect(r.address).to.be.a('string'); }); diff --git a/packages/wasm-sdk/tests/unit/key-generation.spec.mjs b/packages/wasm-sdk/tests/unit/key-generation.spec.mjs index 47a6378b12f..51e92a07062 100644 --- a/packages/wasm-sdk/tests/unit/key-generation.spec.mjs +++ b/packages/wasm-sdk/tests/unit/key-generation.spec.mjs @@ -46,15 +46,15 @@ describe('Keys and mnemonics', () => { it('derives address from pubkey equals generated address', () => { const kp = sdk.WasmSdk.generateKeyPair('mainnet'); - const addr = sdk.WasmSdk.pubkeyToAddress(kp.public_key, 'mainnet'); + const addr = sdk.WasmSdk.pubkeyToAddress(kp.publicKey, 'mainnet'); expect(addr).to.equal(kp.address); }); it('signs messages deterministically for same inputs', () => { const kp = sdk.WasmSdk.generateKeyPair('mainnet'); const msg = 'Hello, Dash!'; - const s1 = sdk.WasmSdk.signMessage(msg, kp.private_key_wif); - const s2 = sdk.WasmSdk.signMessage(msg, kp.private_key_wif); + const s1 = sdk.WasmSdk.signMessage(msg, kp.privateKeyWif); + const s2 = sdk.WasmSdk.signMessage(msg, kp.privateKeyWif); expect(s1).to.be.a('string'); expect(s1).to.equal(s2); }); diff --git a/yarn.lock b/yarn.lock index a698eda92e0..c31159136c3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6738,7 +6738,7 @@ __metadata: hasbin: "npm:^1.2.3" is-wsl: "npm:2.2.0" jayson: "npm:^4.1.0" - js-yaml: "npm:^4.1.0" + js-yaml: "npm:^4.1.1" listr2: "npm:5.0.7" lodash: "npm:^4.17.21" memory-streams: "npm:^0.1.3" @@ -7960,7 +7960,7 @@ __metadata: languageName: node linkType: hard -"esprima@npm:^4.0.0, esprima@npm:^4.0.1, esprima@npm:~4.0.0": +"esprima@npm:^4.0.1, esprima@npm:~4.0.0": version: 4.0.1 resolution: "esprima@npm:4.0.1" bin: @@ -10266,38 +10266,14 @@ __metadata: languageName: node linkType: hard -"js-yaml@npm:3.13.1": - version: 3.13.1 - resolution: "js-yaml@npm:3.13.1" - dependencies: - argparse: "npm:^1.0.7" - esprima: "npm:^4.0.0" - bin: - js-yaml: bin/js-yaml.js - checksum: cec89175b065743875fce53e63adc8b89aded77e18d00e54ff80c57ab730f22ccfddaf2fe3e6adab1d6dff59a3d55dd9ae6fc711d46335b7e94c32d3583a5627 - languageName: node - linkType: hard - -"js-yaml@npm:^3.10.0, js-yaml@npm:^3.13.0, js-yaml@npm:^3.13.1, js-yaml@npm:^3.14.1": - version: 3.14.1 - resolution: "js-yaml@npm:3.14.1" - dependencies: - argparse: "npm:^1.0.7" - esprima: "npm:^4.0.0" - bin: - js-yaml: bin/js-yaml.js - checksum: 9e22d80b4d0105b9899135365f746d47466ed53ef4223c529b3c0f7a39907743fdbd3c4379f94f1106f02755b5e90b2faaf84801a891135544e1ea475d1a1379 - languageName: node - linkType: hard - -"js-yaml@npm:^4.1.0": - version: 4.1.0 - resolution: "js-yaml@npm:4.1.0" +"js-yaml@npm:^4.1.1": + version: 4.1.1 + resolution: "js-yaml@npm:4.1.1" dependencies: argparse: "npm:^2.0.1" bin: js-yaml: bin/js-yaml.js - checksum: c138a34a3fd0d08ebaf71273ad4465569a483b8a639e0b118ff65698d257c2791d3199e3f303631f2cb98213fa7b5f5d6a4621fd0fff819421b990d30d967140 + checksum: a52d0519f0f4ef5b4adc1cde466cb54c50d56e2b4a983b9d5c9c0f2f99462047007a6274d7e95617a21d3c91fde3ee6115536ed70991cd645ba8521058b78f77 languageName: node linkType: hard