TP-Lab / provider-document

Providers document for TokenPocket chains.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TokenPocket Providers API (Draft)

TokenPocketProvider

Interfaces

interface TokenPocketWindow extends Window {
    tokenpocket: TokenPocketProvider
}

interface TokenPocketProvider extends Window {
    ethereum?: EvmProvider
    tron?: TronProvider
    aptos?: AptosProvider
    bitcoin?: BitcoinProvider
    nostr?: NostrProvider
    // solana?: SolanaProvider
    // cosmos?: CosmosProvider
    // eos?: EosProvider
}

EVM Provider

Support ETH, BSC, POLYGON, OP, ARB, HECO, OKC and any EVM chains.

Implementation of EIP-1193, EIP-1102, EIP-3085, EIP-695, EIP-1474, EIP-3326

Interfaces

interface RequestPayload {
    method: string;
    params?: unknown[] | object
}

interface EvmProvider {
    readonly isTokenpocket: true;
    request(payload: RequestPayload): Promise<RequestResponse>;
}

APTOS Provider

Support APTOS Network

Implementation of aptos-wallet-adapter

Interfaces

interface AptosProvider {
    readonly isTokenPocket: true
    connect(): Promise<AptosAccount>;
    account(): Promise<AptosAccount>;
    getChainId(): Promise<string | number>
    getNodeUrl(): Promise<string>
    network(): Promise<string>
    signAndSubmitTransaction(transaction: AptosTransaction, options: AptosTransactionOpt): Promise<AptosTransactionResponse>;
    signTransaction(transaction: AptosTransaction, options: AptosTransactionOpt): Promise<AptosSignedTransaction>;
    signMessage(messageObj: AptosMessage): Promise<AptosMessage>;
    request(payload: RequestPayload): Promise<RequestResponse>
}

TRON Provider

implementation of TIP-1193, TIP-1102

Support TRON

Interfaces

interface RequestPayload {
    method: string;
    params?: unknown[] | object
}

interface TronProvider {
    readonly isTokenpocket: true;
    tronWeb: TronWeb;
    request(payload: RequestPayload): Promise<RequestResponse>;
}

Methods

1. tron_requestAccounts / eth_requestAccounts

bitcoin.request({
    method: 'tron_requestAccounts'
}).then(console.log)

// return
['TKqQ7zuL7yKp1NWuhGpoXTDiE3j2qiAbRE']

BTC & Forked Provider

Support BTC / DOGE ...

Interfaces

interface RequestPayload {
    method: string;
    params?: unknown[] | object
}


interface BitcoinProvider {
    readonly isTokenpocket: true;
    request(payload: RequestPayload): Promise<RequestResponse>;
}

Methods

1. btc_accounts

bitcoin.request({
    method: 'btc_accounts'
}).then(console.log)

// return

['39Px4rNdV1c1MzEKeVUQgQThbWAD4vfVHC']

2. btc_signMessage

bitcoin.request({
    method: 'btc_signMessage',
    params: ['Hello world!', '39Px4rNdV1c1MzEKeVUQgQThbWAD4vfVHC']
}).then(console.log)

// return signature
"I9knbZ0oaUo7fl8mKBJPP4cTy9kOOdTed51EC4BbrfdJdMdqUKw5yX81J7nrDBbDlA/7adqhQr2Fdg8MRSbA1W8="
2.1 Verification

Using https://github.com/bitcoinjs/bitcoinjs-message to verify the signature

var bitcoinMessage = require('bitcoinjs-message')

console.log(bitcoinMessage.verify(message, address, signature[, network.messagePrefix]))
// return true or false

3. btc_chainId

Reference: BIP-122

bitcoin.request({
    method: 'btc_chainId'
}).then(console.log)

// return chainid 
'000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'

4. transfer btc/doge...

Reference: tp-js-sdk: btcTokenTransfer

We will migrate the tp-js-sdk's methods into this new protocol in the future. But we will keep this tp-js-sdk either.

5. get btc/doge... balance

Reference: tp-js-sdk: getCurrentBalance

We will migrate the tp-js-sdk's methods into this new protocol in the future. But we will keep this tp-js-sdk either.

Nostr (Under development)

Implementation of NIP-07

Interfaces

interface Nip04 {
    encrypt(pubkey: string, plaintext: string): Promise<string>
    decrypt(pubkey: string, ciphertext: string): Promise<string> 
}

interface Relays {
    [url: string]: {read: boolean, write: boolean}
}

interface Event {
    id: string;
    pubkey: string:
    created_at: string;
    kind: number;
    tags?: array;
    content: string;
    sig?: string; 
}

interface NostrProvider {
    readonly isTokenPocket: true;
    getPublicKey(): Promise<string>;
    signEvent(event: Event): Promise<Event>;
    getRelays(): Promise<Relays>
    nip04: Nip04
}

About

Providers document for TokenPocket chains.