Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

feat: move request ID to outer request #94

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/KeyringClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
Expand All @@ -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'],
},
Expand All @@ -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'],
},
Expand Down
19 changes: 12 additions & 7 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
nullable,
} from 'superstruct';

import { JsonRpcRequestStruct } from './JsonRpcRequest';
import { UuidStruct } from './utils';

/**
Expand Down Expand Up @@ -82,21 +81,27 @@ export type KeyringAccount = Infer<typeof KeyringAccountStruct>;

export const KeyringRequestStruct = object({
/**
* Account ID (UUIDv4).
* Keyring request ID (UUIDv4).
*/
account: UuidStruct,
id: UuidStruct,

/**
* Request's scope (CAIP-2 chain ID).
*/
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)]),
}),
});

/**
Expand Down
5 changes: 2 additions & 3 deletions src/rpc-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
},
Expand Down