Portal pentru dezvoltatori
Temă

Provider API (Signet)#

What is injected provider API (Signet) ?#

The OKX Injected Providers API (Signet) is based on a JavaScript model embedded by OKX into user-accessed websites. DApp projects can use this API to request your account information, read data from the blockchain to which you are connected, and help you in signing messages and transactions.

Note: BTC Signet is only available for extension version 2.82.32 or above.

connect#

okxwallet.bitcoinSignet.connect()

Description

Connect wallet

Parameters

none

Return value

  • Promise - object
    • address - string: address of current account
    • publicKey - string: public key of current account

Example

typescript
const result = await okxwallet.bitcoinSignet.connect()
// example
{
  address: 'bc1pwqye6x35g2n6xpwalywhpsvsu39k3l6086cvdgqazlw9mz2meansz9knaq',
  publicKey: '4a627f388196639041ce226c0229560127ef9a5a39d4885123cd82dc82d8b497'
}

signMessage#

okxwallet.bitcoinSignet.signMessage(signStr[, type])

Description

Sign message

Parameters

  • signStr - string: requires signed data
  • type - string: (optional) “ecdsa” | “bip322-simple”. The default value is “ecdsa”

Return value

  • Promise - string: the signing result

Example

typescript
const signStr = 'need sign string';
const result = await window.okxwallet.bitcoinSignet.signMessage(signStr, 'ecdsa')
// example
INg2ZeG8b6GsiYLiWeQQpvmfFHqCt3zC6ocdlN9ZRQLhSFZdGhgYWF8ipar1wqJtYufxzSYiZm5kdlAcnxgZWQU=

signPsbt#

okxwallet.bitcoinSignet.signPsbt(psbtHex[, options])

Description

Signing psbt: this will traverse all inputs that match the current address to sign.

Parameters

  • psbtHex - string: hexadecimal string representation of the partially signed bitcoin transaction (PSBT) that needs to be signed.
Note

When you generate the psbt (string) to be signed, you need to add a public key for every input of the psbt if the input uses a Taproot address.

Example: Refer to txInput and publicKey below.

typescript
const txInputs: utxoInput[] = [];
txInputs.push({
      txId: "1e0f92720ef34ab75eefc5d691b551fb2f783eac61503a69cdf63eb7305d2306",
      vOut: 2,
      amount: 341474,
      address: "tb1q8h8....mjxzny",
      privateKey: "0s79......ldjejke",
      publicKey: "tb1q8h8....mjxzny",
      bip32Derivation: [
          {
              "masterFingerprint": "a22e8e32",
              "pubkey": "tb1q8h8....mjxzny",
              "path": "m/49'/0'/0'/0/0",
          },
      ],
  });
  • options
    • autoFinalized - boolean: whether to finalize psbt after signing — the default is true
    • toSignInputs - array:
      • index - number: which input to sign
      • address - string: (at least specify either an address or a public key) which corresponding private key to use for signing
      • publicKey - string: (at least specify either an address or a public key) which corresponding private key to use for signing
      • sighashTypes - number[]: (optional) sighashTypes
      • disableTweakSigner - boolean: (optional) when signing and unlocking Taproot addresses, the tweakSigner is used by default for signature generation. Enabling this allows for signing with the original private key.
      • useTweakedSigner - boolean: (optional) when signing Taproot inputs, true uses the tweaked signer (key-path), false uses the untweaked signer (script-path). Takes priority over disableTweakSigner when set.

Return value

  • Promise - string: the hex string of the signed psbt

Example

typescript
try {
  let res = await okxwallet.bitcoinSignet.signPsbt('70736274ff01007d....', {
    autoFinalized: false,
    toSignInputs: [
      {
        index: 0,
        address: 'tb1q8h8....mjxzny',
      },
      {
        index: 1,
        publicKey: 'tb1q8h8....mjxzny',
        sighashTypes: [1],
      },
      {
        index: 2,
        publicKey: '02062...8779693f',
      },
    ],
  });
  console.log(res);
} catch (e) {
  console.log(e);
}

okxwallet.bitcoinSignet.signPsbt('xxxxxxxx', {
  toSignInputs: [{ index: 0, publicKey: 'xxxxxx', disableTweakSigner: true }],
  autoFinalized: false,
});

signPsbts#

okxwallet.bitcoinSignet.signPsbts(psbtHexs[, options])

Description

Signing psbts: this will traverse all inputs that match the current address to sign.

Parameters

  • psbtHexs - string[]: the hex strings of psbts to sign
Note

When you generate the psbt (string) to be signed, you need to add a public key for every input of the psbt if the input uses a Taproot address.

Example: Refer to txInput and publicKey below.

typescript
const txInputs: utxoInput[] = [];
txInputs.push({
      txId: "1e0f92720ef34ab75eefc5d691b551fb2f783eac61503a69cdf63eb7305d2306",
      vOut: 2,
      amount: 341474,
      address: "tb1q8h8....mjxzny",
      privateKey: "0s79......ldjejke",
      publicKey: "tb1q8h8....mjxzny",
      bip32Derivation: [
          {
              "masterFingerprint": "a22e8e32",
              "pubkey": "tb1q8h8....mjxzny",
              "path": "m/49'/0'/0'/0/0",
          },
      ],
  });
  • options - object[]: the options of signing psbts
    • autoFinalized - boolean: whether to finalize psbts after signing — the default is true
    • toSignInputs - array:
      • index - number: which input to sign
      • address - string: (at least specify either an address or a public key) which corresponding private key to use for signing
      • publicKey - string: (at least specify either an address or a public key) which corresponding private key to use for signing
      • sighashTypes - number[]: (optional) sighashTypes
      • useTweakedSigner - boolean: (optional) when signing Taproot inputs, true uses the tweaked signer (key-path), false uses the untweaked signer (script-path).

Return value

  • Promise - string[]: the hex strings of the signed psbts

Example

typescript
try {
  let res = await okxwallet.bitcoinSignet.signPsbts([
    '70736274ff01007d...',
    '70736274ff01007d...',
  ]);
  console.log(res);
} catch (e) {
  console.log(e);
}

deriveContextHash#

okxwallet.bitcoinSignet.deriveContextHash(appName, context)

Description

Derive a deterministic 32-byte value from the wallet's key material, current network, connected public key, appName, and context.

Parameters

  • appName - string: application identifier (1–64 bytes, [a-z0-9\-]).
  • context - string: hex-encoded bytes (lowercase, even-length, no 0x prefix, max 1024 bytes, non-empty).

Return value

  • Promise - string: 64 lowercase hex chars (32 bytes).

Example

typescript
const hash = await okxwallet.bitcoinSignet.deriveContextHash(
  'btc-vault',
  '0001020304050607'
);