Skip to Content
dApps
このページの内容

署名

dApp API の使用前に enable() を呼び出してください。CIP-30 API が返すアドレスは 16 進数エンコードされたバイト列です。トランザクションと値のパラメーターは、16 進数エンコードされた CBOR です。Buffer を使用するブラウザーの例には、明示的な buffer インポート、またはバイト変換ヘルパーが必要です。

Cardano で認証用データに署名する方法を説明します。


データに署名 (CIP-8)

認証のために任意のデータに署名します:

const api = await window.cardano.onekey.enable() const addresses = await api.getUsedAddresses() const address = addresses[0] // Message to sign const payload = Buffer.from('Hello Cardano!').toString('hex') const signature = await api.signData(address, payload) console.log({ signature: signature.signature, // COSE_Sign1 signature key: signature.key, // COSE_Key public key })

署名を検証

import { COSESign1, COSEKey } from '@emurgo/cardano-message-signing-browser' const coseSign1 = COSESign1.from_bytes( Buffer.from(signature.signature, 'hex') ) const coseKey = COSEKey.from_bytes( Buffer.from(signature.key, 'hex') ) // Get the signed payload const signedPayload = coseSign1.payload() // Verify signature // Parsing COSE is not verification. Use a CIP-8 verifier to check the // protected headers, signing structure, payload, signature, and address binding.

エラー処理

try { const api = await window.cardano.onekey.enable() } catch (error) { if (error.code === -3) { console.log('The wallet refused the request') } else if (error.code === -4) { console.log('The account changed; reconnect and retry') } else { console.error('Error:', error.message) } }

主なエラー

コード説明
-1無効なリクエスト
-2内部エラー
-3拒否されたリクエスト
-4アカウント変更時
最終更新日