0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Signing and Verifying Arbitrary Data

0
Last updated at Posted at 2024-12-07

Previous << Transactions
Next >> WalletConnect 2.0 Manual Configuration

Signing Arbitrary Data

暗号署名はブロックチェーンの重要な要素です。秘密鍵を公開することなくアドレスの所有を証明するために使用されます。主にトランザクションの署名に使用されますが、暗号署名は任意のメッセージの署名にも使用できます。

FCLには、設定されたウォレットorサービスに対して任意のデータを送信し、ユーザーが秘密鍵を使って署名することを承認できる機能があります。

Verifying User Signatures

メッセージの署名をより面白いものにしているのは、私たちはFlowブロックチェーンを使って、署名を検証することができることです。Cadenceには、publicKey.verifyという組み込み関数が用意されており、引数として渡したアカウントのアドレスのFlowアカウントに対して署名を検証することができます。

FCLには、Flowブロックチェーン上のアカウントの公開鍵に対して1つまたは複数の署名を検証するための、AppUtils.verifyUserSignaturesというユーティリティ関数が含まれています。

両者を併用することで、ユーザーが秘密鍵を管理していることを証明することができます。

これにより、ユーザーの公開アドレスをIDとするメッセージ署名ベースの認証メカニズムを使用した暗号学的に安全なログイン・フローが可能となります。

currentUser.signUserMessage()

FCL対応ウォレット/サービス経由でユーザーが直接署名することができるメソッド。

Note:認証済みの署名サービスでの認証/設定が必要です。(Requires authentication/configuration with an authorized signing service.)

Arguments

Name Type Description
message string A hexadecimal string to be signed

Returns

Type Description
Array An Array of CompositeSignatures (signature)

Usage

import * as fcl from "@onflow/fcl"

const signMessage = async () => {
  const MSG = Buffer.from("FOO").toString("hex")
  try {
    return await fcl.currentUser.signUserMessage(MSG)
  } catch (error) {
    console.log(error)
  }
}

AppUtils.verifyUserSignatures

Note
⚠️ この API を使用するには、fcl.config.flow.network または options override が必要です。 FCL Configurationを参照してください。

メッセージがユーザーの秘密鍵によって署名されていることを検証することで、 Flow アカウントの所有を暗号学的にアプリケーションが検証できるようにしたメソッド。これは通常、currentUser.signUserMessage のレスポンスと一緒に使用されます。

Arguments

Name Type Description
message string (required) A hexadecimal string
compositeSignatures Array (required) An Array of CompositeSignatures
opts Object (optional) opts.fclCryptoContractを指定することで、ローカル開発用のFCLCryptoContractアドレスを上書きすることができます。

Returns

Type Description
Boolean true if verified or false

Usage

/**
 * Verify a valid signatures for an account on Flow.
 *
 * @param {string} msg - A message string in hexadecimal format
 * @param {Array} compSigs - An array of Composite Signatures
 * @param {string} compSigs[].addr - The account address
 * @param {number} compSigs[].keyId - The account keyId
 * @param {string} compSigs[].signature - The signature to verify
 * @param {Object} [opts={}] - Options object
 * @param {string} opts.fclCryptoContract - An optional override of Flow account address where the FCLCrypto contract is deployed
 * @return {bool}
 *
 * @example
 *
 *  const isValid = await fcl.AppUtils.verifyUserSignatures(
 *    Buffer.from('FOO').toString("hex"),
 *    [{f_type: "CompositeSignature", f_vsn: "1.0.0", addr: "0x123", keyId: 0, signature: "abc123"}],
 *    {fclCryptoContract}
 *  )
 */

Examples
使用例としては、暗号ログイン(cryptographic login)、メッセージの検証、検証可能なクレデンシャルなどがあります。

Last updated on Nov 26, 2024 by Giovanni Sanchez

翻訳元


Previous << Transactions

Flow blockchain / Cadence version1.0ドキュメント (Signing and Verifying Arbitrary Data)

Next >> WalletConnect 2.0 Manual Configuration

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?