Keeper-Wallet / Keeper-Wallet-Extension

Your entry point to the Waves blockchain and Waves-powered web services
https://keeper-wallet.app
Other
66 stars 45 forks source link
blockchain blockchain-wallet browser-extension crypto-wallet cryptocurrencies cryptocurrency-wallet dapp-developers

Keeper Wallet

"" "" ""

"" "" ""

en | ru

Keeper Wallet is a browser extension that enables secure interaction with Waves-enabled web services.

Seed phrases and private keys are encrypted and stored within the extension and cannot be accessed by online dApps and services, making sure that users' funds are always protected from hackers and malicious websites. Completion of a transaction doesn't require entering any sensitive information.

Keeper Wallet is designed for convenience, so users can sign transactions with just one click. Users can create multiple wallets and switch between them easily. And if a user ever forgets the password to the account, it can be recovered from the seed phrase.

Waves protocol documentation

Keeper Wallet API

On browser pages that operate under http/https (not local pages with file:// protocol) with Keeper Wallet extension installed, KeeperWallet global object becomes available.

In KeeperWallet you will find the following methods:

All methods except for on operate asynchronously and return Promises.

In code, you can use TypeScript types.

In Keeper Wallet, for greater security and ease of use, each new website using API has to be allowed by the user. At the first attempt to use API (except on), the user will see a request to allow the website to access Keeper Wallet. If the user agrees to allow access, the website is considered trusted and can use API on its pages. Otherwise, the website is blocked, and the error message {message: "Api rejected by user", code: 12} will be displayed in response to all requests. The user won't see new notifications. To grant access, the user has to mark the website as trusted in the interface.

Description of methods

publicState

If a website is trusted, Keeper Wallet public data are returned.

Example:

KeeperWallet.publicState()
  .then(state => {
    console.log(state); //displaying the result in the console
    /*...processing data */
  })
  .catch(error => {
    console.error(error); // displaying the result in the console
    /*...processing errors */
  });

or

const getPublicState = async () => {
  try {
    const state = await KeeperWallet.publicState();
    console.log(state); // displaying the result in the console
    /*... processing data*/
  } catch (error) {
    console.error(error); // displaying the result in the console
    /*... processing errors */
  }
};

const result = await getPublicState();

Response:

{
    "initialized": true,
    "locked": true,
    "account": {
        "name": "foo",
        "publicKey": "bar",
        "address": "waves address",
        "networkCode": "network byte",
        "balance": {
            "available": "balance in waves",
            "leasedOut": "leased balance"
        }
    },
    "network": {
        "code": "W",
        "server": "https://nodes.wavesnodes.com/",
        "matcher": "https://matcher.waves.exchange/"
    },
    "messages": [],
    "txVersion": {
        "3": [ 2 ],
        "4": [ 2 ],
        "5": [ 2 ],
        ...
    }
}

Response fields:

Possible errors:

notification

A method for sending a user a message from the site. You can send message only 1 time in 30 sec for trusted sites with send permission.

notification facilitates input of the following data:

Example:

KeeperWallet.notification({
  title: 'Hello!',
  message: 'Congratulation!!!',
});

Response: Promise.

Possible errors:

encryptMessage

You can encrypt string messages to account in Waves network. You need have recipient publicKey.

KeeperWallet.encryptMessage(*string to encrypt*, *public key in base58 string*, *prefix: a secret app string for encoding*)

Example:

KeeperWallet.encryptMessage(
  'My message',
  '416z9d8DQDy5MPTqDhvReRBaPb19gEyVRWvHcewpP6Nc',
  'my app',
).then(encryptedMessage => {
  console.log(encryptedMessage);
});

Possible errors:

decryptMessage

You can decrypt string messages from account in Waves network to you. You need to have user's public key and the encrypted message.

KeeperWallet.decryptMessage(*string to decrypt*, *public key in base58 string*, *prefix: a secret app string for encoding*)

Example:

KeeperWallet.decryptMessage(
  '**encrypted msg**',
  '416z9d8DQDy5MPTqDhvReRBaPb19gEyVRWvHcewpP6Nc',
  'my app',
).then(message => {
  console.log(message);
});

Possible errors:

on

Allows subscribing to Keeper Wallet events.

Supports events:

Example:

KeeperWallet.on('update', state => {
  //state object as from KeeperWallet.publicState
});

If a website is not trusted, events won't be displayed.

auth

This is a method for obtaining a signature of authorization data while verifying Waves' user. If the the signature is valid, be sure that the given blockchain account belongs to that user.

Example:

const authData = { data: 'Auth on my site' };
KeeperWallet.auth(authData)
  .then(auth => {
    console.log(auth); //displaying the result on the console
    /*...processing data */
  })
  .catch(error => {
    console.error(error); // displaying the result on the console
    /*...processing errors */
  });

or

const getAuthData = async authData => {
  try {
    const state = await KeeperWallet.auth(authData);
    console.log(state); // displaying the result on the console
    /*... processing data */
  } catch (error) {
    console.error(error); // displaying the result on the console
    /*... processing errors */
  }
};

const authData = { data: 'Auth on my site' };
getAuthData(authData);

auth facilitates input of the following data:

Example:

const authData = {
  data: 'Generated string from server',
  name: 'My test App',
  icon: '/img/icons/waves_logo.svg',
  referrer: 'https://waves.exchange/',
  successPath: 'login',
};

KeeperWallet.auth(authData)
  .then(data => {
    //data – data from Keeper Wallet
    //verifying signature and saving the address...
    console.log(data);
  })
  .catch(error => {
    //processing the error
  });

If the verification is successful, Keeper Wallet returns to the Promise an object containing data for signature verification:

Possible errors:

How to check signature validity Signed data consists of three parts: `prefix` (`WavesWalletAuthentication` string) + `host` + provided data. All strings are converted to `length bytes` + `value bytes` as in Data Transactions. Prefix string and the host is required for security purposes if malicious service tries to use data and signature. We also suggest address validation in case the signature and public key is valid but the address was swapped. **TypeScript example code** ```typescript import { verifyAuthData, libs } from '@waves/waves-transactions'; const authValidate = ( data: { host: string; data: string }, signature: string, publicKey: string, chainId: string | number, ): boolean => { const chain = typeof chainId === 'string' ? chainId : String.fromCharCode(chainId); const address = libs.crypto.address({ publicKey }, chain); return verifyAuthData({ publicKey, address, signature }, data); }; // Obtaining the signature const data = await KeeperWallet.auth({ data: '123' }); authValidate(data, { host: data.host, data: '123' }); // true ``` **JS example code** ```js import { verifyAuthData, libs } from '@waves/waves-transactions'; const authValidate = (signature, data, publicKey, chainId) => { const chain = typeof chainId === 'string' ? chainId : String.fromCharCode(chainId); const address = libs.crypto.address({ publicKey }, chain); return verifyAuthData({ publicKey, address, signature }, data); }; // Obtaining the signature const data = await KeeperWallet.auth({ data: '123' }); authValidate(data, { host: data.host, data: '123' }); // true ``` **Python example code** ```python import axolotl_curve25519 as curve import pywaves.crypto as crypto import base58 from urllib.parse import urlparse, parse_qs def str_with_length(string_data): string_length_bytes = len(string_data).to_bytes(2, byteorder='big') string_bytes = string_data.encode('utf-8') return string_length_bytes + string_bytes def signed_data(host, data): prefix = 'WavesWalletAuthentication' return str_with_length(prefix) + str_with_length(host) + str_with_length(data) def verify(public_key, signature, message): public_key_bytes = base58.b58decode(public_key) signature_bytes = base58.b58decode(signature) return curve.verifySignature(public_key_bytes, message, signature_bytes) == 0 def verifyAddress(public_key, address): public_key_bytes = base58.b58decode(public_key) unhashed_address = chr(1) + str('W') + crypto.hashChain(public_key_bytes)[0:20] address_hash = crypto.hashChain(crypto.str2bytes(unhashed_address))[0:4] address_from_public_key = base58.b58encode(crypto.str2bytes(unhashed_address + address_hash)) return address_from_public_key == address address = '3PCAB4sHXgvtu5NPoen6EXR5yaNbvsEA8Fj' pub_key = '2M25DqL2W4rGFLCFadgATboS8EPqyWAN3DjH12AH5Kdr' signature = '2w7QKSkxKEUwCVhx2VGrt5YiYVtAdoBZ8KQcxuNjGfN6n4fi1bn7PfPTnmdygZ6d87WhSXF1B9hW2pSmP7HucVbh' data_string = '0123456789abc' host_string = 'example.com' message_bytes = signed_data(host_string, data_string) print('Address:', address) print('Public key:', pub_key) print('Signed Data:', message_bytes) print('Real signature:', signature) print('Verified:', verify(pub_key, signature, message_bytes)) print('Address verified:', verifyAddress(pub_key, address)) fake_signature = '29qWReHU9RXrQdQyXVXVciZarWXu7DXwekyV1zPivkrAzf4VSHb2Aq2FCKgRkKSozHFknKeq99dQaSmkhUDtZWsw' print('Fake signature:', fake_signature) print('Fake signature verification:', verify(pub_key, fake_signature, message_bytes)) ``` **PHP example code** ```php log('i', 'Address: '. $address); $wk->log('i', 'Public key:' . $pub_key); $wk->log('i', 'Signed Data: ' . $message_bytes); $wk->log('i', 'Real signature: '. $signature); $wk->setPublicKey( $pub_key ); $is_address_verified = $address === $wk->getAddress(); if ( $is_address_verified === true) $wk->log('s', "Address: Verified: TRUE"); else $wk->log('e', "Address: Verified: FALSE"); $signature_verified = $wk->verify($wk->base58Decode($signature), $message_bytes); if ( $signature_verified === true) $wk->log('s', "Signature Verified: TRUE"); else $wk->log('e', "Signature Verified: FALSE"); $fake_signature = '29qWReHU9RXrQdQyXVXVciZarWXu7DXwekyV1zPivkrAzf4VSHb2Aq2FCKgRkKSozHFknKeq99dQaSmkhUDtZWsw'; $wk->log('i', 'Fake Signature: '. $fake_signature); $signature_verified = $wk->verify($wk->base58Decode($fake_signature), $message_bytes); if ( $signature_verified === true) $wk->log('e', "Fake Signature Verified: TRUE"); else $wk->log('s', "Fake Signature Verified: FALSE"); ?> ```

signTransaction

A method for signing transactions in Waves network. See the description of supported transaction types in Transactions section below.

Example:

const txData = {
  type: 4,
  data: {
    amount: {
      assetId: 'WAVES',
      tokens: '1.567',
    },
    fee: {
      assetId: 'WAVES',
      tokens: '0.001',
    },
    recipient: 'test',
  },
};
KeeperWallet.signTransaction(txData)
  .then(data => {
    //data – a line ready for sending to Waves network's node (server)
  })
  .catch(error => {
    //Processing errors
  });

API returns lines, not an object, as in JavaScript precision is lost in operation with 8-byte integers.

In the example, we are signing a transaction for transferring WAVES to the alias test in Waves network.

Response:

{
  "version": 2,
  "assetId": "",
  "amount": 156700000,
  "feeAssetId": "",
  "fee": 100000,
  "recipient": "recipient",
  "attachment": "",
  "timestamp": 1548770230589,
  "senderPublicKey": "public key",
  "proofs": ["signature"],
  "type": 4
}

Possible errors:

signAndPublishTransaction

This is similar to signTransaction, but it also broadcasts a transaction to the blockchain. See the description of supported transaction types in Transactions section below.

Example:

const txData = {
  type: 4,
  data: {
    amount: {
      assetId: 'WAVES',
      tokens: '1.567',
    },
    fee: {
      assetId: 'WAVES',
      tokens: '0.001',
    },
    recipient: 'test',
  },
};

KeeperWallet.signAndPublishTransaction(txData)
  .then(data => {
    //data - a line ready for sending to Waves network's node (server)
  })
  .catch(error => {
    //processing errors
  });

Response: a reply from Waves network returns as a line containing the entire past transaction.

Possible errors:

signTransactionPackage

A package transaction signature. Sometimes several transactions need to be simultaneously signed, and for users' convenience, up to seven transactions at ones could be signed. See the description of supported transaction types in Transactions section below.

Example:

const name = 'For Test';
const tx = [
  {
    type: 4,
    data: {
      amount: {
        assetId: 'WAVES',
        tokens: '1.567',
      },
      fee: {
        assetId: 'WAVES',
        tokens: '0.001',
      },
      recipient: 'test',
    },
  },
  {
    type: 4,
    data: {
      amount: {
        assetId: 'WAVES',
        tokens: '0.51',
      },
      fee: {
        assetId: 'WAVES',
        tokens: '0.001',
      },
      recipient: 'merry',
    },
  },
];

KeeperWallet.signTransactionPackage(tx, name);

Sign two transaction:

Response: a unit of two lines – transactions that are signed and ready to broadcast.

Possible errors:

Same as in signTransaction.

Transactions

Every user of Waves network has a state (balances, assets, data, scripts), and every past transaction changes this data. More about transactions

In Keeper Wallet API transaction format is different from Node REST API. signTransactionsignAndPublishTransaction, and signTransactionPackage accept transactions as follows:

{
    type: number, //transaction type
    data: {
        ... //transaction data
    }
}

Keeper Wallet supports the following types of transactions:

Legend keys:

MoneyLike could look as:

In both messages, the same price of 1 WAVES is indicated. You can easily convert coins into tokens and back, if you know in what asset the price is indicated, and you have received its precision: tokens = coins / (10 ** precision).

If the field contains other types than MoneyLike, for instance, string/MoneyLike, the sum is indicated as a number in  coins.

Transaction fee

See Transaction fee section in the Waves protocol documentation.

Issue transaction (type 3)

See Issue transaction details in the Waves protocol documentation.

Fields:

Example:

KeeperWallet.signAndPublishTransaction({
  type: 3,
  data: {
    name: 'Best Token',
    description: 'Great token',
    quantity: 1000000,
    precision: 2,
    reissuable: true,
    fee: {
      tokens: '1',
      assetId: 'WAVES',
    },
  },
})
  .then(tx => {
    console.log("Hurray! I've created my asset!!!");
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });

In case of success, we issue a new asset in the quantity of 1,000,000, and your balance will show 10,000.00 Best Token.

Transfer transaction (type 4)

See Transfer transaction details in the Waves protocol documentation.

Fields:

Example:

KeeperWallet.signAndPublishTransaction({
  type: 4,
  data: {
    amount: { tokens: '3.3333333', assetId: 'WAVES' },
    fee: { tokens: '0.001', assetId: 'WAVES' },
    recipient: 'merry',
  },
})
  .then(tx => {
    console.log("Hurray! I've been able to send WAVES!!!");
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });
Reissue transaction (type 5)

See Reissue transaction details in the Waves protocol documentation.

Fields:

Example:

KeeperWallet.signAndPublishTransaction({
  type: 5,
  data: {
    quantity: 1000,
    assetId: '4DZ1wnZAKr66kpPtYr8hH1kfViF7Z7vrALfUDDttSGzD',
    reissuable: true,
    fee: {
      tokens: '1',
      assetId: 'WAVES',
    },
  },
})
  .then(tx => {
    console.log("Hurray! I've reissued my asset!!!");
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });

In case of success, we reissue the asset in the quantity of 1000, and user balance will show 10,010.00 Best Token.

Burn transaction (type 6)

See Burn transaction details in the Waves protocol documentation.

Fields:

Example:

KeeperWallet.signAndPublishTransaction({
  type: 6,
  data: {
    amount: 1000,
    assetId: '4DZ1wnZAKr66kpPtYr8hH1kfViF7Z7vrALfUDDttSGzD',
    fee: {
      tokens: '0.001',
      assetId: 'WAVES',
    },
  },
})
  .then(tx => {
    console.log("Hurray! I've burned unneeded tokens!!!");
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });

In case of success, 1000 coins are burned.

Lease transaction (type 8)

See Lease transaction details in the Waves protocol documentation.

Fields:

Example:

KeeperWallet.signAndPublishTransaction({
  type: 8,
  data: {
    amount: 1000,
    recipient: 'merry',
    fee: {
      tokens: '0.001',
      assetId: 'WAVES',
    },
  },
})
  .then(tx => {
    console.log("Hurray! I've been able to lease tokens!!!");
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });

In case of success, 0.00001000 WAVES is leased.

Lease Cancel transaction (type 9)

See Lease Cancel transaction details in the Waves protocol documentation.

Fields:

Example:

KeeperWallet.signAndPublishTransaction({
  type: 9,
  data: {
    leaseId: '6frvwF8uicAfyEfTfyC2sXqBJH7V5C8he5K4YH3BkNiS',
    fee: {
      tokens: '0.001',
      assetId: 'WAVES',
    },
  },
})
  .then(tx => {
    console.log("Hurray! I've cancelled leasing!!!");
  })
  .catch(error => {
    console.error('Something went wrong ', error);
  });

In case of success, the lease is cancelled.

Create Alias transaction (type 10)

See Create Alias transaction details in the Waves protocol documentation.

Fields:

Example:

KeeperWallet.signAndPublishTransaction({
  type: 10,
  data: {
    alias: 'test_alias',
    fee: {
      tokens: '0.001',
      assetId: 'WAVES',
    },
  },
})
  .then(tx => {
    console.log('Hurray! Now I have an alias!!!');
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });

In case of success, an alias (another name) is created.

Mass Transfer transaction (type 11)

See Mass Transfer transaction details in the Waves protocol documentation.

Fields:

Example:

KeeperWallet.signAndPublishTransaction({
  type: 11,
  data: {
    totalAmount: { assetId: 'WAVES', coins: 0 },
    transfers: [
      { recipient: 'alias1', amount: '200000' },
      { recipient: 'alias2', amount: '200000' },
    ],
    fee: {
      tokens: '0.002',
      assetId: 'WAVES',
    },
  },
})
  .then(tx => {
    console.log("Hurray! I've sent hi to my friends!!!");
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });

In case of success, 0.00200000 WAVES will be sent to alias1 and alias2.

Data transaction (type 12)

See Data transaction details in the Waves protocol documentation.

Fields:

Example:

KeeperWallet.signAndPublishTransaction({
  type: 12,
  data: {
    data: [
      {
        key: 'string',
        value: 'testVdfgdgf dfgdfgdfg dfg dfg al',
        type: 'string',
      },
      {
        key: 'binary',
        value: 'base64:AbCdAbCdAbCdAbCdAbCdAbCdAbCdAbCdAbCdAbCdAbCd',
        type: 'binary',
      },
      { key: 'integer', value: 20, type: 'integer' },
      { key: 'boolean', value: false, type: 'boolean' },
    ],
    fee: {
      tokens: '0.01',
      assetId: 'WAVES',
    },
  },
})
  .then(tx => {
    console.log("Hurray! I've saved data!!!");
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });

In case of success, new data is stored in the account data storage.

To delete an entry, pass the entry key along with value: null. Entry deletion is available from version 2, so the version field is required.

Example:

KeeperWallet.signAndPublishTransaction({
  type: 12,
  data: {
    version: 2,
    data: [{ key: 'binary', value: null }],
    fee: {
      tokens: '0.001',
      assetId: 'WAVES',
    },
  },
})
  .then(tx => {
    console.log("Hurray! I've deleted data!!!");
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });
Set Script transaction (type 13)

See Set Script transaction details in the Waves protocol documentation.

Fields:

To develop and compile the script, use Waves IDE.

Example:

KeeperWallet.signAndPublishTransaction({
  type: 13,
  data: {
    script:
      'base64:BQkACccAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXmfT++m',
    fee: {
      tokens: '0.01',
      assetId: 'WAVES',
    },
  },
})
  .then(tx => {
    console.log("Hurray! I've added a script!!!");
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });

In case of success, a new script will be added to the account (be careful!).

For cancelling a script set script: null or script: ''.

Example 2:

KeeperWallet.signAndPublishTransaction({
  type: 13,
  data: {
    script: '',
    fee: {
      tokens: '0.04',
      assetId: 'WAVES',
    },
  },
})
  .then(tx => {
    console.log("Hurray! I've cancelled a script!!!");
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });

In case of success, the script is removed from the account.

Sponsor Fee transaction (type 14)

See Sponsor Fee transaction details in the Waves protocol documentation.

Fields:

Example:

KeeperWallet.signAndPublishTransaction({
  type: 14,
  data: {
    minSponsoredAssetFee: {
      assetId: '6frvwF8uicAfyEfTfyC2sXqBJH7V5C8he5K4YH3BkNiS',
      tokens: 0.1,
    },
    fee: {
      tokens: '1',
      assetId: 'WAVES',
    },
  },
})
  .then(tx => {
    console.log("Hurray! I've become a sponsor!!!");
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });

In case of success, fees for Transfer and Invoke Script transactions can be paid in the asset.

Set Asset Script transaction (type 15)

See Set Asset Script transaction details in the Waves protocol documentation.

Fields:

It's impossible to remove the asset script; you can only change the script. To develop and compile the script, use Waves IDE.

Example:

KeeperWallet.signAndPublishTransaction({
  type: 15,
  data: {
    assetId: '',
    script: 'base64:BQbtKNoM',
    fee: {
      tokens: '0.01',
      assetId: 'WAVES',
    },
  },
})
  .then(tx => {
    console.log('Hurray! I have reset a script to the asset!!!');
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });

In case of success, the asset's script is reset.

Invoke Script transaction (type 16)

See Invoke Script transaction details in the Waves protocol documentation.

Fields:

Example:

KeeperWallet.signAndPublishTransaction({
  type: 16,
  data: {
    fee: {
      tokens: '0.05',
      assetId: 'WAVES',
    },
    dApp: '3N27HUMt4ddx2X7foQwZRmpFzg5PSzLrUgU',
    call: {
      function: 'tellme',
      args: [
        {
          type: 'string',
          value: 'Will?',
        },
      ],
    },
    payment: [{ assetId: 'WAVES', tokens: 2 }],
  },
})
  .then(tx => {
    console.log('Hurray! I've invoked the script!!!');
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });

In case of success, the callable function tellme of Testnet account 3N27HUMt4ddx2X7foQwZRmpFzg5PSzLrUgU will be invoked.

An example of an invocation of a function with a list argument:

KeeperWallet.signAndPublishTransaction({
  type: 16,
  data: {
    dApp: '3N28o4ZDhPK77QFFKoKBnN3uNeoaNSNXzXm',
    call: {
      function: 'foo',
      args: [
        {
          type: 'list',
          value: [
            { type: 'string', value: 'alpha' },
            { type: 'string', value: 'beta' },
            { type: 'string', value: 'gamma' },
          ],
        },
      ],
    },
    payment: [],
    fee: {
      tokens: '0.005',
      assetId: 'WAVES',
    },
  },
})
  .then(tx => {
    console.log("Hurray! I've invoked the script!!!");
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });
Update Asset Info transaction (type 17)

See Update Asset Info transaction details in the Waves protocol documentation.

Fields:

Example:

KeeperWallet.signAndPublishTransaction({
  type: 17,
  data: {
    name: 'New name',
    description: 'New description',
    assetId: 'DS5fJKbhKDaFfcRpCd7hTcMqqxsfoF3iY9yEcmsTQV1T',
    fee: {
      assetId: 'WAVES',
      tokens: '0.001',
    },
  },
})
  .then(tx => {
    console.log("Hurray! I've renamed the asset!!!");
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });

signOrder

Keeper Wallet's method for signing an order to the matcher (exchange service). As input, it accepts an object similar to a transaction like this:

{
    data: {
        ...data
    }
}

See order details in the Waves protocol documentation.

See how to calculate the order fee in Waves.Exchange documentation.

Fields:

Example:

KeeperWallet.signOrder({
  data: {
    matcherPublicKey: '9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5',
    orderType: 'sell',
    expiration: Date.now() + 100000,
    amount: {
      tokens: '100',
      assetId: 'WAVES',
    },
    price: {
      tokens: '0.01',
      assetId: '8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS',
    },
    matcherFee: {
      tokens: '0.1',
      assetId: 'WAVES',
    },
  },
});
then(tx => {
  console.log("Hurray! I've signed an order!!!");
}).catch(error => {
  console.error('Something went wrong', error);
});

Response: a line with data for sending to the matcher.

Possible errors:

signAndPublishOrder

Keeper Wallet's method for creating an order to the matcher is identical to signOrder, but it also tries to send data to the matcher.

Response: the matcher's reply line about successful creation of an order.

Possible errors:

signCancelOrder

Keeper Wallet's method for signing cancellation of an order to the matcher. As input, it accepts an object similar to a transaction like this:

{
    data: {
        ...data
    }
}

Fields:

Example:

KeeperWallet.signCancelOrder({
  data: {
    id: '31EeVpTAronk95TjCHdyaveDukde4nDr9BfFpvhZ3Sap',
  },
});

Response: a data line for sending to the matcher.

Possible errors:

signAndPublishCancelOrder

Keeper Wallet's method for cancelling an order to the matcher. It works identically to signCancelOrder, but also tries to send data to the matcher. You should specify two more fields: priceAsset and amountAsset from the order.

Example:

KeeperWallet.signAndPublishCancelOrder({
  priceAsset: 'WAVES',
  amountAsset: '8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS',
  data: {
    id: '31EeVpTAronk95TjCHdyaveDukde4nDr9BfFpvhZ3Sap',
  },
})
  .then(() => {
    console.log("Hurray! I've cancelled the order");
  })
  .catch(error => {
    console.error('Something went wrong', error);
  });

Response: data returned by the matcher.

Possible errors:

signRequest

Keeper Wallet's method for signing typified data, for signing requests on various services. As input, it accepts an object similar to a transaction like this:

{
    type: number,
    data: {
        ...data
    }
}

Currently, the method supports only signing data for a request to the matcher for your orders.

Fields:

Example:

KeeperWallet.signRequest({
  data: {
    timestamp: 234234242423423,
  },
});

Response: a line with a signature in base58.

Possible errors:

signCustomData

Keeper Wallet's method for signing a custom data for different services. It accepts an object:

Version 1

Note: This method adds the [255, 255, 255, 1] prefix to the signed bytes. This was done to make it impossible to sign transaction data in this method, which can lead to unauthenticated transactions and phishing. For the details check serializeCustomData method in waves-transactions library.

Example:

KeeperWallet.signCustomData({
  version: 1,
  binary: 'base64:AADDEE==',
});

Response:

   {
        version: 1,
        binary: 'base64:AADDEE==',
        signature: '...',
        publicKey: '...'
   }

Possible errors:

Version 2

Bytes to sign: [255, 255, 255, 2, ...(from data array to bin)]. For the details check serializeCustomData method in waves-transactions library.

Example:

KeeperWallet.signCustomData({
  version: 2,
  data: [{ type: 'string', key: 'name', value: 'Mr. First' }],
});

Response:

   {
        version: 2,
        data: [{ type: 'string', key: 'name', value: 'Mr. First' }]
        signature: '...',
        publicKey: '...'
   }

Possible errors:

verifyCustomData

Validate custom data:

{
    version: 1,
    binary: 'base64:AADDEE==',
    signature: '...',
    publicKey: '...'
}

or

{
    version: 2,
    data: [{ type: 'string', key: 'name', value: 'Mr. First' }],
    signature: '...',
    publicKey: '...'
}

Example:

KeeperWallet.verifyCustomData({
  version: 1,
  binary: 'base64:AADDEE==',
  publicKey: '3BvAsKuGZe2LbSwKr9SA7eSXcNDKnRqN1j2K2bZaTn5X',
  signature:
    '2bLJYR68pwWrUUoatGbySz2vfY76VtzR8TScg1tt5f9DVDsFDCdecWrUiR4x6gFBnwF4Y51uszpouAwtSrg7EcGg',
}).then(result => {
  console.log(result);
});

Response: true/false.

Possible errors:

resourceIsApproved

Check whether the user allowed your website to access Keeper Wallet.

Example:

KeeperWallet.resourceIsApproved().then(result => {
  console.log(result);
});

Response: true/false.

resourceIsBlocked

Check whether the user blocked your website in Keeper Wallet.

Example:

KeeperWallet.resourceIsBlocked().then(result => {
  console.log(result);
});

Response: true/false.