Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
Add validate address options (#804)
Browse files Browse the repository at this point in the history
* Add validate address options

I have added the 2 main tools that Parity has created to validate ss58 addresses. I also added a list of places for developers to look for some more code examples to use to create their own custom validation tools in various languages.

@joepetrowski @danforbes

* Fix line length

* Add validate address options

I have added the 2 main tools that Parity has created to validate ss58 addresses. I also added a list of places for developers to look for some more code examples to use to create their own custom validation tools in various languages.

@joepetrowski @danforbes

* Nitpicks

* Updated Terms of Use per Legal (#803)

* Updated Terms of Use per Legal

* Prettier

`npx prettier --write --print-width 100 ./website/pages/en/terms.js`

Co-authored-by: Dan Forbes <[email protected]>

* refining off-chain indexing (#800)

* refining off-chain indexing

* Update docs/knowledgebase/learn-substrate/off-chain-workers.md

Co-authored-by: Dan Forbes <[email protected]>

* Update docs/knowledgebase/learn-substrate/off-chain-workers.md

Co-authored-by: Dan Forbes <[email protected]>

* Expanded the section from off-chain-worker to off-chain-features

* Update docs/knowledgebase/learn-substrate/off-chain-features.md

Co-authored-by: Tomasz Drwięga <[email protected]>

* update on content to make it more coherent

* Fix link

* Links and nitpicks

* Prettier

Co-authored-by: Dan Forbes <[email protected]>
Co-authored-by: Tomasz Drwięga <[email protected]>
Co-authored-by: Dan Forbes <[email protected]>

* Bump ini from 1.3.5 to 1.3.7 in /website (#801)

Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.7.
- [Release notes](https://github.com/isaacs/ini/releases)
- [Commits](npm/ini@v1.3.5...v1.3.7)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jimmy Chu <[email protected]>

* Making most static strings in substrate.dev supporting multi-lingual (#802)

* adding <translate> tag for multi-lingual support

* Most strings are translatable now

* Minor fix of bash syntax in console output

* fixing spacing

* using relative link so multi-lingual option is kept between navigation

* cmd style in console output

* Indent all JS to use spacing for indentation

* Updated to latest libs

* Fix site internal links to respect multi-lingual.

* Add validate address options

I have added the 2 main tools that Parity has created to validate ss58 addresses. I also added a list of places for developers to look for some more code examples to use to create their own custom validation tools in various languages.

@joepetrowski @danforbes

* Fix line length

* Add validate address options

I have added the 2 main tools that Parity has created to validate ss58 addresses. I also added a list of places for developers to look for some more code examples to use to create their own custom validation tools in various languages.

@joepetrowski @danforbes

* Fix: Comment Edits

* Update docs/knowledgebase/advanced/ss58-address-format.md

Co-authored-by: joe petrowski <[email protected]>

* Update docs/knowledgebase/advanced/ss58-address-format.md

Co-authored-by: joe petrowski <[email protected]>

* Update docs/knowledgebase/advanced/ss58-address-format.md

Co-authored-by: joe petrowski <[email protected]>

* Update docs/knowledgebase/advanced/ss58-address-format.md

Co-authored-by: joe petrowski <[email protected]>

* Update docs/knowledgebase/advanced/ss58-address-format.md

Co-authored-by: joe petrowski <[email protected]>

* Review and edits for SS58 

General pruning to make text more succinct. Slight tweak on structure and linking to be more consistent with other KB articles. Added code comments too.

* Revert "Review and edits for SS58 "

This reverts commit 532d283.

* Apply uncontroversial suggestions from code review

Co-authored-by: sacha-l <[email protected]>

* fix github suggestions error

* Update docs/knowledgebase/advanced/ss58-address-format.md

Co-authored-by: sacha-l <[email protected]>

* fix: wording and formatting

* Update docs/knowledgebase/advanced/ss58-address-format.md

Co-authored-by: Dan Forbes <[email protected]>
Co-authored-by: Imad Arain <[email protected]>
Co-authored-by: Jimmy Chu <[email protected]>
Co-authored-by: Dan Forbes <[email protected]>
Co-authored-by: Tomasz Drwięga <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jimmy Chu <[email protected]>
Co-authored-by: joe petrowski <[email protected]>
Co-authored-by: Sacha <[email protected]>
Co-authored-by: sacha-l <[email protected]>
  • Loading branch information
11 people authored May 14, 2021
1 parent 37327e4 commit 072d613
Showing 1 changed file with 85 additions and 2 deletions.
87 changes: 85 additions & 2 deletions docs/knowledgebase/advanced/ss58-address-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,89 @@ The basic idea is a base-58 encoded value that can identify a specific account o
chain. Different chains have different means of identifying accounts. SS58 is designed to be
extensible for this reason.

The living specification for the SS-58 address format can be found on the Substrate GitHub wiki:
The living specification for the SS58 address format can be found on the
[Substrate GitHub wiki](<https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)>).

https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)
## Validating Addresses

There are several ways to verify that a value is a valid SS58 address.

### Subkey

You can use the [Subkey](https://substrate.dev/docs/en/knowledgebase/integrate/subkey) `inspect`
subcommand, which accepts the seed phrase, a hex-encoded private key, or an SS58 address as the input
URI. If the input is a valid address, it will return a list containing the corresponding public
key (hex), account ID, and SS58 values.

Subkey assumes that an address is based on a public/private keypair. In the case of inspecting an
address, it will return the 32 byte account ID. Not all addresses in Substrate-based networks are
based on keys.

> **Note:** If you input a valid SS58 value, Subkey will also return a network ID/version value
> that indicates for which network the address has been encoded.
```bash
# A valid address.
$ subkey inspect "12bzRJfh7arnnfPPUZHeJUaE62QLEwhK48QnH9LXeK2m1iZU"
Public Key URI `12bzRJfh7arnnfPPUZHeJUaE62QLEwhK48QnH9LXeK2m1iZU` is account:
Network ID/version: polkadot
Public key (hex): 0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a
Account ID: 0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a
SS58 Address: 12bzRJfh7arnnfPPUZHeJUaE62QLEwhK48QnH9LXeK2m1iZU

# An invalid address.
$ subkey inspect "12bzRJfh7arnnfPPUZHeJUaE62QLEwhK48QnH9LXeK2m1iZUInvalidAddress"
Invalid phrase/URI given
```

### Polkadot.js

For verifying an address in your JavaScript projects, you can utilize the functions built
into the [Polkadot.js API](https://polkadot.js.org/docs/api/).

```javascript
// Import Polkadot.js API dependencies.
const { decodeAddress, encodeAddress } = require("@polkadot/keyring");
const { hexToU8a, isHex } = require("@polkadot/util");

// Specify an address to test.
const address = "<addressToTest>";

// Check address.
const isValidSubstrateAddress = () => {
try {
encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address));

return true;
} catch (error) {
return false;
}
};

// Query result.
const isValid = isValidSubstrateAddress();
console.log(isValid);
```

### Community Built

Below you will find a list of other Substrate API tools built in various languages by our community.
They each validate addresses in their own way, and can act as a starting point.

- [Python Substrate Interface](https://polkascan.github.io/py-substrate-interface/#substrateinterface.Keypair) - developed by Polkascan.

- [Go Substrate RPC client](https://github.com/centrifuge/go-substrate-rpc-client) - developed by Centrifuge.

- [C++ Polkadot Substrate API](https://github.com/usetech-llc/polkadot_api_cpp) - developed by Usetech.

- [.Net API](https://github.com/usetech-llc/polkadot_api_dotnet) - developed by Usetech.

- [Go implemented utilities](https://github.com/itering/subscan-essentials) - developed by Subscan.

- [SS58 Transform](https://polkadot.subscan.io/tools/ss58_transform) - to manually verify an address (sanity check).

### Learn More

- [Polkadot-js API on GitHub](https://github.com/polkadot-js/api)

- [Subkey guide](docs/en/knowledgebase/integrate/subkey)

0 comments on commit 072d613

Please sign in to comment.