@cardano-foundation/cardano-verify-datasignature

中文文档
1.0.11发布于 2022/12/21Apache-2.0TypeScriptESM + CJS近 30 天下载 1.9万

A lightweight typescript library to verify a cip30 datasignature for browser and nodejs

原始使用文档
文档目录4 节
  1. 🚀 Getting Started
  2. 🧐 Verification
  3. How to get a cip30 datasignature?
  4. What does it mean "to verify a signature"?

Cardano Verify Datasignature

Release semantic-release: angular

A lightweight typescript library to verify a cip30 datasignature.

🚀 Getting Started

npm i @cardano-foundation/cardano-verify-datasignature

🧐 Verification

You need a key and a signature from a cip30 datasignature.

How to get a cip30 datasignature?

There are multiple ways to create a cip30 data signature:

  1. Make sure you have a cip30 compatible wallet installed (Nami, NuFi, Typhon Wallet, Flint, Gerowallet, Yoroi, ...).

  2. Option A: Open your browser console and copy&paste this function:

const signMessage = async (message, walletname) => {
  const api = await window.cardano[walletname].enable();
  const hexAddresses = await api.getRewardAddresses();
  const hexAddress = hexAddresses[0];
  let hexMessage = '';

  for (var i = 0, l = message.length; i < l; i++) {
    hexMessage += message.charCodeAt(i).toString(16);
  }

  try {
    const { signature, key } = await api.signData(hexAddress, hexMessage);
    console.log(signature, key);
  } catch (error) {
    console.warn(error);
  }
};

Usage example:

signMessage('Hello World', 'yoroi').then((dataSignature) =>
  console.log(dataSignature)
);
  1. Option B: Use the signMessage function of the cardano-connect-with-wallet library to get a valid key and signature.

  2. Option C: If you want to use the cli to sign or verify data please checkout the cardano-signer by gitmachtl.

What does it mean "to verify a signature"?

This function uses the public key (COSE_KEY) and checks if its corresponding private key has been used to sign the payload (data/message) within the signature (COSE_Sign1).

Furthermore an optional plain text message can be provided to check if both the plain text and the signed message are equal.

Another optional argument is a readable (bech32) address starting with (addr1/addr_test1/stake1/stake_test1) to test if this address belongs to the key that was used to sign the message.

const verifyDataSignature = require('@cardano-foundation/cardano-verify-datasignature');

const key =
  'a4010103272006215820b89526fd6bf4ba737c55ea90670d16a27f8de6cc1982349b3b676705a2f420c6';
const signature =
  '84582aa201276761646472657373581de118987c1612069d4080a0eb247820cb987fea81bddeaafdd41f996281a166686173686564f458264175677573746120416461204b696e672c20436f756e74657373206f66204c6f76656c61636558401712458b19f606b322982f6290c78529a235b56c0f1cec4f24b12a8660b40cd37f4c5440a465754089c462ed4b0d613bffaee3d1833516569fda4852f42a4a0f';
const message = 'Augusta Ada King, Countess of Lovelace';
const address = 'stake1uyvfslqkzgrf6syq5r4jg7pqewv8l65phh024lw5r7vk9qgznhyty';

console.log(verifyDataSignature(signature, key)); // true
console.log(verifyDataSignature(signature, key, message)); // true
console.log(verifyDataSignature(signature, key, message, address)); // true
console.log(
  verifyDataSignature(
    signature,
    key,
    message,
    'stake1_test1hweafkafrwf9ets85rs9gtk9qgzegwtg'
  )
); // false
console.log(
  verifyDataSignature(signature, key, 'Augusta Ada King, Countess of Lovelace!')
); // false

版本与发布记录

@cardano-foundation/cardano-verify-datasignature 共发布 12 个版本,首次发布于 2022/12/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.11latest2022/12/213 年前
1.0.102022/12/213 年前
1.0.92022/12/203 年前
1.0.82022/12/203 年前
1.0.72022/12/193 年前
1.0.62022/12/183 年前

关于 @cardano-foundation/cardano-verify-datasignature 的常见问题

@cardano-foundation/cardano-verify-datasignature 是什么?

A lightweight typescript library to verify a cip30 datasignature for browser and nodejs

如何安装 @cardano-foundation/cardano-verify-datasignature?

在项目目录运行 npm install @cardano-foundation/cardano-verify-datasignature,或使用 pnpm add / yarn add / bun add。

@cardano-foundation/cardano-verify-datasignature 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cardano-foundation/cardano-verify-datasignature 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cardano-foundation/cardano-verify-datasignature 可以商用吗?

@cardano-foundation/cardano-verify-datasignature 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@cardano-foundation/cardano-verify-datasignature 的下载量有多少?

根据 npm 官方下载统计,@cardano-foundation/cardano-verify-datasignature 在 2026/10/09 – 2026/11/07 这 30 天内被下载 19,253 次,日均约 642 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cardano-foundation/cardano-verify-datasignature 还在维护吗?

最新版本 1.0.11 发布于 2022/12/21(3 年前);至今共发布 12 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/12/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。