Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ready for publish #3

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
db9517f
feat: init WIPs
devchenyan Aug 9, 2023
322e7ab
init ux protocol
poor-defined Aug 9, 2023
b6411ae
Update 0046-walletconnect-namespaces.md
devchenyan Aug 9, 2023
54abeba
feat: namepsaces
devchenyan Aug 11, 2023
e4cfb6a
update
devchenyan Aug 11, 2023
a28abd3
Update 0046-walletconnect-namespaces.md
devchenyan Aug 11, 2023
4e5fc7c
Update Reference-level-explanation.md
devchenyan Aug 11, 2023
267d283
feat: sdk
devchenyan Aug 11, 2023
d7783da
Merge branch 'feat-sdk' of github.com:devchenyan/WIPs into feat-sdk
devchenyan Aug 11, 2023
70100c2
update
devchenyan Aug 11, 2023
0a89b33
Update ckb-walletconnect-sdk.md
devchenyan Aug 11, 2023
3871b0b
Update ckb-walletconnect-sdk.md
devchenyan Aug 11, 2023
04f7b8f
Update 0046-walletconnect-namespaces.md
devchenyan Aug 11, 2023
b46e00c
Update 0046-walletconnect-namespaces.md
devchenyan Aug 14, 2023
eb25284
Merge remote-tracking branch 'refs/remotes/origin/develop' into develop
poor-defined Aug 16, 2023
5785997
init ux protocol doc
poor-defined Aug 16, 2023
2d0272d
Merge remote-tracking branch 'origin/feat-sdk' into develop
devchenyan Aug 16, 2023
154d953
Delete .gitkeep
devchenyan Aug 16, 2023
e380ec2
modify the Notes of Asset Amounts and adjust the prototype
poor-defined Aug 16, 2023
fe2581d
Merge branch 'develop' of github.com:Magickbase/WIPs into develop
poor-defined Aug 16, 2023
c32e026
Update ux-protocol.md
poor-defined Aug 16, 2023
c2f593e
Update ux-protocol.md
poor-defined Aug 16, 2023
afbb36f
fix
devchenyan Aug 17, 2023
4c9a665
Merge branch 'develop' of github.com:Magickbase/WIPs into develop
devchenyan Aug 17, 2023
cb23c23
docs: update 0046-walletconnect-namespaces.md
Keith-CY Aug 18, 2023
ea10b12
Merge pull request #1 from Magickbase/update-walletconnect-namespace
devchenyan Aug 18, 2023
8b14591
Merge branch 'feat-sdk' into develop
devchenyan Aug 18, 2023
c94d80b
fix
devchenyan Aug 18, 2023
0f2898a
fix
devchenyan Aug 18, 2023
83a8330
feat: script_bases
devchenyan Aug 22, 2023
ca4e2d4
update
devchenyan Aug 22, 2023
770b792
Rename 0046-walletconnect-namespaces.md to 0047-walletconnect-namespa…
Keith-CY Aug 22, 2023
6119753
Update 0047-walletconnect-namespaces.md
Keith-CY Aug 22, 2023
8957968
fix: txCount
devchenyan Aug 23, 2023
ef4bcc8
feat: remove type
devchenyan Aug 23, 2023
a4cad67
feat: update
devchenyan Oct 16, 2023
59f4a0e
Merge pull request #4 from Magickbase/feat-sdk
devchenyan Oct 16, 2023
616af0c
fix
devchenyan Oct 23, 2023
8dfa935
Merge branch 'feat-sdk' into develop
devchenyan Oct 23, 2023
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
Empty file added CHANGELOG.md
Empty file.
248 changes: 248 additions & 0 deletions rfc/0046-walletconnect-namespaces/0047-walletconnect-namespaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
---
Number: "0047"
Category: Standards Track
Status: Proposal
Author: [email protected]
Created: 2022-08-08
---

# WalletConnect Namespaces Protocol

## Abstract

