add a bunch of examples

This commit is contained in:
2022-11-23 18:19:23 -07:00
parent 4888d75134
commit b9b06436af
+80 -19
View File
@@ -206,7 +206,7 @@ export {
RpcResp_W2A_tx_sign_noprop, RpcResp_W2A_tx_sign_noprop,
EventData_A2W_tx_sign_noprop, EventData_A2W_tx_sign_noprop,
EventData_W2A_tx_sign_noprop EventData_W2A_tx_sign_noprop
// transaction.sign (do not propagate) // message.sign
Params_A2W_msg_sign, Params_A2W_msg_sign,
Result_W2A_msg_sign, Result_W2A_msg_sign,
RpcCall_A2W_msg_sign, RpcCall_A2W_msg_sign,
@@ -216,6 +216,8 @@ export {
}; };
// TODO: Give examples for everything
// TODO: Add back in transaction.sign and propagate
//============================================================================= //=============================================================================
// LAYER 2: WHO IS THIS MESSAGE FOR // LAYER 2: WHO IS THIS MESSAGE FOR
@@ -227,6 +229,19 @@ export {
/** /**
* This is the data that is sent from the wallet to the aepp through the Event * This is the data that is sent from the wallet to the aepp through the Event
* bus * bus
*
* @example
*
* ```ts
* {type : "to_aepp",
* data : {jsonrpc : "2.0",
* method : "connection.announcePresence",
* params : {id : "{aee9e933-52b6-410a-8c3f-99c6be596b4e}",
* name : "Superhero",
* networkId : "ae_mainnet",
* origin : "moz-extension://ee425d81-d5b2-44b6-9406-4da31b019e7c",
* type : "extension"}}}
* ```
*/ */
type EventData_W2A type EventData_W2A
<t extends any> <t extends any>
@@ -234,9 +249,20 @@ type EventData_W2A
data : t}; data : t};
/** /**
* This is the data that is sent from the aepp to the wallet through the Event * This is the data that is sent from the aepp to the wallet through the Event
* bus * bus
*
* @example
* ```ts
* {type : "to_waellet",
* data : {jsonrpc : "2.0",
* id : "ske-connect-1",
* method : "connection.open",
* params : {name : "sidekick examples",
* version : 1}}}
* ```
*/ */
type EventData_A2W type EventData_A2W
<t extends any> <t extends any>
@@ -245,7 +271,6 @@ type EventData_A2W
//============================================================================= //=============================================================================
// LAYER 3: JSON RPC 2.0 // LAYER 3: JSON RPC 2.0
// //
@@ -325,6 +350,8 @@ const ERROR_CODE_RpcPermissionDenyError = 11;
/** /**
* This is the general "something went wrong, i dunno" negative error. * This is the general "something went wrong, i dunno" negative error.
* *
* `const ERROR_CODE_RpcInternalError = 12;`
*
* See https://github.com/aeternity/aepp-sdk-js/blob/1065da9a46b8dbfe60a2c3e5646e7422ee7e495e/src/aepp-wallet-communication/schema.ts#L196-L209 * See https://github.com/aeternity/aepp-sdk-js/blob/1065da9a46b8dbfe60a2c3e5646e7422ee7e495e/src/aepp-wallet-communication/schema.ts#L196-L209
*/ */
const ERROR_CODE_RpcInternalError = 12; const ERROR_CODE_RpcInternalError = 12;
@@ -333,13 +360,22 @@ const ERROR_CODE_RpcInternalError = 12;
/** /**
* This is presumably the equivalent of the HTTP 404 error * This is presumably the equivalent of the HTTP 404 error
* *
* `const ERROR_CODE_RpcMethodNotFoundError = -32601;`
*
* See https://github.com/aeternity/aepp-sdk-js/blob/1065da9a46b8dbfe60a2c3e5646e7422ee7e495e/src/aepp-wallet-communication/schema.ts#L211-L224 * See https://github.com/aeternity/aepp-sdk-js/blob/1065da9a46b8dbfe60a2c3e5646e7422ee7e495e/src/aepp-wallet-communication/schema.ts#L211-L224
*/ */
const ERROR_CODE_RpcMethodNotFoundError = -32601; const ERROR_CODE_RpcMethodNotFoundError = -32601;
/** /**
* Error data inside the `error` field of a RpcResp_Err * Error data inside the `error` field of a `RpcResp_Err`
*
* @example
* ```ts
* {code : 4,
* data : {},
* message : "Operation rejected by user"}
* ```
*/ */
type RpcError type RpcError
= {code : number, = {code : number,
@@ -357,6 +393,17 @@ type RpcError
* This type is used for "notifications", i.e. messages sent from the client to * This type is used for "notifications", i.e. messages sent from the client to
* the server that do not need a response. An example is the wallet announcing * the server that do not need a response. An example is the wallet announcing
* it exists. * it exists.
*
* @example
* ```ts
* {jsonrpc : "2.0",
* method : "connection.announcePresence",
* params : {id : "{aee9e933-52b6-410a-8c3f-99c6be596b4e}",
* name : "Superhero",
* networkId : "ae_mainnet",
* origin : "moz-extension://ee425d81-d5b2-44b6-9406-4da31b019e7c",
* type : "extension"}}
* ```
*/ */
type RpcCast type RpcCast
<method_s extends string, <method_s extends string,
@@ -451,10 +498,20 @@ type RpcResp_Any = RpcResp<string, any>;
* Waellet-to-aepp parameters of "connection.announcePresence" cast * Waellet-to-aepp parameters of "connection.announcePresence" cast
* *
* (layer 4) * (layer 4)
*
* @example
* ```ts
* {id : "{aee9e933-52b6-410a-8c3f-99c6be596b4e}",
* name : "Superhero",
* networkId : "ae_uat",
* origin : "moz-extension://ee425d81-d5b2-44b6-9406-4da31b019e7c",
* type : "extension"}
* ```
*/ */
type Params_W2A_connection_announcePresence type Params_W2A_connection_announcePresence
= {id : string, = {id : string,
name : string, name : string,
networkId : string,
origin : string, origin : string,
type : "window" | "extension"}; type : "window" | "extension"};
@@ -464,6 +521,17 @@ type Params_W2A_connection_announcePresence
* Shape of the waellet-to-aepp "connection.announcePresence" RPC cast * Shape of the waellet-to-aepp "connection.announcePresence" RPC cast
* *
* (layer 3) * (layer 3)
*
* @example
* ```ts
* {jsonrpc : "2.0",
* method : "connection.announcePresence",
* params : {id : "{aee9e933-52b6-410a-8c3f-99c6be596b4e}",
* name : "Superhero",
* networkId : "ae_mainnet",
* origin : "moz-extension://ee425d81-d5b2-44b6-9406-4da31b019e7c",
* type : "extension"}}
* ```
*/ */
type RpcCast_W2A_connection_announcePresence type RpcCast_W2A_connection_announcePresence
= RpcCast<"connection.announcePresence", = RpcCast<"connection.announcePresence",
@@ -476,22 +544,15 @@ type RpcCast_W2A_connection_announcePresence
* (layer 2) * (layer 2)
* *
* @example * @example
* * ```ts
* ```json * {type: "to_aepp",
* { * data: {jsonrpc: "2.0",
* "type": "to_aepp", * method: "connection.announcePresence",
* "data": { * params: {id : "{aee9e933-52b6-410a-8c3f-99c6be596b4e}",
* "jsonrpc": "2.0", * name : "Superhero",
* "method": "connection.announcePresence", * networkId : "ae_mainnet",
* "params": { * origin : "moz-extension://ee425d81-d5b2-44b6-9406-4da31b019e7c",
* "id": "{aee9e933-52b6-410a-8c3f-99c6be596b4e}", * type : "extension"}}}
* "name": "Superhero",
* "networkId": "ae_mainnet",
* "origin": "moz-extension://ee425d81-d5b2-44b6-9406-4da31b019e7c",
* "type": "extension"
* }
* }
* }
* ``` * ```
*/ */
type EventData_W2A_connection_announcePresence type EventData_W2A_connection_announcePresence