Skip to content

Addresses and keys

Paul edited this page Nov 3, 2022 · 9 revisions

Accounts

Master account in 3DPass is defined by a mnemonic seed phrase which can be utilized for the construction of various types of keys. Whatever key type was used, there is always a possibility to validate the standard account by its public key. Standard account ID is a public key.

3DPass allows for the creation and management of different types of crypto. There are ed25519 (Edwards) and sr25519 (schnorrkel) types supported. There are no differences in security between ed25519 and sr25519 for simple signatures. At the same time, sr25519 makes implementing more complex protocols safer. In particular, sr25519 comes with safer version of many protocols like HDKD common in the Bitcoin and Ethereum ecosystem.

  • Master account (mnemonic seed phrase like fog olympic thrive recall allow page hood damage october curtain degree bubble)
    • sr25519 (schnorrkel) - standard accounts designed to control funds with
    • ed25519 (Edwards) - GRANDPA finalization

SS58 Address Format

The default Substrate address format is SS58. The SS58 encoded address format is based on the Bitcoin Base-58-check format, but with a few modification specifically designed to suite Substrate-based chains. However, the SS58 address format provides a base-58 encoded value that can identify a specific account on any Substrate chain. Because different chains can have different ways of identifying accounts, the SS58 address is designed to be extensible. Follow Substrate documentation to learn more details.

Default SS58 Substrate address example:

SS58 Address: 5CsiY8RKbWM2UN2rdjg8mKcoELWr366EAPMu6FQsWLFs373Q

The ss58Format: is used to format addresses for 3DPass:

  • ss58Format: 71 - mainnet
  • ss58Format: 72 - testnet

For example, to generate a mainnet account you'll need to specify both the type and the format like that type: 'sr25519', ss58Format: 71.

3DPass mainnet standard account example:

Public key (account ID): 0xccc201f5b3e7036c5ea534096d75befbda68a9b285025csd7105bc4726f02f7e
Secret seed: fog olympic thrive recall allow page hood damage october curtain degrwe bubble
SS58 Address (formatted): d1GtBxnPwRZVez7VsQ9H7MskPn34H59RddrR9yXqhgDYsqC3t

@polkadot/keyring

Use these guidelines to create/validate addresses and keys using @polkadot/keyring in any JavaScript projects.

3DPass web wallet examples

3DPass web wallet uses @polkadot/keyring. Follow the code examples down below as a reference to its exact implementation:

Validation of 3DPass addresses

There are two common ways which might be leveraged for the validation of 3dpass addresses, such as: cli command or @polkadot/keyring API.

  1. In order to validate the address via cli, there is inspect command, 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. You can use it as follows:
./target/release/poscan-consensus key inspect "d1HqrBYq9qsTbBb4tQtnt9sLgh9UsS7XJbgQgr5Cb4CxH2xAd"

If correct, the output will be like this:

Public Key URI `d1HqrBYq9qsTbBb4tQtnt9sLgh9UsS7XJbgQgr5Cb4CxH2xAd` is account:
  Network ID/Version: 71
  Public key (hex):   0xf7352a4d1c4d6a14652dc76cfa73f7c843dd02299e89c5397168d80469b6d0b1
  Account ID:         0xf7352a4d1c4d6a14652dc76cfa73f7c843dd02299e89c5397168d80469b6d0b1
  Public key (SS58):  d1HqrBYq9qsTbBb4tQtnt9sLgh9UsS7XJbgQgr5Cb4CxH2xAd
  SS58 Address:       d1HqrBYq9qsTbBb4tQtnt9sLgh9UsS7XJbgQgr5Cb4CxH2xAd

Incorrect:

./target/release/poscan-consensus key inspect "d1HqrBYq9qsTbBb4tQtnt9sLgh9UsS7XJbgQgr5Cb4CxH2xqd"
Invalid phrase/URI given
  1. For verification of the addresses in JavaScript projects Polkadot.js API is recommended to use:
// 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);

Additional Terminal cli commands

  • In order to generate a standard sr25519 account (address, keys and mnemonic seed phrase) via terminal use the following:
./target/release/poscan-consensus generate-mining-key --base-path ~/3dp-chain/ --chain mainnetSpecRaw.json

The output would be like that:

Public key: 0xccc201f5b3e7036c5ea534096d75befbda68a9b285025csd7105bc4726f02f7e
Secret seed: fog olympic thrive recall allow page hood damage october curtain degrwe bubble
Address: d1GtBxnPwRZVez7VsQ9H7MskPn34H59RddrR9yXqhgDYsqC3t

Notice, the key will be imported in the keystore ~/3dp-chain/chains/3dpass/keystore

  • In order to import the account previously generated somewhere else (e.x.in the wallet) into the keystore use the command below:
./target/release/poscan-consensus import-mining-key 'your secret seed phrase' --base-path ~/3dp-chain/ --chain mainnetSpecRaw.json
  • In order to generate GRANDPA keys for your account you have to utilize ed25519 type. Use the following:
./target/release/poscan-consensus key inspect --password-interactive --scheme Ed25519 "your secret seed phrase from your mining account"

The output would be like that:

Secret phrase:       fog olympic thrive recall allow page hood damage october curtain degree bubble
  Network ID:        71
  Secret seed:       0x9d7bf7c1ef42c97a5545adc8275347e16a7788e32b861aac45916660856aaf7e
  Public key (hex):  0xf7352a4d1c4d6a14652dc76cfa73f7c843dd02299e89c5397168d80469b6d0b1
  Account ID:        0xf7352a4d1c4d6a14652dc76cfa73f7c843dd02299e89c5397168d80469b6d0b1
  Public key (SS58): d1HqrBYq9qsTbBb4tQtnt9sLgh9UsS7XJbgQgr5Cb4CxH2xAd
  SS58 Address:      d1HqrBYq9qsTbBb4tQtnt9sLgh9UsS7XJbgQgr5Cb4CxH2xAd
  • In order to insert your GRANDPA key into the keystore the following command is required:
./target/release/poscan-consensus key insert --base-path ~/3dp-chain/ --chain mainnetSpecRaw.json --scheme Ed25519 --suri 0x9d7bf7c1ef42c97a5545adc8275347e16a7788e32b861aac45916660856aaf7e --key-type gran

--suri is your Secret seed for Grandpa (not a Secret phrase, but this one 0x9d7bf7c1ef42c97a5545adc8275347e16a7788e32b861aac45916660856aaf7e in the example above)

Cryptography

This is a high-level overview of the cryptography used in 3DPass. It assumes that you have some knowledge about cryptographic primitives that are generally used in blockchains such as hashes, elliptic curve cryptography (ECC), and public-private keypairs.

3DPass uses Schnorrkel/Ristretto x25519 ("sr25519") as its key derivation and signing algorithm. Sr25519 is based on the same underlying Curve25519 as its EdDSA counterpart, Ed25519. However, it uses Schnorr signatures instead of the EdDSA scheme. Schnorr signatures bring some noticeable benefits over the ECDSA/EdDSA schemes. For one, it is more efficient and still retains the same feature set and security assumptions. Additionally, it allows for native multisignature through signature aggregation.

The names Schnorrkel and Ristretto come from the two Rust libraries that implement this scheme, the Schnorrkel library for Schnorr signatures and the Ristretto library that makes it possible to use cofactor-8 curves like Curve25519.