This RFC describes a namespaces protocol which is a standardized object defined by the [Chain Agnostic Improvement Proposal (CAIP)](https://github.com/ChainAgnostic/CAIPs) that ensures a common industry standard for chain agnostic purposes.

## Motivation

WalletConnect is an open-source protocol that enables secure and seamless communication between decentralized applications (dApps) and wallets on various blockchains. By establishing a remote connection using end-to-end encryption, WalletConnect allows users to interact with dApps through their preferred wallet without exposing their private keys.

Users will encounter two namespaces: the proposal namespace and the session namespace when connecting wallets and dApps. Upon approval, the wallet will then send a session namespace that includes all the accounts, chains, methods, and events it has approved.

## Specification

Here is an example of a session approval message passing the namespace.

```
{
...
"namespaces": {
"ckb": {
"chains": [ "ckb:mainnet", ... ],
"accounts": [ "ckb:mainnet:${account_id}" ],
"methods": [ "ckb_signTransaction", ... ],
"events": [ "accountChanged", ... ],
}
},
"sessionProperties": {
"scriptBases": "<script_base a>,<script_base b>",
},
...
}
```

### chains

A general blockchain identification schema has been defined in [CAIP-2](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md). Its implementation for the CKB blockchain is as stated below

| Component | Description |
| ------------------- | --------------------------------- |
| caip2-like chain_id | namespace + : + chain_reference |
| namespace | ckb |
| chain_reference | One of (mainnet, testnet, devnet) |

### accounts

> CAIP-10 defines a way to identify an account in any blockchain specified by CAIP-2 blockchain id.

For context, see the [CAIP-10](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md) specification.

| Component | Description |
| ---------------------- | ------------------------------------------------ |
| caip10-like account_id | namespace + : + chain_reference + : + identity |
| namespace | ckb |
| chain_id | One of (mainnet, testnet, devnet) |
| identity | The hash obtained by the first pk of the account |

### methods

#### ckb_getAddresses

Get the Address[^1] list by specific lock script base[^2], in the format of `<code_hash>:<hash_type>`.

- Parameters

```ts
{
[<script_base>] :{
page: {
size: number // the size of address list to return
before: string // used as the end point of the returned address list(excluded)
after: string // used as the start point of the returned address(excluded)
},
type: 'generate' | 'all' // set 'generate' to generate new addresses if necessary; set 'all' to get existent addresses
}
}
```

- Returns

```ts
{
'<script_base x>' : Address[],
'<script_base y>' : Address[],
}
```

#### ckb_signTransaction

Get a Transaction[^3] over the provided instructions.

- Parameters

```ts
{
transaction: Transaction
actionType: 'sign' | 'signAndSend'
description: string
}
```

- Returns

```ts
{
transaction?: SignedTransaction
hash?: string
}
```

#### ckb_signMessage

Get a signature for the provided message from the specified signer address.

- Parameters

```ts
{
message: string, // the message to sign
address: string // address of which private to sign
}
```

- Returns

```ts
{
signature: string
}
```

### events

#### accountChanged

Emit the event when the account changed

```ts
{
name: "accountChanged",
data: string
}
```

#### addressesChanged

Emit the event when addresses changed

```ts
{
name: "addressesChanged",
data: {
addresses: Address[],
changeType: 'add' | 'consume' // add: new addresses created; consume: addresses consumed
}
}
```

### compound types

#### Address

```ts
interface Address {
address: string
identifier: string
description: string
balance: string
index: number
}
```

#### Transaction

```ts
interface Transaction {
cellDeps: {
outPoint: {
txHash: string;
index: string;
};
depType: string;
}[];
headerDeps: string[];
inputs: {
previousOutput: {
txHash: string;
index: string;
};
since: string;
capacity: string;
lock: {
args: string;
codeHash: string;
hashType: 'type' | 'data';
};
lockHash: string;
}[];
outputs: {
capacity: string;
lock: {
args: string;
codeHash: string;
hashType: 'type' | 'data';
};
type: {
args: string;
codeHash: string;
hashType: 'type' | 'data';
};
}[];
outputsData: string[];
description: string;
[key: string]: any;
}
```

#### SignedTransaction

```ts
interface interface SignedTransaction {
transaction: Transaction;
signatures: {
[hash: string]: string[];
};
description: string;
[key: string]: any;
}
```

## Further reading

1. [Reference-level explanation](./Reference-level-explanation.md)
2. Namespaces https://docs.walletconnect.com/2.0/specs/clients/sign/namespaces

## Refs

[^1]: Address: a compound type of CKB address, defined as [Address](#address);
[^2]: Script Base: It's the combination of `code_hash` and `hash_type` of a specific `script` in the format `<code_hash>:<hash_type>`. Without a concrete `args` of the `script`, the `script base` refers to the set of an abstract script. The relation between `script base` and `script` can be considered as `class` and `instance`;
[^3]: Transaction: a compound type of CKB transaction, defined as [Transaction](#transaction).
Loading