Skip to content

Commit 0a4175c

Browse files
authored
Added Transport OpenRPC Document for the MultiChain API (#236)
* Added Transport OpenRPC Document for the MultiChain API * fix: rename transport to multichain * fix: add notifications and methods as required
1 parent 6d6ba82 commit 0a4175c

File tree

3 files changed

+194
-0
lines changed

3 files changed

+194
-0
lines changed

merge-openrpc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const mergeOpenRPC = require("./merge-utils");
44
const yaml = require("js-yaml");
55

66
const MetaMaskOpenRPC = yaml.load(fs.readFileSync(__dirname + "/openrpc.yaml", "utf8"));
7+
const TransportOpenRPC = yaml.load(fs.readFileSync(__dirname + "/multichain/openrpc.yaml", "utf8"));
78

89
const getFilteredExecutionAPIs = () => {
910
return fetch("https://raw.githubusercontent.com/ethereum/execution-apis/59e6a6f9947859e8bb41bc63b248aa026b0781bd/refs-openrpc.json")
@@ -32,6 +33,14 @@ getFilteredExecutionAPIs().then((EthereumOpenRPC) => {
3233
4
3334
)
3435
);
36+
fs.writeFileSync(__dirname + "/src/build/multichain-openrpc.json",
37+
JSON.stringify(
38+
TransportOpenRPC,
39+
null,
40+
4
41+
)
42+
);
43+
3544
});
3645

3746
const unneeded = [

multichain/openrpc.yaml

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
openrpc: 1.2.4
2+
info:
3+
title: MetaMask MultiChain API
4+
version: 1.0.0
5+
description: >-
6+
This provides the specs for the MultiChain API Layer for the MetaMask API
7+
methods:
8+
- name: "provider_authorize"
9+
paramStructure: "by-name"
10+
params:
11+
- name: "requiredScopes"
12+
description: "Scopes that the wallet must support in order to be used with this provider."
13+
schema:
14+
type: "object"
15+
patternProperties:
16+
"[-a-z0-9]{3,8}(:[-_a-zA-Z0-9]{1,32})?":
17+
$ref: "#/components/schemas/Scope"
18+
- name: "optionalScopes"
19+
description: "Scopes that the wallet may support in order to be used with this provider."
20+
schema:
21+
type: "object"
22+
patternProperties:
23+
"[-a-z0-9]{3,8}(:[-_a-zA-Z0-9]{1,32})?":
24+
$ref: "#/components/schemas/Scope"
25+
- name: "sessionProperties"
26+
description: "Properties that the wallet may use to determine if the session is valid."
27+
schema:
28+
type: "object"
29+
properties:
30+
expiry:
31+
type: "string"
32+
format: "date-time"
33+
result:
34+
name: "provider_authorizeResult"
35+
schema:
36+
type: "object"
37+
properties:
38+
sessionId:
39+
description: "A unique identifier for the session. Defined by [CAIP-171](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-171.md)"
40+
type: "string"
41+
sessionScopes:
42+
type: "object"
43+
patternProperties:
44+
"[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}":
45+
$ref: "#/components/schemas/Scope"
46+
sessionProperties:
47+
type: "object"
48+
properties:
49+
expiry:
50+
type: "string"
51+
format: "date-time"
52+
examples:
53+
- name: "provider_authorizeExample"
54+
description: "Example of a provider authorization request."
55+
params:
56+
- name: "requiredScopes"
57+
value:
58+
eip155:
59+
chains:
60+
- "eip155:1"
61+
- "eip155:137"
62+
methods:
63+
- "eth_sendTransaction"
64+
- "eth_getBalance"
65+
- "personal_sign"
66+
notifications:
67+
- "accountsChanged"
68+
- "chainChanged"
69+
"eip155:10":
70+
methods:
71+
- "eth_getBalance"
72+
notifications:
73+
- "accountsChanged"
74+
- "chainChanged"
75+
- name: "optionalScopes"
76+
value:
77+
"eip155:42161":
78+
methods:
79+
- "eth_sendTransaction"
80+
- "eth_getBalance"
81+
- "personal_sign"
82+
notifications:
83+
- "accountsChanged"
84+
- "chainChanged"
85+
- name: "sessionProperties"
86+
value:
87+
expiry: "2022-12-24T17:07:31+00:00"
88+
result:
89+
name: "provider_authorizationResultExample"
90+
value:
91+
sessionId: "0xdeadbeef"
92+
sessionScopes:
93+
eip155:
94+
chains:
95+
- "eip155:1"
96+
- "eip155:137"
97+
methods:
98+
- "eth_sendTransaction"
99+
- "eth_getBalance"
100+
- "personal_sign"
101+
notifications:
102+
- "accountsChanged"
103+
- "chainChanged"
104+
accounts:
105+
- "eip155:1:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb"
106+
- "eip155:137:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb"
107+
"eip155:10":
108+
methods:
109+
- "eth_getBalance"
110+
notifications:
111+
- "accountsChanged"
112+
- "chainChanged"
113+
accounts: []
114+
"eip155:42161":
115+
methods:
116+
- "personal_sign"
117+
notifications:
118+
- "accountsChanged"
119+
- "chainChanged"
120+
accounts:
121+
- "eip155:42161:0x0910e12C68d02B561a34569E1367c9AAb42bd810"
122+
cosmos: {}
123+
sessionProperties:
124+
expiry: "2022-11-31T17:07:31+00:00"
125+
errors:
126+
- code: 5000
127+
message: "User disapproved requested chains"
128+
- code: 5001
129+
message: "User disapproved requested methods"
130+
- code: 5002
131+
message: "User disapproved requested notifications"
132+
- code: 5100
133+
message: "Requested chains are not supported"
134+
- code: 5101
135+
message: "Requested methods are not supported"
136+
- code: 5102
137+
message: "Requested notifications are not supported"
138+
- code: 5103
139+
message: "Scope/chain mismatch"
140+
- code: 5104
141+
message: "ChainId defined in two different scopes"
142+
- code: 5200
143+
message: "Invalid Session Properties requested"
144+
- code: 5201
145+
message: "Session Properties can only be optional"
146+
components:
147+
schemas:
148+
Scope:
149+
type: "object"
150+
title: "Scope"
151+
description: "Scope for a multi-chain connection"
152+
additionalProperties: true
153+
required:
154+
- notifications
155+
- methods
156+
properties:
157+
chains:
158+
type: "array"
159+
items:
160+
type: "string"
161+
pattern: "[-a-z0-9]{3,8}(:[-_a-zA-Z0-9]{1,32})?"
162+
methods:
163+
description: "Methods that the wallet must support in order to be used with this provider."
164+
type: "array"
165+
items:
166+
type: "string"
167+
notifications:
168+
description: "notifications that the wallet must support in order to be used with this provider."
169+
type: "array"
170+
items:
171+
type: "string"
172+
rpcEndpoints:
173+
description: "JSON-RPC endpoints for this namespace."
174+
type: "array"
175+
items:
176+
type: "string"
177+
format: "uri"
178+
rpcDocuments:
179+
type: "array"
180+
description: "OpenRPC documents that define RPC methods in which to anchor the methods authorized in a CAIP-25 interaction."
181+
items:
182+
type: "string"
183+
format: "uri"

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
import MetaMaskOpenRPCDocument from "./build/openrpc.json";
2+
import MultiChainOpenRPCDocument from "./build/multichain-openrpc.json";
3+
export { MetaMaskOpenRPCDocument, MultiChainOpenRPCDocument };
24
export default MetaMaskOpenRPCDocument;

0 commit comments

Comments
 (0)