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

SIP-030: Wallet RPC Standards #166

Open
wants to merge 49 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
9b2cbd7
feat: add wallet api sip
janniks Jan 12, 2024
7278192
fix: add note on namespaces
janniks Jan 12, 2024
ad07fd0
fix: update tx results
janniks Jan 30, 2024
4ad74cd
chore: minor updates
janniks Jan 30, 2024
6584e3a
chore: add open questions
janniks Feb 14, 2024
c3d503f
fix: update address and account methods
janniks Feb 15, 2024
d5375e6
chore: update sip
janniks Feb 15, 2024
425f81c
docs: add new js representation
janniks Feb 29, 2024
a32fb11
docs: update methods
janniks Mar 5, 2024
2e74745
docs: update open questions
janniks Mar 5, 2024
1468025
fix: typo
janniks Mar 15, 2024
fe54791
fix: typo
janniks Mar 15, 2024
560cffd
docs: update sip
janniks Mar 26, 2024
22bfbcc
docs: update sip
janniks Mar 26, 2024
46bc249
chore: add comment
janniks Mar 26, 2024
e90bd19
chore: address pr comments
janniks Mar 26, 2024
c15ed40
chore: update authors
janniks Mar 26, 2024
09f5503
chore: update
janniks Mar 26, 2024
f8f841a
chore: add wbip links
janniks Apr 3, 2024
1b79cac
chore: add open question
janniks Apr 3, 2024
33701fb
fix: pr comment changes
janniks Apr 24, 2024
78d21f4
fix: add origin post conditions
janniks Jul 30, 2024
cb10455
chore: rename to 30
janniks Oct 23, 2024
d5de192
chore: update from pr review
janniks Nov 5, 2024
537d9a1
chore: add pr feedback
janniks Nov 5, 2024
b1e9b01
chore: add pr feedback
janniks Nov 5, 2024
c02be3f
chore: update sip
janniks Nov 20, 2024
cd86682
chore: update sip
janniks Nov 20, 2024
8f1c99d
chore: pr feedback
janniks Nov 21, 2024
ecb0e7c
chore: add more references
janniks Nov 21, 2024
6ed5cd7
chore: add wallet standard
janniks Nov 21, 2024
fb6ce09
chore: pr feedback
janniks Nov 21, 2024
51c3eb7
chore: pr feedback
janniks Nov 21, 2024
b9421a2
chore: pr feedback
janniks Nov 21, 2024
93eee63
chore: pr feedback
janniks Nov 21, 2024
f026526
chore: pr feedback
janniks Nov 21, 2024
8f5d316
chore: pr feedback
janniks Nov 21, 2024
6d1c101
chore: pr feedback
janniks Nov 21, 2024
df7d302
fix: update sip properties
janniks Jan 14, 2025
9121864
fix: fix sip number reference
janniks Jan 16, 2025
5b54749
chore: add more details on the scope of the specification
janniks Jan 16, 2025
61f5cda
chore: update network functions
janniks Jan 16, 2025
7b375fe
chore: mention clarity value type
janniks Jan 16, 2025
87afbb2
chore: add auth to related work
janniks Jan 16, 2025
e963f95
chore: udpate activation phrasing
janniks Jan 16, 2025
47096d8
chore: mention sbtc
janniks Jan 16, 2025
f270d4a
chore: add note on type definitions
janniks Jan 22, 2025
15647a8
chore: add broadcast
janniks Jan 22, 2025
8af7c39
chore: add broadcast common note
janniks Jan 28, 2025
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
284 changes: 256 additions & 28 deletions sips/sip-02X/sip-02X-wallet-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ License: BSD 2-Clause

<!-- todo: remove section before merge -->

- [ ] Should post-condition `type` be called `condition` or something (future overlap with clarity value?) or something else. Suffix `-condition`?
- [ ] Should we add `stx_transferFt` and `stx_transferNft`?
- [ ] Should `sender` in the params be renamed to `address`/`account`, or stay `sender for added clarity VS recipient/etc.?
- [ ] Should Clarity values and maybe other types be hex-encoded, or is there a better idea that has similar benefits (no dependencies, but is easier to work with)?
- [x] Change sender to `address`~~/`account`, or stay `sender for added clarity VS recipient/etc.?~~
- [x] Should Clarity values and maybe other types be hex-encoded, or is there a better idea that has similar benefits (no dependencies, but is easier to work with)?
- For Clarity values, we could use strings (e.g. `u123`, `"text"`, `0x4be9`, `{ key: u3 }`) and parse the Clarity expression in the wallet. The only downside (I can think of) -- apart from additional wallet dev cost -- is cases like strings which need quotes, but this might not be clear to the user. A function/library for this would be provided by Stacks.js.

