Skip to content

Commit e475f9b

Browse files
committed
Add some basic code for signing API
1 parent 0d0f76c commit e475f9b

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

src/BlockcoreProvider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ export class BlockcoreProvider {
4444
return null;
4545
}
4646

47-
signTypedData() {
48-
return null;
47+
async signTypedData(params?: unknown[] | object) {
48+
console.log('SIGN DATA WITH PARAMS:', params);
49+
50+
return {};
4951
}
5052

5153
// public setNetwork(network: string): void {

src/WebProvider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export class WebProvider implements EIP1193Provider {
5252
param0 = args.params;
5353
}
5454

55+
// params: [from, JSON.stringify(msgParams)]
56+
5557
switch (args.method) {
5658
case 'wallet_requestPermissions': // eip-2255 - https://eips.ethereum.org/EIPS/eip-2255
5759
return [
@@ -79,6 +81,9 @@ export class WebProvider implements EIP1193Provider {
7981
],
8082
},
8183
];
84+
case 'signTypedData':
85+
case 'signTypedData_v4':
86+
return this.provider.signTypedData(args.params);
8287
case 'requestPermissions': //
8388
return null;
8489
case 'getTransactionByHash':

test/provider-blockcore.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,75 @@ test('get CITY network', async (t) => {
1212
t.assert(network.versions.public === 28);
1313
t.assert(network.isProofOfStake === true);
1414
});
15+
16+
test('perform signing request', async (t) => {
17+
let provider = new BlockcoreProvider();
18+
19+
const msgParams = JSON.stringify({
20+
domain: {
21+
// Defining the chain aka Rinkeby testnet or Ethereum Main Net
22+
chainId: 1,
23+
// Give a user friendly name to the specific contract you are signing for.
24+
name: 'Ether Mail',
25+
// If name isn't enough add verifying contract to make sure you are establishing contracts with the proper entity
26+
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
27+
// Just let's you know the latest version. Definitely make sure the field name is correct.
28+
version: '1',
29+
},
30+
31+
// Defining the message signing data content.
32+
message: {
33+
/*
34+
- Anything you want. Just a JSON Blob that encodes the data you want to send
35+
- No required fields
36+
- This is DApp Specific
37+
- Be as explicit as possible when building out the message schema.
38+
*/
39+
contents: 'Hello, Bob!',
40+
attachedMoneyInEth: 4.2,
41+
from: {
42+
name: 'Cow',
43+
wallets: ['0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826', '0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF'],
44+
},
45+
to: [
46+
{
47+
name: 'Bob',
48+
wallets: ['0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB', '0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57', '0xB0B0b0b0b0b0B000000000000000000000000000'],
49+
},
50+
],
51+
},
52+
// Refers to the keys of the *types* object below.
53+
primaryType: 'Mail',
54+
types: {
55+
// TODO: Clarify if EIP712Domain refers to the domain the contract is hosted on
56+
EIP712Domain: [
57+
{ name: 'name', type: 'string' },
58+
{ name: 'version', type: 'string' },
59+
{ name: 'chainId', type: 'uint256' },
60+
{ name: 'verifyingContract', type: 'address' },
61+
],
62+
// Not an EIP712Domain definition
63+
Group: [
64+
{ name: 'name', type: 'string' },
65+
{ name: 'members', type: 'Person[]' },
66+
],
67+
// Refer to PrimaryType
68+
Mail: [
69+
{ name: 'from', type: 'Person' },
70+
{ name: 'to', type: 'Person[]' },
71+
{ name: 'contents', type: 'string' },
72+
],
73+
// Not an EIP712Domain definition
74+
Person: [
75+
{ name: 'name', type: 'string' },
76+
{ name: 'wallets', type: 'address[]' },
77+
],
78+
},
79+
});
80+
81+
const account = {};
82+
83+
const result = await provider.signTypedData([account, msgParams]);
84+
85+
t.assert(result != null);
86+
});

0 commit comments

Comments
 (0)