Skip to content

Commit

Permalink
Merge pull request ethereum#49 from Keeper-Wallet/waves
Browse files Browse the repository at this point in the history
Add Waves namespace
  • Loading branch information
Bumblefudge authored Feb 2, 2023
2 parents c44e5b1 + d7e9951 commit 1610259
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 0 deletions.
24 changes: 24 additions & 0 deletions waves/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
namespace-identifier: waves
title: Waves Ecosystem
author: Maxim Smolyakov (@msmolyakov), Yury Sidorov (@darksyd94)
status: Draft
type: Informational
created: 2023-01-19
requires: ["CAIP-2", "CAIP-10", "CAIP-19"]
---

# Namespace for Waves Blockchains

This document defines the applicability of CAIP schemes to the blockchains of
the Waves ecosystem.

## References

- [Official website](https://waves.tech)
- [Waves Documentation](https://docs.waves.tech)
- [Waves Developer Portal](https://dev.waves.tech)

## Copyright

Copyright and related rights waived via CC0.
74 changes: 74 additions & 0 deletions waves/caip-10.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
namespace-identifier: waves-caip10
title: Waves Namespace - Addresses
author: Maxim Smolyakov (@msmolyakov), Yury Sidorov (@darksyd94)
discussions-to:
status: Draft
type: Standard
created: 2023-01-19
requires: ["CAIP-2", "CAIP-10"]
---

# CAIP-10

*For context, see the [CAIP-10][] specification.*

## Rationale

Waves "account" has a public key that is the same for any Waves blockchain.

But Waves "address" is 26 byte array derived from public key and represented as Base58 encoded string.

Waves "address" can change depending on chain ID. It prevents unintentional transfers on other Waves blockchains. Address also contains checksum, which protects against typos and copying errors of the address.

## Syntax

The syntax of Waves addresses:

```
caip10-like address: namespace + ":" chainId + ":" + address
namespace: waves
chain Id: [-128..127] value. If the value is shorter than 3 characters, then must be padded with leading zeros to 3 characters
address: Waves address represented as Base58 encoded string
```

Waves address is byte array of `Entity type + Chain ID + Account public key hash + Checksum`, where:
1. `Entity type` — always 1-byte integer with value `1`
2. `Chain ID` — 1-byte integer of current blockchain ID
3. `Account public key hash` — first 20 bytes of the result of `keccak256(publicKey)` hashing function
4. `Checksum` — first 4 bytes of the result of `keccak256(Entity type + Chain ID + Account public key hash)` hashing function

### Resolution method

To derive an address from public key, make a GET HTTP request `/addresses/publicKey/{publicKey}` to the blockchain node, for example: https://nodes-testnet.wavesnodes.com/addresses/publicKey/7Y5rWP1aB1iGkDer8cS9TasAv1HpvCMZiZ2C9KLema6 \
Thus, the node will return in response an address of the account with the public key for the current blockchain, for example:

```json
{
"address": "3NBNV8hiq8DTVF7UmzFLSUwud3h3pKZkVB3"
}
```

## Test Cases

```
# Public Key:
# 7Y5rWP1aB1iGkDer8cS9TasAv1HpvCMZiZ2C9KLema6
# Waves Mainnet
waves:087:3PPPJ62chFkr7hQu34WLPwKiywCpeSbfap7
# Waves Testnet
waves:084:3NBNV8hiq8DTVF7UmzFLSUwud3h3pKZkVB3
# Waves custom network with negative Chain ID
waves:-07:3NBNV8hiq8DTVF7UmzFLSUwud3h3pKZkVB3
```

## Links

- [About addresses in Waves Documentation](https://docs.waves.tech/en/blockchain/account/address)

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
54 changes: 54 additions & 0 deletions waves/caip-19.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
namespace-identifier: waves-caip19
title: Waves Namespace - Assets
author: Maxim Smolyakov (@msmolyakov), Yury Sidorov (@darksyd94)
discussions-to:
status: Draft
type: Standard
created: 2023-01-19
---

## Rationale

Any account can issue its own token. The new token is immediately available.

ID format of fungible and non-fungible tokens is the same.

Process of issuing is also the same. The only difference is that NFTs must have specific values for certain properties.

## Specification of Asset ID

Asset ID is a 32 byte array encoded as Base58 string. It's usually equal to ID of the transaction that issued this asset (except when the token is issued using a dApp contract, but in this case the Asset ID format is always the same). This is true for both fungible and non-fungible tokens.

## Syntax

The syntax of Waves Asset ID:

```
caip10-like asset id: namespace + ":" chainId + ":" + assetId
namespace: waves
chain Id: [-128..127] value. If the value is shorter than 3 characters, then must be padded with leading zeros to 3 characters
assetId: Waves Asset ID represented as Base58 encoded string
```

## Examples

```
# Waves Mainnet
waves:087:DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p
# Waves Testnet
waves:084:2HAJrwa8q4SxBx9cHYaBTQdBjdk5wwqdof7ccpAx2uhZ
# Waves custom network with negative Chain ID
waves:-07:2HAJrwa8q4SxBx9cHYaBTQdBjdk5wwqdof7ccpAx2uhZ
```

## Links

- [Token](https://docs.waves.tech/en/blockchain/token)
- [Token ID](https://docs.waves.tech/en/blockchain/token/token-id)

## Copyright

Copyright and related rights waived via [CC0](../LICENSE).
99 changes: 99 additions & 0 deletions waves/caip-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
caip: 2
title: Waves Blockchain ID Specification
author: Maxim Smolyakov (@msmolyakov), Yury Sidorov (@darksyd94)
discussions-to:
status: Draft
type: Standard
created: 2023-01-19
---

## Abstract

In CAIP-2 a general blockchain identification scheme is defined. This is the implementation of CAIP-2 for Waves network.

## Specification

### Syntax

Blockchains in the "waves" namespace are identified by their chain ID.

Chain ID format is a signed integer in decimal representation. The signed integer is represented as a one-byte signed integer in the range [-128..127].

```
chain_id: namespace + ":" + reference
namespace: waves
reference: integer in the range [-128..127]. If the value is shorter than 3 characters, then must be padded with leading zeros to 3 characters
```

### Resolution method

There is no in-protocol resolution method at present. But there is a solution for some cases where it might be needed.

To resolve a blockchain reference for the Waves namespace, make a GET HTTP request `/addresses` to the blockchain node, for example: https://nodes-testnet.wavesnodes.com/addresses \
Thus, the node will return in response an array of its public blockchain addresses, for example:

```json
[
"3NA4UdyFVv7v1J6UgGe4moyHm2fambavqvm",
"3MvbutkV3xapQVUcGBGWCongwfdH8LKTm8w"
]
```

Decode any of them as Base58 string and take the second byte from the resulting array, for example (in pseudocode):

```java
byte getChainId(String address) {
byte[] decodedAddress = decodeBase58(address);
return decodedAddress[1];
}
```

This byte is the chain ID of the blockchain where this node is running.

## Rationale

The chain ID is specified as a one-byte signed integer.

For example, chain ID of Mainnet is 87 (ASCII code of "W").

There may also be other custom networks based on Waves, but with a different chain ID.

Chain ID is used in [binary format](https://docs.waves.tech/en/blockchain/binary-format/) of blockchain entities:
- [Block](https://docs.waves.tech/en/blockchain/binary-format/block-binary-format)
- [Transaction](https://docs.waves.tech/en/blockchain/binary-format/transaction-binary-format/)
- [Order](https://docs.waves.tech/en/blockchain/binary-format/order-binary-format)
- [Address](https://docs.waves.tech/en/blockchain/binary-format/address-binary-format)
- [Alias](https://docs.waves.tech/en/blockchain/binary-format/alias-binary-format)

Therefore, these entities cannot be used on another network with different chain ID.

## Test Cases

This is a list of manually composed examples

```
# Waves Mainnet
waves:087
# Waves Testnet
waves:084
# Waves Stagenet
waves:083
# Waves custom network used in the [private node Docker image](https://hub.docker.com/r/wavesplatform/waves-private-node)
waves:082
# Waves custom network with negative Chain ID
waves:-07:3NBNV8hiq8DTVF7UmzFLSUwud3h3pKZkVB3
```

## Links

- [About Chain ID in Waves Documentation](https://docs.waves.tech/en/blockchain/blockchain-network/#chain-id)
- [About binary format of blockchain entities](https://docs.waves.tech/en/blockchain/binary-format/)

## Copyright

Copyright and related rights waived via [CC0](../LICENSE).

0 comments on commit 1610259

Please sign in to comment.