From 9a304566d6c71161383bf951fee4aaf4d2b66b8b Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Mon, 10 Apr 2023 11:21:17 +0200 Subject: [PATCH 1/6] fix(js): return body as string to This is to prevent the reqId (which is a large number) from overflowing and changing Signed-off-by: Timo Glastra --- .../indy-vdr-nodejs/src/NodeJSIndyVdr.ts | 5 ++--- .../tests/CustomRequest.test.ts | 20 +++++++++++++++++-- .../src/ReactNativeIndyVdr.ts | 5 ++--- .../src/builder/CustomRequest.ts | 8 +------- .../src/indyVdr/IndyVdrRequest.ts | 2 +- .../indy-vdr-shared/src/types/IndyVdr.ts | 2 +- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/wrappers/javascript/indy-vdr-nodejs/src/NodeJSIndyVdr.ts b/wrappers/javascript/indy-vdr-nodejs/src/NodeJSIndyVdr.ts index 5dc0da71..c5844bc5 100644 --- a/wrappers/javascript/indy-vdr-nodejs/src/NodeJSIndyVdr.ts +++ b/wrappers/javascript/indy-vdr-nodejs/src/NodeJSIndyVdr.ts @@ -511,14 +511,13 @@ export class NodeJSIndyVdr implements IndyVdr { this.handleError(this.nativeIndyVdr.indy_vdr_request_free(requestHandle)) } - public requestGetBody>(options: { requestHandle: number }): T { + public requestGetBody(options: { requestHandle: number }): string { const output = allocateString() const { requestHandle } = serializeArguments(options) this.handleError(this.nativeIndyVdr.indy_vdr_request_get_body(requestHandle, output)) - const outputString = handleReturnPointer(output) - return JSON.parse(outputString) as T + return handleReturnPointer(output) } public requestGetSignatureInput(options: { requestHandle: number }): string { diff --git a/wrappers/javascript/indy-vdr-nodejs/tests/CustomRequest.test.ts b/wrappers/javascript/indy-vdr-nodejs/tests/CustomRequest.test.ts index 42dd5362..0395d343 100644 --- a/wrappers/javascript/indy-vdr-nodejs/tests/CustomRequest.test.ts +++ b/wrappers/javascript/indy-vdr-nodejs/tests/CustomRequest.test.ts @@ -1,9 +1,9 @@ import type { IndyVdrPool } from '@hyperledger/indy-vdr-nodejs' -import { DID, setupPool } from './utils' - import { CustomRequest } from '@hyperledger/indy-vdr-nodejs' +import { DID, setupPool } from './utils' + describe('CustomRequest', () => { let pool: IndyVdrPool @@ -23,4 +23,20 @@ describe('CustomRequest', () => { op: 'REPLY', }) }) + + test('Can parse a request from string', async () => { + const json = `{"endorser":"DJKobikPAaYWAu9vfhEEo5","identifier":"2GjxcxqE2XnFrVhipkWCWT","operation":{"dest":"2GjxcxqE2XnFrVhipkWCWT","raw":"{\\"endpoint\\":{\\"endpoint\\":\\"https://example.com/endpoint\\",\\"routingKeys\\":[\\"a-routing-key\\"],\\"types\\":[\\"endpoint\\",\\"did-communication\\",\\"DIDComm\\"]}}","type":"100"},"protocolVersion":2,"reqId":1680599092494999800,"signature":"3RyENWHC1szYH7FwDfZ2pKteShtsuDgYCSjGQGDPDjAYE5mipCZ6AnZKuAgCQYq6yt1LEfPPRKVS8BjBirX5s5q3","taaAcceptance":{"mechanism":"accept","taaDigest":"e546ad2a5311b2020fd80efb4d17ec75f823d26ee2424cf741ee345ede9d3ff3","time":1680566400}}` + const request = new CustomRequest({ + customRequest: json, + }) + + request.setMultiSignature({ + identifier: 'TL1EaPFCZ8Si5aUrqScBDt', + signature: Buffer.from('Hello, this is a signature'), + }) + + expect(request.body).toEqual( + '{"endorser":"DJKobikPAaYWAu9vfhEEo5","identifier":"2GjxcxqE2XnFrVhipkWCWT","operation":{"dest":"2GjxcxqE2XnFrVhipkWCWT","raw":"{\\"endpoint\\":{\\"endpoint\\":\\"https://example.com/endpoint\\",\\"routingKeys\\":[\\"a-routing-key\\"],\\"types\\":[\\"endpoint\\",\\"did-communication\\",\\"DIDComm\\"]}}","type":"100"},"protocolVersion":2,"reqId":1680599092494999800,"signatures":{"2GjxcxqE2XnFrVhipkWCWT":"3RyENWHC1szYH7FwDfZ2pKteShtsuDgYCSjGQGDPDjAYE5mipCZ6AnZKuAgCQYq6yt1LEfPPRKVS8BjBirX5s5q3","TL1EaPFCZ8Si5aUrqScBDt":"3DaTn63KBMjCE8pCLkDvMBFPKHefZiQXyzr8"},"taaAcceptance":{"mechanism":"accept","taaDigest":"e546ad2a5311b2020fd80efb4d17ec75f823d26ee2424cf741ee345ede9d3ff3","time":1680566400}}' + ) + }) }) diff --git a/wrappers/javascript/indy-vdr-react-native/src/ReactNativeIndyVdr.ts b/wrappers/javascript/indy-vdr-react-native/src/ReactNativeIndyVdr.ts index 273505f8..307f3824 100644 --- a/wrappers/javascript/indy-vdr-react-native/src/ReactNativeIndyVdr.ts +++ b/wrappers/javascript/indy-vdr-react-native/src/ReactNativeIndyVdr.ts @@ -303,10 +303,9 @@ export class ReactNativeIndyVdr implements IndyVdr { indyVdrReactNative.requestFree(serializedOptions) } - public requestGetBody>(options: { requestHandle: number }): T { + public requestGetBody(options: { requestHandle: number }): string { const serializedOptions = serializeArguments(options) - const result = handleError(indyVdrReactNative.requestGetBody(serializedOptions)) - return JSON.parse(result) as T + return handleError(indyVdrReactNative.requestGetBody(serializedOptions)) } public requestGetSignatureInput(options: { requestHandle: number }): string { diff --git a/wrappers/javascript/indy-vdr-shared/src/builder/CustomRequest.ts b/wrappers/javascript/indy-vdr-shared/src/builder/CustomRequest.ts index e5267d7c..7dc15363 100644 --- a/wrappers/javascript/indy-vdr-shared/src/builder/CustomRequest.ts +++ b/wrappers/javascript/indy-vdr-shared/src/builder/CustomRequest.ts @@ -1,13 +1,7 @@ import { indyVdr, IndyVdrRequest } from '../indyVdr' -// TODO: this needs some more work, but need to find a way to use it first. export type CustomRequestOptions = { - customRequest: { - protocolVersion: 1 | 2 - reqId?: number - identifier: string - operation: Record - } + customRequest: string | Record } export class CustomRequest extends IndyVdrRequest { diff --git a/wrappers/javascript/indy-vdr-shared/src/indyVdr/IndyVdrRequest.ts b/wrappers/javascript/indy-vdr-shared/src/indyVdr/IndyVdrRequest.ts index bce85d9f..3ac2601f 100644 --- a/wrappers/javascript/indy-vdr-shared/src/indyVdr/IndyVdrRequest.ts +++ b/wrappers/javascript/indy-vdr-shared/src/indyVdr/IndyVdrRequest.ts @@ -36,7 +36,7 @@ export class IndyVdrRequest = Recor return this._handle } - public get body(): Record { + public get body(): string { return indyVdr.requestGetBody({ requestHandle: this.handle }) } diff --git a/wrappers/javascript/indy-vdr-shared/src/types/IndyVdr.ts b/wrappers/javascript/indy-vdr-shared/src/types/IndyVdr.ts index 8c6d7237..b56af0b5 100644 --- a/wrappers/javascript/indy-vdr-shared/src/types/IndyVdr.ts +++ b/wrappers/javascript/indy-vdr-shared/src/types/IndyVdr.ts @@ -115,7 +115,7 @@ export interface IndyVdr { requestFree(options: { requestHandle: number }): void - requestGetBody>(options: { requestHandle: number }): T + requestGetBody(options: { requestHandle: number }): string requestGetSignatureInput(options: { requestHandle: number }): string From f8805eb3ecd7e7de76a05cff42a8dc7b0f4bd4f2 Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Tue, 11 Apr 2023 09:01:32 +0200 Subject: [PATCH 2/6] type fixes Signed-off-by: Timo Glastra --- wrappers/javascript/indy-vdr-nodejs/src/ffi/serialize.ts | 2 ++ .../javascript/indy-vdr-react-native/src/utils/serialize.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/wrappers/javascript/indy-vdr-nodejs/src/ffi/serialize.ts b/wrappers/javascript/indy-vdr-nodejs/src/ffi/serialize.ts index dfa94683..bd4335b4 100644 --- a/wrappers/javascript/indy-vdr-nodejs/src/ffi/serialize.ts +++ b/wrappers/javascript/indy-vdr-nodejs/src/ffi/serialize.ts @@ -20,6 +20,8 @@ export type SerializedOptions = Required<{ ? number : Type[Property] extends Record ? string + : Type[Property] extends string | Record + ? string : Type[Property] extends Array ? string : Type[Property] extends Array | undefined diff --git a/wrappers/javascript/indy-vdr-react-native/src/utils/serialize.ts b/wrappers/javascript/indy-vdr-react-native/src/utils/serialize.ts index 0fe04351..d0c57daf 100644 --- a/wrappers/javascript/indy-vdr-react-native/src/utils/serialize.ts +++ b/wrappers/javascript/indy-vdr-react-native/src/utils/serialize.ts @@ -19,6 +19,8 @@ export type SerializedOptions = { ? number : Type[Property] extends Record ? string + : Type[Property] extends string | Record + ? string : Type[Property] extends Array ? string : Type[Property] extends Array | undefined From b976bcd9c809b7ca961ef227e8ed29ca5e4368de Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Tue, 11 Apr 2023 11:47:15 +0200 Subject: [PATCH 3/6] fixes Signed-off-by: Timo Glastra --- .../javascript/indy-vdr-nodejs/tests/CustomRequest.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wrappers/javascript/indy-vdr-nodejs/tests/CustomRequest.test.ts b/wrappers/javascript/indy-vdr-nodejs/tests/CustomRequest.test.ts index 0395d343..e48a615e 100644 --- a/wrappers/javascript/indy-vdr-nodejs/tests/CustomRequest.test.ts +++ b/wrappers/javascript/indy-vdr-nodejs/tests/CustomRequest.test.ts @@ -1,9 +1,9 @@ import type { IndyVdrPool } from '@hyperledger/indy-vdr-nodejs' -import { CustomRequest } from '@hyperledger/indy-vdr-nodejs' - import { DID, setupPool } from './utils' +import { CustomRequest } from '@hyperledger/indy-vdr-nodejs' + describe('CustomRequest', () => { let pool: IndyVdrPool @@ -24,7 +24,7 @@ describe('CustomRequest', () => { }) }) - test('Can parse a request from string', async () => { + test('Can parse a request from string', () => { const json = `{"endorser":"DJKobikPAaYWAu9vfhEEo5","identifier":"2GjxcxqE2XnFrVhipkWCWT","operation":{"dest":"2GjxcxqE2XnFrVhipkWCWT","raw":"{\\"endpoint\\":{\\"endpoint\\":\\"https://example.com/endpoint\\",\\"routingKeys\\":[\\"a-routing-key\\"],\\"types\\":[\\"endpoint\\",\\"did-communication\\",\\"DIDComm\\"]}}","type":"100"},"protocolVersion":2,"reqId":1680599092494999800,"signature":"3RyENWHC1szYH7FwDfZ2pKteShtsuDgYCSjGQGDPDjAYE5mipCZ6AnZKuAgCQYq6yt1LEfPPRKVS8BjBirX5s5q3","taaAcceptance":{"mechanism":"accept","taaDigest":"e546ad2a5311b2020fd80efb4d17ec75f823d26ee2424cf741ee345ede9d3ff3","time":1680566400}}` const request = new CustomRequest({ customRequest: json, From 9b71badba80ddff9d409155d2011807116a864ca Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Tue, 11 Apr 2023 11:49:43 +0200 Subject: [PATCH 4/6] chore: update version to dev.14 Signed-off-by: Timo Glastra --- libindy_vdr/Cargo.toml | 2 +- wrappers/javascript/indy-vdr-nodejs/package.json | 6 +++--- wrappers/javascript/indy-vdr-react-native/package.json | 6 +++--- wrappers/javascript/indy-vdr-shared/package.json | 2 +- wrappers/javascript/lerna.json | 2 +- wrappers/python/indy_vdr/version.py | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libindy_vdr/Cargo.toml b/libindy_vdr/Cargo.toml index 2b6849be..7a4e601d 100644 --- a/libindy_vdr/Cargo.toml +++ b/libindy_vdr/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "indy-vdr" -version = "0.4.0-dev.13" +version = "0.4.0-dev.14" authors = ["Hyperledger Indy Contributors "] description = "A library for interacting with Hyperledger Indy Node, a distributed ledger for self-sovereign identity (https://www.hyperledger.org/use/hyperledger-indy)." edition = "2021" diff --git a/wrappers/javascript/indy-vdr-nodejs/package.json b/wrappers/javascript/indy-vdr-nodejs/package.json index 6619dd5b..ba67eedb 100644 --- a/wrappers/javascript/indy-vdr-nodejs/package.json +++ b/wrappers/javascript/indy-vdr-nodejs/package.json @@ -1,6 +1,6 @@ { "name": "@hyperledger/indy-vdr-nodejs", - "version": "0.1.0-dev.13", + "version": "0.1.0-dev.14", "license": "Apache-2.0", "description": "Nodejs wrapper for Indy Vdr", "source": "src/index", @@ -41,7 +41,7 @@ "typescript": "~4.9.4" }, "dependencies": { - "@hyperledger/indy-vdr-shared": "0.1.0-dev.13", + "@hyperledger/indy-vdr-shared": "0.1.0-dev.14", "@mapbox/node-pre-gyp": "^1.0.10", "@types/ref-array-di": "^1.2.5", "ffi-napi": "^4.0.3", @@ -52,7 +52,7 @@ "binary": { "module_name": "indy_vdr", "module_path": "native", - "remote_path": "v0.4.0-dev.13", + "remote_path": "v0.4.0-dev.14", "host": "https://github.com/hyperledger/indy-vdr/releases/download/", "package_name": "library-{platform}-{arch}.tar.gz" } diff --git a/wrappers/javascript/indy-vdr-react-native/package.json b/wrappers/javascript/indy-vdr-react-native/package.json index 14ebc934..69bcdfd6 100644 --- a/wrappers/javascript/indy-vdr-react-native/package.json +++ b/wrappers/javascript/indy-vdr-react-native/package.json @@ -1,6 +1,6 @@ { "name": "@hyperledger/indy-vdr-react-native", - "version": "0.1.0-dev.13", + "version": "0.1.0-dev.14", "license": "Apache-2.0", "description": "React Native wrapper for Indy Vdr", "source": "src/index", @@ -40,7 +40,7 @@ "install": "node-pre-gyp install" }, "dependencies": { - "@hyperledger/indy-vdr-shared": "0.1.0-dev.13", + "@hyperledger/indy-vdr-shared": "0.1.0-dev.14", "@mapbox/node-pre-gyp": "^1.0.10" }, "devDependencies": { @@ -58,7 +58,7 @@ "binary": { "module_name": "indy_vdr", "module_path": "native", - "remote_path": "v0.4.0-dev.13", + "remote_path": "v0.4.0-dev.14", "host": "https://github.com/hyperledger/indy-vdr/releases/download/", "package_name": "library-ios-android.tar.gz" } diff --git a/wrappers/javascript/indy-vdr-shared/package.json b/wrappers/javascript/indy-vdr-shared/package.json index 2a12d4a6..fbbdcf6d 100644 --- a/wrappers/javascript/indy-vdr-shared/package.json +++ b/wrappers/javascript/indy-vdr-shared/package.json @@ -1,6 +1,6 @@ { "name": "@hyperledger/indy-vdr-shared", - "version": "0.1.0-dev.13", + "version": "0.1.0-dev.14", "license": "Apache-2.0", "description": "Shared library for using Indy VDR with NodeJS and React Native", "main": "build/index", diff --git a/wrappers/javascript/lerna.json b/wrappers/javascript/lerna.json index 5d10bbac..ca41cfe1 100644 --- a/wrappers/javascript/lerna.json +++ b/wrappers/javascript/lerna.json @@ -1,6 +1,6 @@ { "packages": ["packages/*"], - "version": "0.1.0-dev.13", + "version": "0.1.0-dev.14", "useWorkspaces": true, "npmClient": "yarn", "command": { diff --git a/wrappers/python/indy_vdr/version.py b/wrappers/python/indy_vdr/version.py index cc8988f9..5b52bbb7 100644 --- a/wrappers/python/indy_vdr/version.py +++ b/wrappers/python/indy_vdr/version.py @@ -1,3 +1,3 @@ """indy_vdr library wrapper version.""" -__version__ = "0.4.0.dev13" +__version__ = "0.4.0.dev14" From 0a8c3ad5c521dacf6290c1e82a3771541ccd1c6f Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Tue, 11 Apr 2023 12:15:23 +0200 Subject: [PATCH 5/6] fixes Signed-off-by: Timo Glastra --- .../indy-vdr-nodejs/tests/IndyVdrRequest.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wrappers/javascript/indy-vdr-nodejs/tests/IndyVdrRequest.test.ts b/wrappers/javascript/indy-vdr-nodejs/tests/IndyVdrRequest.test.ts index 29669e9e..243a8f60 100644 --- a/wrappers/javascript/indy-vdr-nodejs/tests/IndyVdrRequest.test.ts +++ b/wrappers/javascript/indy-vdr-nodejs/tests/IndyVdrRequest.test.ts @@ -2,10 +2,10 @@ import type { IndyVdrRequest } from '@hyperledger/indy-vdr-nodejs' -import { DID, SCHEMA_ID } from './utils' - import { GetSchemaRequest } from '@hyperledger/indy-vdr-nodejs' +import { DID, SCHEMA_ID } from './utils' + describe('IndyVdrRequest', () => { let request: IndyVdrRequest @@ -20,7 +20,8 @@ describe('IndyVdrRequest', () => { }) test('Get request body', () => { - expect(request.body).toMatchObject({ + expect(typeof request.body).toEqual('string') + expect(JSON.parse(request.body)).toMatchObject({ identifier: 'LibindyDid111111111111', operation: { data: { name: 'MyName', version: '1.0' }, From 16d3774f42a77a395a7322aaad2cdcd8a50b7308 Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Tue, 11 Apr 2023 13:29:27 +0200 Subject: [PATCH 6/6] fixes Signed-off-by: Timo Glastra --- .../javascript/indy-vdr-nodejs/tests/IndyVdrRequest.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wrappers/javascript/indy-vdr-nodejs/tests/IndyVdrRequest.test.ts b/wrappers/javascript/indy-vdr-nodejs/tests/IndyVdrRequest.test.ts index 243a8f60..80fa3346 100644 --- a/wrappers/javascript/indy-vdr-nodejs/tests/IndyVdrRequest.test.ts +++ b/wrappers/javascript/indy-vdr-nodejs/tests/IndyVdrRequest.test.ts @@ -2,10 +2,10 @@ import type { IndyVdrRequest } from '@hyperledger/indy-vdr-nodejs' -import { GetSchemaRequest } from '@hyperledger/indy-vdr-nodejs' - import { DID, SCHEMA_ID } from './utils' +import { GetSchemaRequest } from '@hyperledger/indy-vdr-nodejs' + describe('IndyVdrRequest', () => { let request: IndyVdrRequest