From 08f1f61052109715321a2f111fd1a84a532e02a3 Mon Sep 17 00:00:00 2001 From: Daniel Rocha <68558152+danroc@users.noreply.github.com> Date: Mon, 4 Sep 2023 12:38:39 +0200 Subject: [PATCH] feat: move request ID to outer request BREAKING: This is a breaking API change. --- src/KeyringClient.test.ts | 15 ++++++--------- src/api.ts | 19 ++++++++++++------- src/rpc-handler.test.ts | 5 ++--- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/KeyringClient.test.ts b/src/KeyringClient.test.ts index cde4254b4..f1df149cb 100644 --- a/src/KeyringClient.test.ts +++ b/src/KeyringClient.test.ts @@ -165,11 +165,10 @@ describe('KeyringClient', () => { it('should send a request to list requests and return the response', async () => { const expectedResponse: KeyringRequest[] = [ { - account: '46b5ccd3-4786-427c-89d2-cef626dffe9b', + id: '71621d8d-62a4-4bf4-97cc-fb8f243679b0', scope: 'eip155:1', + account: '46b5ccd3-4786-427c-89d2-cef626dffe9b', request: { - jsonrpc: '2.0', - id: '71621d8d-62a4-4bf4-97cc-fb8f243679b0', method: 'personal_sign', params: ['0xe9a74aacd7df8112911ca93260fc5a046f8a64ae', '0x0'], }, @@ -191,11 +190,10 @@ describe('KeyringClient', () => { it('should send a request to get a request and return the response', async () => { const id = '71621d8d-62a4-4bf4-97cc-fb8f243679b0'; const expectedResponse: KeyringRequest = { - account: '46b5ccd3-4786-427c-89d2-cef626dffe9b', + id, scope: 'eip155:1', + account: '46b5ccd3-4786-427c-89d2-cef626dffe9b', request: { - jsonrpc: '2.0', - id, method: 'personal_sign', params: ['0xe9a74aacd7df8112911ca93260fc5a046f8a64ae', '0x0'], }, @@ -216,11 +214,10 @@ describe('KeyringClient', () => { describe('submitRequest', () => { it('should send a request to submit a request', async () => { const request: KeyringRequest = { - account: '46b5ccd3-4786-427c-89d2-cef626dffe9b', + id: '71621d8d-62a4-4bf4-97cc-fb8f243679b0', scope: 'eip155:1', + account: '46b5ccd3-4786-427c-89d2-cef626dffe9b', request: { - jsonrpc: '2.0', - id: '71621d8d-62a4-4bf4-97cc-fb8f243679b0', method: 'personal_sign', params: ['0xe9a74aacd7df8112911ca93260fc5a046f8a64ae', '0x0'], }, diff --git a/src/api.ts b/src/api.ts index 1b18a9bf4..3e3bac437 100644 --- a/src/api.ts +++ b/src/api.ts @@ -12,7 +12,6 @@ import { nullable, } from 'superstruct'; -import { JsonRpcRequestStruct } from './JsonRpcRequest'; import { UuidStruct } from './utils'; /** @@ -82,9 +81,9 @@ export type KeyringAccount = Infer; export const KeyringRequestStruct = object({ /** - * Account ID (UUIDv4). + * Keyring request ID (UUIDv4). */ - account: UuidStruct, + id: UuidStruct, /** * Request's scope (CAIP-2 chain ID). @@ -92,11 +91,17 @@ export const KeyringRequestStruct = object({ scope: string(), /** - * JSON-RPC request sent by the client application. - * - * Note: The request ID must be a string. + * Account ID (UUIDv4). */ - request: JsonRpcRequestStruct, + account: UuidStruct, + + /** + * Inner request sent by the client application. + */ + request: object({ + method: string(), + params: union([array(JsonStruct), record(string(), JsonStruct)]), + }), }); /** diff --git a/src/rpc-handler.test.ts b/src/rpc-handler.test.ts index 2c592a497..9b02841d9 100644 --- a/src/rpc-handler.test.ts +++ b/src/rpc-handler.test.ts @@ -379,11 +379,10 @@ describe('keyringRpcDispatcher', () => { it('should call keyring_submitRequest', async () => { const dappRequest = { + id: 'c555de37-cf4b-4ff2-8273-39db7fb58f1c', + scope: 'eip155:1', account: '4abdd17e-8b0f-4d06-a017-947a64823b3d', - scope: '', request: { - jsonrpc: '2.0', - id: 'c555de37-cf4b-4ff2-8273-39db7fb58f1c', method: 'eth_method', params: [1, 2, 3], },