# Abstract
Expand Down Expand Up @@ -83,23 +84,21 @@ Methods can be namespaced under `stx_` if used in settings like WebBTC (see WBIP
In other cases (e.g. WalletConnect), the namespace may already be given by meta-data (e.g. a `chainId` field) and can be omitted.
On the predominant `StacksProvider` global object, the methods can be used without a namespace, but wallets may add namespaced aliases for convenience.

### Method Independent

#### Common Definitions
#### Common definitions

The following definitions can be used in multiple methods (mainly for transfer and transaction methods).

`params`

- `address?`: `string` address, Stacks c32-encoded, defaults to wallets current address
- `network?`: `'mainnet' | 'testnet' | 'regtest' | 'mocknet'`
- `fee?`: `number | string` (anything parseable by the BigInt constructor)
- `nonce?`: `number | string` (anything parseable by the BigInt constructor)
- `attachment?`: `string` hex-encoded
- `anchoreMode?`: `'onChainOnly' | 'offChainOnly' | 'any'`
- `postConditionMode?`: `'allow' | 'deny'`
- `anchorMode?`: `'on-chain' | 'off-chain' | 'any'`
- `postConditions?`: `PostCondition[]`, defaults to `[]`
janniks marked this conversation as resolved.
Show resolved Hide resolved
- `postConditionMode?`: `'allow' | 'deny'`
- `sponsored?`: `boolean`, defaults to `false`
- `address?`: `string` address, Stacks c32-encoded (sender or signer address), defaults to wallets current address
- ~~`appDetails`~~ _removed_
- ~~`onFinish`~~ _removed_
- ~~`onCancel`~~ _removed_
Expand All @@ -108,7 +107,9 @@ The following definitions can be used in multiple methods (mainly for transfer a

- `PostCondition`: `string` hex-encoded

### `stx_transferStx`
---

### Method `stx_transferStx`

`params`

Expand All @@ -121,22 +122,21 @@ The following definitions can be used in multiple methods (mainly for transfer a
- `txid`: `string` hex-encoded
janniks marked this conversation as resolved.
Show resolved Hide resolved
- `transaction`: `string` hex-encoded

### `stx_transferFt`
### Method `stx_transferFt`

`todo: haven't existed yet, should we add them?`

### `stx_transferNft`
### Method `stx_transferNft`

`todo: haven't existed yet, should we add them?`

### `stx_contractCall`
### Method `stx_callContract`

`params`

- `contractAddress`: `string` address, Stacks c32-encoded
- `contractName`: `string`
- `functionName`: `string`
- `functionArgs`: `ClarityValue[]`, defaults to `[]`
- `contract`: `string.string` address with contract name suffix, Stacks c32-encoded
- `function`: `string`
janniks marked this conversation as resolved.
Show resolved Hide resolved
- `arguments`: `ClarityValue[]`, defaults to `[]`

`where`

Expand All @@ -147,20 +147,20 @@ The following definitions can be used in multiple methods (mainly for transfer a
- `txid`: `string` hex-encoded
- `transaction`: `string` hex-encoded

### `stx_contractDeploy`
### Method `stx_deployContract`

`params`

- `contractName`: `string`
- `codeBody`: `string` Clarity contract code
- `name`: `string`
- `clarityCode`: `string` Clarity contract code
- `clarityVersion?`: `number`
janniks marked this conversation as resolved.
Show resolved Hide resolved

`result`

- `txid`: `string` hex-encoded
- `transaction`: `string` hex-encoded

### `stx_signTransaction`
### Method `stx_signTransaction`

`params`

Expand All @@ -170,7 +170,7 @@ The following definitions can be used in multiple methods (mainly for transfer a

- `transaction`: `string` hex-encoded (signed)

### `stx_signMessage`
### Method `stx_signMessage`

`params`

Expand All @@ -181,24 +181,27 @@ The following definitions can be used in multiple methods (mainly for transfer a
- `signature`: `string` hex-encoded
- `publicKey`: `string` hex-encoded

### `stx_signStructuredMessage`
### Method `stx_signStructuredMessage`

`params`

- `message`: `string` Clarity value, hex-encoded
- `domain?`: `string` hex-encoded (defined by SIP-018)
- `domain`: `string` hex-encoded (defined by SIP-018)

`result`

> `domain` can be optional if the wallet (e.g. browser extension) can infer it from the origin of the request.
- `signature`: `string` hex-encoded
- `publicKey`: `string` hex-encoded

### `stx_getAddresses`
### Method `stx_getAddresses`

`result`

- `addresses`: `{}[]`
- `address`: `string` address, Stacks c32-encoded
- `publicKey`: `string` hex-encoded

### `stx_getAccounts`
### Method `stx_getAccounts`

`result`

Expand All @@ -208,7 +211,7 @@ The following definitions can be used in multiple methods (mainly for transfer a
- `gaiaHubUrl`: `string` URL
- `gaiaAppKey`: `string` hex-encoded

### `stx_updateProfile`
### Method `stx_updateProfile`

`params`

Expand All @@ -218,7 +221,232 @@ The following definitions can be used in multiple methods (mainly for transfer a

- `profile`: `object` updated Schema.org Person object

## Provider Registration
## JS Representations
janniks marked this conversation as resolved.
Show resolved Hide resolved

While discussing this SIP, it has become clear that the current Stacks.js representation is confusing to developers.
Rather, a better solution would be human-readable — for example, rely on string literal enumeration, rather than magic values, which need additional lookups.
Relying on soley a hex-encoded also poses difficulties when building Stacks enabled web applications.

### Clarity values

Proposed below is an updated interface representation for Clarity primitives for use in Stacks.js and JSON compatible environments.

> For encoding larger than JS `Number` big integers, `string` is used.

`0x00` `int`

```ts
{
type: "int",
value: string // `bigint` compatible
}
```

`0x01` `uint`

```ts
{
type: "uint",
value: string // `bigint` compatible
}
```

`0x02` `buffer`

```ts
{
type: "buffer",
value: string // hex-encoded string
}
```

`0x03` `bool` `true`

```ts
{
type: "true",
}
```

`0x04` `bool` `false`

```ts
{
type: "false",
}
```

`0x05` `address` (aka "standard principal")

```ts
{
type: "address",
value: string // Stacks c32-encoded
}
```

`0x06` `contract` (aka "contract principal")

```ts
{
type: "contract",
value: `${string}.${string}` // Stacks c32-encoded, with contract name suffix
}
```

`0x07` `ok` (aka "response ok")

```ts
{
type: "ok",
value: object // Clarity value
}
```

`0x08` `err` (aka "response err")

```ts
{
type: "err",
value: object // Clarity value
}
```

`0x09` `none` (aka "optional none")

```ts
{
type: "none",
}
```

`0x0a` `some` (aka "optional some")

```ts
{
type: "some",
value: object // Clarity value
}
```

`0x0b` `list`

```ts
{
type: "list",
value: object[] // Array of Clarity values
}
```

`0x0c` `tuple`

```ts
{
type: "tuple",
value: Record<string, object> // Record of Clarity values
}
```

`0x0d` `ascii`

```ts
{
type: "ascii",
value: string // ASCII-compatible string
}
```

`0x0e` `utf8`

```ts
{
type: "utf8",
value: string
}
```

### Post conditions

`0x00` STX

```ts
{
type: 'stx',
address: string | `${string}.${string}`, // Stacks c32-encoded, with optional contract name suffix
condition: 'eq' | 'gt' | 'gte' | 'lt' | 'lte',
amount: string // `bigint` compatible, amount in mirco-STX
}
```

`0x01` Fungible token

```ts
{
type: 'ft',
address: string | `${string}.${string}`, // Stacks c32-encoded, with optional contract name suffix
condition: 'eq' | 'gt' | 'gte' | 'lt' | 'lte',
asset: `${string}.${string}::${string}` // Stacks c32-encoded address, with contract name suffix, with asset suffix
amount: string // `bigint` compatible, amount in lowest integer denomination of fungible token
}
```

`0x02` Non-fungible token

```ts
{
type: 'nft',
address: string | `${string}.${string}`, // Stacks c32-encoded, with optional contract name suffix
condition: 'sent' | 'not-sent',
asset: `${string}.${string}::${string}` // address with contract name suffix with asset suffix, Stacks c32-encoded
assetId: object, // Clarity value
}
```

### Test vectors

Listed below are some examples of the potentially unclear representations:

- `u12` = `{ type: 'uint', value: "12" }`
- `0xbeaf` = `{ type: 'ascii', value: "hello there" }`
- `"hello there"` = `{ type: 'ascii', value: "hello there" }`
- `(list 4 8)` =
```
{
type: 'list',
value: [
{ type: 'int', value: "4"},
{ type: 'int', value: "8"},
]
}
```
- `(err u4)` =
```
{
type: 'err',
value: { type: 'uint', value: "4"},
}
```
- "sends more than 10000 uSTX" =
```
{
type: 'stx',
address: 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6',
amount: '10000',
condition: 'gt'
}
```
- "does not send the `12` TKN non-fungible token" =
```
{
type: 'ntf',
address: 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6.vault'
asset: 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6.tokencoin::tkn',
assetId: { type: 'uint', value: '12' }
condition: 'not-sent'
}
```

## Provider registration

Wallets can register their aliased provider objects according to WBIP-004.

Expand Down