Skip to content

Commit 32f4448

Browse files
authored
fix(js): return body as string (#182)
Signed-off-by: Timo Glastra <[email protected]>
1 parent 3e610cf commit 32f4448

File tree

15 files changed

+39
-26
lines changed

15 files changed

+39
-26
lines changed

libindy_vdr/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "indy-vdr"
3-
version = "0.4.0-dev.13"
3+
version = "0.4.0-dev.14"
44
authors = ["Hyperledger Indy Contributors <[email protected]>"]
55
description = "A library for interacting with Hyperledger Indy Node, a distributed ledger for self-sovereign identity (https://www.hyperledger.org/use/hyperledger-indy)."
66
edition = "2021"

wrappers/javascript/indy-vdr-nodejs/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hyperledger/indy-vdr-nodejs",
3-
"version": "0.1.0-dev.13",
3+
"version": "0.1.0-dev.14",
44
"license": "Apache-2.0",
55
"description": "Nodejs wrapper for Indy Vdr",
66
"source": "src/index",
@@ -41,7 +41,7 @@
4141
"typescript": "~4.9.4"
4242
},
4343
"dependencies": {
44-
"@hyperledger/indy-vdr-shared": "0.1.0-dev.13",
44+
"@hyperledger/indy-vdr-shared": "0.1.0-dev.14",
4545
"@mapbox/node-pre-gyp": "^1.0.10",
4646
"@types/ref-array-di": "^1.2.5",
4747
"ffi-napi": "^4.0.3",
@@ -52,7 +52,7 @@
5252
"binary": {
5353
"module_name": "indy_vdr",
5454
"module_path": "native",
55-
"remote_path": "v0.4.0-dev.13",
55+
"remote_path": "v0.4.0-dev.14",
5656
"host": "https://github.com/hyperledger/indy-vdr/releases/download/",
5757
"package_name": "library-{platform}-{arch}.tar.gz"
5858
}

wrappers/javascript/indy-vdr-nodejs/src/NodeJSIndyVdr.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,13 @@ export class NodeJSIndyVdr implements IndyVdr {
511511
this.handleError(this.nativeIndyVdr.indy_vdr_request_free(requestHandle))
512512
}
513513

514-
public requestGetBody<T extends Record<string, unknown>>(options: { requestHandle: number }): T {
514+
public requestGetBody(options: { requestHandle: number }): string {
515515
const output = allocateString()
516516
const { requestHandle } = serializeArguments(options)
517517

518518
this.handleError(this.nativeIndyVdr.indy_vdr_request_get_body(requestHandle, output))
519519

520-
const outputString = handleReturnPointer<string>(output)
521-
return JSON.parse(outputString) as T
520+
return handleReturnPointer<string>(output)
522521
}
523522

524523
public requestGetSignatureInput(options: { requestHandle: number }): string {

wrappers/javascript/indy-vdr-nodejs/src/ffi/serialize.ts

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export type SerializedOptions<Type> = Required<{
2020
? number
2121
: Type[Property] extends Record<string, unknown>
2222
? string
23+
: Type[Property] extends string | Record<string, unknown>
24+
? string
2325
: Type[Property] extends Array<unknown>
2426
? string
2527
: Type[Property] extends Array<unknown> | undefined

wrappers/javascript/indy-vdr-nodejs/tests/CustomRequest.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,20 @@ describe('CustomRequest', () => {
2323
op: 'REPLY',
2424
})
2525
})
26+
27+
test('Can parse a request from string', () => {
28+
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}}`
29+
const request = new CustomRequest({
30+
customRequest: json,
31+
})
32+
33+
request.setMultiSignature({
34+
identifier: 'TL1EaPFCZ8Si5aUrqScBDt',
35+
signature: Buffer.from('Hello, this is a signature'),
36+
})
37+
38+
expect(request.body).toEqual(
39+
'{"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}}'
40+
)
41+
})
2642
})

wrappers/javascript/indy-vdr-nodejs/tests/IndyVdrRequest.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ describe('IndyVdrRequest', () => {
2020
})
2121

2222
test('Get request body', () => {
23-
expect(request.body).toMatchObject({
23+
expect(typeof request.body).toEqual('string')
24+
expect(JSON.parse(request.body)).toMatchObject({
2425
identifier: 'LibindyDid111111111111',
2526
operation: {
2627
data: { name: 'MyName', version: '1.0' },

wrappers/javascript/indy-vdr-react-native/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hyperledger/indy-vdr-react-native",
3-
"version": "0.1.0-dev.13",
3+
"version": "0.1.0-dev.14",
44
"license": "Apache-2.0",
55
"description": "React Native wrapper for Indy Vdr",
66
"source": "src/index",
@@ -40,7 +40,7 @@
4040
"install": "node-pre-gyp install"
4141
},
4242
"dependencies": {
43-
"@hyperledger/indy-vdr-shared": "0.1.0-dev.13",
43+
"@hyperledger/indy-vdr-shared": "0.1.0-dev.14",
4444
"@mapbox/node-pre-gyp": "^1.0.10"
4545
},
4646
"devDependencies": {
@@ -58,7 +58,7 @@
5858
"binary": {
5959
"module_name": "indy_vdr",
6060
"module_path": "native",
61-
"remote_path": "v0.4.0-dev.13",
61+
"remote_path": "v0.4.0-dev.14",
6262
"host": "https://github.com/hyperledger/indy-vdr/releases/download/",
6363
"package_name": "library-ios-android.tar.gz"
6464
}

wrappers/javascript/indy-vdr-react-native/src/ReactNativeIndyVdr.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,9 @@ export class ReactNativeIndyVdr implements IndyVdr {
303303
indyVdrReactNative.requestFree(serializedOptions)
304304
}
305305

306-
public requestGetBody<T extends Record<string, unknown>>(options: { requestHandle: number }): T {
306+
public requestGetBody(options: { requestHandle: number }): string {
307307
const serializedOptions = serializeArguments(options)
308-
const result = handleError(indyVdrReactNative.requestGetBody(serializedOptions))
309-
return JSON.parse(result) as T
308+
return handleError(indyVdrReactNative.requestGetBody(serializedOptions))
310309
}
311310

312311
public requestGetSignatureInput(options: { requestHandle: number }): string {

wrappers/javascript/indy-vdr-react-native/src/utils/serialize.ts

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export type SerializedOptions<Type> = {
1919
? number
2020
: Type[Property] extends Record<string, unknown>
2121
? string
22+
: Type[Property] extends string | Record<string, unknown>
23+
? string
2224
: Type[Property] extends Array<unknown>
2325
? string
2426
: Type[Property] extends Array<unknown> | undefined

wrappers/javascript/indy-vdr-shared/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hyperledger/indy-vdr-shared",
3-
"version": "0.1.0-dev.13",
3+
"version": "0.1.0-dev.14",
44
"license": "Apache-2.0",
55
"description": "Shared library for using Indy VDR with NodeJS and React Native",
66
"main": "build/index",

wrappers/javascript/indy-vdr-shared/src/builder/CustomRequest.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { indyVdr, IndyVdrRequest } from '../indyVdr'
22

3-
// TODO: this needs some more work, but need to find a way to use it first.
43
export type CustomRequestOptions = {
5-
customRequest: {
6-
protocolVersion: 1 | 2
7-
reqId?: number
8-
identifier: string
9-
operation: Record<string, unknown>
10-
}
4+
customRequest: string | Record<string, unknown>
115
}
126

137
export class CustomRequest extends IndyVdrRequest {

wrappers/javascript/indy-vdr-shared/src/indyVdr/IndyVdrRequest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class IndyVdrRequest<ResponseType extends Record<string, unknown> = Recor
3636
return this._handle
3737
}
3838

39-
public get body(): Record<string, unknown> {
39+
public get body(): string {
4040
return indyVdr.requestGetBody({ requestHandle: this.handle })
4141
}
4242

wrappers/javascript/indy-vdr-shared/src/types/IndyVdr.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export interface IndyVdr {
115115

116116
requestFree(options: { requestHandle: number }): void
117117

118-
requestGetBody<T extends Record<string, unknown>>(options: { requestHandle: number }): T
118+
requestGetBody(options: { requestHandle: number }): string
119119

120120
requestGetSignatureInput(options: { requestHandle: number }): string
121121

wrappers/javascript/lerna.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"packages": ["packages/*"],
3-
"version": "0.1.0-dev.13",
3+
"version": "0.1.0-dev.14",
44
"useWorkspaces": true,
55
"npmClient": "yarn",
66
"command": {

wrappers/python/indy_vdr/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""indy_vdr library wrapper version."""
22

3-
__version__ = "0.4.0.dev13"
3+
__version__ = "0.4.0.dev14"

0 commit comments

Comments
 (0)