使用 PIXA Keychain 开发。

你的应用提出请求,用户在钱包自己的窗口里阅读,回调函数收到回复。你从不持有密钥,也无需注册。

正在此浏览器中查找 PIXA Keychain

查找钱包

扩展程序会添加 window.pixa_keychain 到每个 https:// 页面,开发时也支持 localhost 和 127.0.0.1。它在页面加载后才会出现,请稍等再判断是否不存在。

如果不存在,请链接到 pixtopia.net/keychain。它不支持手机,请为手机用户保留其他入口。

JavaScript
async function findKeychain(ms = 2000) {
  const end = Date.now() + ms;
  while (!window.pixa_keychain && Date.now() < end) {
    await new Promise((resolve) => setTimeout(resolve, 100));
  }
  return window.pixa_keychain ?? null;
}

让用户登录

你的服务器生成一次性消息,钱包用用户的发帖密钥签名,服务器再用链上该账号的密钥验证签名。不会广播任何内容,也没有费用。

  • 将账号传为 null,用户就能在钱包中选择账号。回复的 data.username 会说明选了哪个。
  • 钱包会原样显示你的消息,所以请写给人看,并写明你的网站名称。
  • 让消息只能用一次,并设定过期时间,防止签名被重放。
  • 始终在服务器上验证。页面无法分辨真正的扩展程序与冒充它的脚本;在签名验证前,data.username 只是一项未经证实的声明。
在浏览器中
const keychain = await findKeychain();
if (!keychain) return showGetTheWallet();

// A request opens a window, so only do this after a tap.
const { message } = await post('/auth/challenge');

keychain.requestSignBuffer(null, message, 'Posting', async (answer) => {
  if (!answer.success) return; // They said no.
  await post('/auth/verify', {
    account: answer.data.username,
    message,
    signature: answer.result,
  });
});
在你的服务器上(Node)
import { secp256k1 } from '@noble/curves/secp256k1.js';
import { ripemd160 } from '@noble/hashes/legacy.js';
import { sha256 } from '@noble/hashes/sha2.js';
import { hexToBytes, utf8ToBytes } from '@noble/hashes/utils.js';
import { base58 } from '@scure/base';

// The key that made a signature. Pixa keys look like PIX...
function recoverKey(message, signature) {
  const bytes = hexToBytes(signature);
  bytes[0] -= 31; // Pixa, like Hive, adds 31 to the recovery number.
  const point = secp256k1.recoverPublicKey(
    bytes,
    sha256(utf8ToBytes(message)),
    { prehash: false },
  );
  const withCheck = new Uint8Array(37);
  withCheck.set(point);
  withCheck.set(ripemd160(point).slice(0, 4), 33);
  return 'PIX' + base58.encode(withCheck);
}

async function verifySignIn({ account, message, signature }) {
  // First make sure this is a message you issued, unused and unexpired.
  const response = await fetch('https://api.pixagram.com', {
    method: 'POST',
    body: JSON.stringify({
      jsonrpc: '2.0',
      id: 1,
      method: 'condenser_api.get_accounts',
      params: [[account]],
    }),
  });
  const [onChain] = (await response.json()).result;
  if (!onChain) return false;

  const key = recoverKey(message, signature);
  const { key_auths, weight_threshold } = onChain.posting;
  const entry = key_auths.find(([known]) => known === key);
  return Boolean(entry) && entry[1] >= weight_threshold;
}

在这里试试

这里会在本页真实执行同样的流程:用你的发帖密钥签署测试消息,从签名恢复公钥,再到链上查找。不会广播任何内容,签名也不会保存或发送到任何地方。

签署测试消息

签名并发送

常见操作只需提出请求,钱包就会构建交易,用清楚易懂的文字说明,签名后通过用户自己的节点广播。

  • requestVote 用于点赞,权重从 -10000 到 10000。
  • requestCustomJson 用于关注和应用自有数据。会显示你的消息、ID 和数据。
  • requestPost 用于帖子和回复。
  • requestTransfer 及其他资金请求。
  • requestBroadcast 用于其他任何操作。
  • requestSignTx 用于需要自行广播的情况。

在 requestPost 中设置帖子的奖励选项,每次确认时都会显示。必须指定该作者和 permlink。

关注操作
const follow = JSON.stringify(['follow', {
  follower: account,
  following: 'pixtopia',
  what: ['blog'],
}]);

keychain.requestCustomJson(
  account,
  'follow',
  'Posting',
  follow,
  'Follow @pixtopia',
  (answer) => {
    if (answer.success) showFollowing(answer.result.tx_id);
  },
);
由你自行广播的交易
const node = 'https://api.pixagram.com';
const call = async (method, params) =>
  (await (await fetch(node, {
    method: 'POST',
    body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }),
  })).json()).result;

const { head_block_number, head_block_id } =
  await call('condenser_api.get_dynamic_global_properties', []);
const prefix = head_block_id
  .slice(8, 16).match(/../g).reverse().join('');
const expires = new Date(Date.now() + 600000);

const transaction = {
  ref_block_num: head_block_number & 0xffff,
  ref_block_prefix: parseInt(prefix, 16),
  expiration: expires.toISOString().slice(0, 19),
  operations: [
    ['vote', { voter: account, author, permlink, weight: 5000 }],
  ],
  extensions: [],
};

keychain.requestSignTx(account, transaction, 'Posting', async (answer) => {
  if (answer.success) {
    await call('condenser_api.broadcast_transaction', [answer.result]);
  }
});

该请求哪种密钥

只请求你需要的最低权限。用户会留意。

发帖

点赞、发帖、回复、关注和你自己的 custom_json。这是唯一可使用“不再询问”的密钥。

活跃

资金与治理:转账、储蓄、能量、委托和见证人投票。始终打开确认窗口。

备注

加密和读取私信。始终打开确认窗口。

所有者

始终拒绝。钱包不保管所有者密钥,所以不要构建依赖它的功能。

读取回复

每个回调收到一个对象。先检查 success,再使用 result。

字段含义
success成功时为 true
result请求产生的结果,例如签名或广播结果
error失败原因
message可显示给用户的一句话
data钱包收到的原始请求
publicKey签名的公钥(如有)
request_id此请求的编号

你需要处理的错误

user_cancel用户拒绝了。无需再提示。
incomplete请求无效。message 说明原因。
ignored本页的较新请求替换了此请求。
busy上一个请求已在发送。请等待。
使用 Promise,一次一个请求
// A page gets one request at a time, so they wait their turn.
let line = Promise.resolve();

function ask(send) {
  const turn = line.then(() => new Promise((resolve, reject) => {
    send(window.pixa_keychain, (answer) => {
      if (answer.success) return resolve(answer);
      const error = new Error(answer.message);
      error.code = answer.error;
      reject(error);
    });
  }));
  line = turn.catch(() => undefined);
  return turn;
}

const answer = await ask((keychain, done) =>
  keychain.requestVote(account, permlink, author, 5000, done));

需要了解的规则

  • 不要主动弹出请求。请求会打开窗口,所以必须由用户的操作触发。
  • 一次一个。新请求会替换仍在等待用户回应的旧请求,旧请求返回 ignored。如果上一请求已在发送,新请求会被拒绝并返回 busy。
  • 金额是带三位小数的字符串("1.000"),单位为 PIXA 和 PXS。委托单位为 PP 或 VESTS。使用 HIVE 或 HBD 的请求会被拒绝。
  • 消息按文本原样签署,与用户看到的完全一致。钱包不会从 JSON 解码字节,并会拒绝以 Pixa 链 ID 开头的文本,因为它可能被签成交易。
  • 读取数据由你负责。余额、帖子和账号请自行查询 Pixa 节点。钱包只负责签名。
  • 节点由用户选择。仍接受 rpc,但会忽略它。
  • 标题由钱包提供。title 在 requestSignBuffer 中也会被忽略。网站文字只会作为值显示,不能冒充钱包的说明。
  • 权重在权限请求中必须是 1 到 65535 的整数。
  • 读不懂时会明确说明。钱包无法描述的操作会显示警告及原始交易,也不能预先批准。这包括 custom_json 通过 requestBroadcast 或 requestSignTx 发送的情况,除非是关注或门户操作。请改用 requestCustomJson 发送应用自有数据,用户能看到你的消息,也能选择不再询问这个 ID。

从 Hive Keychain 迁移

请求结构相同,大多数网站只需重命名全局变量并使用 Pixa 的代币。两个扩展程序可以在同一浏览器中运行,因为这里没有任何名称与 Hive Keychain 共用。

  • 使用 PIXA 和 PXS,以及 pixa 和 pxs,后两者用于 percent_pxs 这样的字段名。
  • 公钥以 PIX 开头,节点是 api.pixagram.com。
  • requestSignedCall 已禁用。请使用 requestBroadcast 或 requestSignTx。
  • 这里没有 Hive Engine、兑换、多重签名或 HiveAuth。
最主要的那一行改动
const keychain = window.pixa_keychain;

测试你的应用

代码仓库有一个页面,为每种请求提供表单。从本地地址提供该页面,并在安装了扩展程序的浏览器中打开。

其中的请求是真实的,你的应用发送的请求也一样。请使用不存有任何重要资产的测试账号。

终端
git clone https://github.com/elmerlin/pixa-keychain.git
cd pixa-keychain/example
python3 -m http.server 1337
# Then open http://localhost:1337/main.html

所有请求

大多数方法以账号为第一个参数,回调函数接近末尾,后面是可选参数。

查找钱包与签署消息

requestHandshake检查钱包是否存在,不打开窗口。
参数类型含义
callbackfunction确认 Keychain 已安装(无参数)
requestSignBuffer签署消息,用于让用户登录。
参数类型含义
account(可选)String执行请求的 Pixa 账号。为 null 时,用户可从下拉列表选择账号
messageString由账号签署的消息
keyString密钥类型。可以是 'Posting'、'Active' 或 'Memo'
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
title(可选)String忽略。钱包自行提供标题
requestVerifyKey请求钱包解码消息,以证明它持有密钥。
参数类型含义
accountString执行请求的 Pixa 账号
messageString由账号解码的消息
keyString密钥类型。可以是 'Posting'、'Active' 或 'Memo'
callbackfunction处理钱包请求回复的函数
示例
const keychain = window.pixa_keychain;
keychain.requestVerifyKey('pixtopia', encodedMessage, 'Posting', (response) => {
  if (response.success === true) {
    const decodedMessage = response.result;
  }
});
requestEncodeMessage为另一个账号加密消息。
参数类型含义
usernameString执行请求的 Pixa 账号
receiverString将解码字符串的账号
messageString要加密的消息,必须以 # 开头
keyString密钥类型。可以是 'Posting'、'Active' 或 'Memo'
callbackfunction处理钱包请求回复的函数
示例
const keychain = window.pixa_keychain;
const message = '#' + username + Date.now();
keychain.requestEncodeMessage(username, myUsername, message, 'Memo', (response) => {
  if (response.success) {
    const encodedMessage = response.result;
    // Send message to a server where you can use your private key to decode it
  }
});
requestEncodeWithKeys为多个公钥加密消息。
参数类型含义
usernameString执行请求的 Pixa 账号
publicKeysArray<String>可解码字符串的密钥
messageString要加密的消息,必须以 # 开头
keyString密钥类型。可以是 'Posting'、'Active' 或 'Memo'
callbackfunction处理钱包请求回复的函数
示例
const keychain = window.pixa_keychain;
const message = '#' + username + Date.now();
keychain.requestEncodeWithKeys(username, [pubKey1, pubKey2], message, 'Memo', (response) => {
  if (response.success) {
    const encodedMessages = response.result;
    // Send message to a server where you can use your private key to decode it
  }
});

帖子与社交

requestPost发布帖子或回复。
参数类型含义
accountString执行请求的 Pixa 账号
titleString帖子标题
bodyString帖子内容
parent_permString父帖的 permlink。根帖则为主标签
parent_accountString父帖作者。根帖请传 ''
json_metadataString帖子的元数据,格式为 JSON
permlinkString帖子的 permlink
comment_optionsString此帖的奖励设置,格式为 JSON 或 ''。必须指定此作者和 permlink,并会显示在确认页面
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
const keychain = window.pixa_keychain;
keychain.requestPost(
  'pixtopia',
  'Hello World!',
  'This is a blog post',
  'blog',
  '',
  JSON.stringify({ format: 'markdown', tags: ['blog'] }),
  'hello-world',
  JSON.stringify({
    author: 'pixtopia',
    permlink: 'hello-world',
    max_accepted_payout: '100000.000 PXS',
    percent_pxs: 10000,
    allow_votes: true,
    allow_curation_rewards: true,
    extensions: [[0, { beneficiaries: [{ account: 'pixa.team', weight: 1000 }] }]],
  }),
  (response) => {
    console.log(response);
  },
);
requestVote为帖子点赞或踩。
参数类型含义
accountString执行请求的 Pixa 账号
permlinkString帖子的 permlink
authorString帖子作者
weightNumber投票权重,介于 -10,000(-100%)和 10,000(100%)之间
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
// Upvote with 50% weight
const keychain = window.pixa_keychain;
keychain.requestVote('pixa.team', 'hello-world', 'pixtopia', 5000, (response) => {
  console.log(response);
});
requestCustomJson广播 custom_json,例如关注操作或应用自有数据。
参数类型含义
account(可选)String执行请求的 Pixa 账号。为 null 时,用户可从下拉列表选择账号
idString要广播的 custom_json 类型
keyString密钥类型。可以是 'Posting' 或 'Active'
jsonString序列化为字符串的自定义 JSON
display_msgString向用户说明此次广播内容的消息
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
const keychain = window.pixa_keychain;
keychain.requestCustomJson(null, 'my-app', 'Posting', JSON.stringify({ action: 'hello' }), 'Say hello in My App', (response) => {
  console.log(response);
});

任何交易

requestBroadcast在一笔交易中广播任意操作。
参数类型含义
accountString执行请求的 Pixa 账号
operationsArray要广播的操作数组
keyString密钥类型。可以是 'Posting' 或 'Active'
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
const keychain = window.pixa_keychain;
keychain.requestBroadcast('pixa.team', [
  [
    'account_witness_vote',
    {
      account: 'pixa.team',
      witness: 'pixtopia',
      approve: true
    }
  ]
], 'Active', (response) => {
  console.log(response);
});
requestSignTx签署你准备的交易,由你广播。
参数类型含义
accountString执行请求的 Pixa 账号
txObject未签名交易
keyString密钥类型。可以是 'Posting' 或 'Active'
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
// This example would be done much easier with requestBroadcast
const node = 'https://api.pixagram.com';
const call = async (method, params) =>
  (await (await fetch(node, {
    method: 'POST',
    body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }),
  })).json()).result;

const { head_block_number, head_block_id } = await call('condenser_api.get_dynamic_global_properties', []);
const prefix = head_block_id.slice(8, 16).match(/../g).reverse().join('');
const tx = {
  ref_block_num: head_block_number & 0xffff,
  ref_block_prefix: parseInt(prefix, 16),
  expiration: new Date(Date.now() + 600000).toISOString().slice(0, 19),
  operations: [...], // Add operations here
  extensions: [],
};
window.pixa_keychain.requestSignTx(username, tx, 'Posting', async (response) => {
  if (response.success) {
    await call('condenser_api.broadcast_transaction', [response.result]);
  }
});
requestSignedCall已禁用。请使用 requestBroadcast 或 requestSignTx。

资金

requestTransfer发送 PIXA 或 PXS。
参数类型含义
accountString执行请求的 Pixa 账号
toString接收转账的 Pixa 账号
amountString要转账的金额,必须有 3 位小数。
memoString如果备注以 '#' 开头且 Keychain 中有备注密钥,就会自动加密。无论 'enforce' 参数如何,这也会强制使用指定账号
currencyString'PIXA' 或 'PXS'
callbackfunction处理钱包请求回复的函数
enforce(可选)boolean设为 true 时,用户不能选择其他账号进行转账
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
const keychain = window.pixa_keychain;
keychain.requestTransfer(username, toUsername, '1.000', '', 'PIXA', (response) => {
  console.log(response)
}, true);
requestRecurrentTransfer设置定期转账。
参数类型含义
username(可选)String执行请求的 Pixa 账号
toString接收转账的 Pixa 账号。
amountString每次执行发送的金额。
currencyString主网上的 PIXA 或 PXS。
memoString转账备注
recurrenceNumber付款间隔(小时),最少 24。
executionsNumber定期付款的执行次数,最少 2。
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
pair_id(可选)Number定期转账的配对 ID
示例
// Let's send @pixtopia 5 PIXA a day
if (window.pixa_keychain) {
  const keychain = window.pixa_keychain;
  keychain.requestRecurrentTransfer(null, 'pixtopia', '5.000', 'PIXA', '', 24, 7, (response) => {
    console.log(response);
  });
} else {
  alert('PIXA Keychain is not installed');
}
requestSavingsOperation将 PIXA 或 PXS 存入或取出储蓄。
参数类型含义
usernameString执行请求的 Pixa 账号
toString接收储蓄转账的账号
amountString要转账的金额,必须有 3 位小数。
currencyString'PIXA' 或 'PXS'
operationString'deposit' 或 'withdraw'
memo(可选)String储蓄操作附带的备注
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
const keychain = window.pixa_keychain;
keychain.requestSavingsOperation(username, toUsername, '1.000', 'PXS', 'deposit', 'test memo', (response) => {
  console.log(response);
});
requestConversion在 PXS 和 PIXA 之间兑换。
参数类型含义
usernameString执行请求的 Pixa 账号
amountString要兑换的金额。
collaterizedBooleantrue 表示将 PIXA 兑换为 PXS,false 表示将 PXS 兑换为 PIXA。
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
// Convert 5 PIXA to PXS
if (window.pixa_keychain) {
  const keychain = window.pixa_keychain;
  keychain.requestConversion(username, '5.000', true, (response) => {
    console.log(response);
  });
} else {
  alert('PIXA Keychain is not installed');
}

能量与委托

requestPowerUp将 PIXA 转为 Pixa Power。
参数类型含义
usernameString执行请求的 Pixa 账号
recipientString接收能量的账号
hiveString要转为能量的 PIXA 数量
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
// Power up 5 PP
if (window.pixa_keychain) {
  const keychain = window.pixa_keychain;
  keychain.requestPowerUp(username, username, '5.000', (response) => {
    console.log(response);
  });
} else {
  alert('PIXA Keychain is not installed');
}
requestPowerDown开始将 Pixa Power 转回 PIXA。
参数类型含义
usernameString执行请求的 Pixa 账号
hive_powerString要解除能量的 PIXA 数量
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
// Power down 5 PP
if (window.pixa_keychain) {
  const keychain = window.pixa_keychain;
  keychain.requestPowerDown(username, '5.000', (response) => {
    console.log(response);
  });
} else {
  alert('PIXA Keychain is not installed');
}
requestDelegation向另一个账号借出 Pixa Power。
参数类型含义
username(可选)String执行请求的 Pixa 账号。为 null 时,用户可从下拉列表选择账号
delegateeString接收委托的账号
amountString要转移的金额。PP 必须有 3 位小数,VESTS 必须有 6 位。
unitStringPP 或 VESTS
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
if (window.pixa_keychain) {
  const keychain = window.pixa_keychain;
  keychain.requestDelegation(null, 'pixtopia', '1.000', 'PP', (response) => {
    console.log(response);
  });
} else {
  alert('PIXA Keychain is not installed');
}

治理

requestWitnessVote为见证人投票,或撤回投票。
参数类型含义
username(可选)String执行请求的 Pixa 账号。为 null 时,用户可从下拉列表选择账号
witnessString接收见证人投票的账号
votebooleantrue 表示为见证人投票,false 表示撤回
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
// Unvote our witness vote for @pixtopia
if (window.pixa_keychain) {
  const keychain = window.pixa_keychain;
  keychain.requestWitnessVote(null, 'pixtopia', false, (response) => {
    console.log(response);
  });
} else {
  alert('PIXA Keychain is not installed');
}
requestProxy设置代理人,代账号投票。
参数类型含义
username(可选)String执行请求的 Pixa 账号。为 null 时,用户可从下拉列表选择账号
proxyString成为代理人的账号。空字符串('')表示移除代理人
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
// Let @pixtopia use our voting power in governance votes
if (window.pixa_keychain) {
  const keychain = window.pixa_keychain;
  keychain.requestProxy(null, 'pixtopia', (response) => {
    console.log(response);
  });
} else {
  alert('PIXA Keychain is not installed');
}
// Remove voting proxy
if (window.pixa_keychain) {
  const keychain = window.pixa_keychain;
  keychain.requestProxy(null, '', (response) => {
    console.log(response);
  });
} else {
  alert('PIXA Keychain is not installed');
}
requestCreateProposal为 Pixa 基金创建提案。
参数类型含义
usernameString执行请求的 Pixa 账号
receiverString提案获投票通过后接收资金的账号
subjectString提案标题
permlinkString提案描述的 permlink
daily_payStringreceiver 每日收到的金额,例如 '10.000 PXS'
startString开始日期,例如 '2027-01-01T00:00:00'
endString结束日期,格式相同
extensionsString序列化为字符串的扩展数组
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
if (window.pixa_keychain) {
  const keychain = window.pixa_keychain;
  keychain.requestCreateProposal('pixtopia', 'pixtopia', 'PIXA Keychain development', 'pixa-keychain-proposal', '10.000 PXS', '2027-01-01T00:00:00', '2027-12-31T00:00:00', JSON.stringify([]), (response) => {
    console.log(response);
  });
} else {
  alert('PIXA Keychain is not installed');
}
requestRemoveProposal移除账号自己的提案。
参数类型含义
usernameString执行请求的 Pixa 账号
proposal_idsString要移除的提案 ID 数组,序列化为字符串
extensionsString序列化为字符串的扩展数组
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
if (window.pixa_keychain) {
  const keychain = window.pixa_keychain;
  keychain.requestRemoveProposal(username, JSON.stringify([216]), JSON.stringify([]), (response) => {
    console.log(response);
  });
} else {
  alert('PIXA Keychain is not installed');
}
requestUpdateProposalVote为提案投票,或撤回投票。
参数类型含义
usernameString执行请求的 Pixa 账号
proposal_idsString要投票的提案 ID 数组,序列化为字符串
approvebooleantrue 表示支持提案,false 表示撤回投票
extensionsString序列化为字符串的扩展数组
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
// Approve a proposal
if (window.pixa_keychain) {
  const keychain = window.pixa_keychain;
  keychain.requestUpdateProposalVote(username, JSON.stringify([216]), true, JSON.stringify([]), (response) => {
    console.log(response);
  });
} else {
  alert('PIXA Keychain is not installed');
}
// Unapprove a proposal
if (window.pixa_keychain) {
  const keychain = window.pixa_keychain;
  keychain.requestUpdateProposalVote(username, JSON.stringify([216]), false, JSON.stringify([]), (response) => {
    console.log(response);
  });
} else {
  alert('PIXA Keychain is not installed');
}

账号及其控制权

requestAddAccount提议将账号密钥添加到钱包。
参数类型含义
usernameString要添加的账号用户名
keysObject账号的私钥:{active:'...',posting:'...',memo:'...'}。必须指定至少一个。也可以用 @${username} 指定授权账号。
callbackfunction处理钱包请求回复的函数
示例
if (window.pixa_keychain) {
  const postingKey = '...';
  const keychain = window.pixa_keychain;
  keychain.requestAddAccount(username, {
    posting: postingKey
  }, (response) => {
    console.log(response);
  });
} else {
  alert('PIXA Keychain is not installed');
}
requestCreateClaimedAccount使用账号票创建账号。
参数类型含义
usernameString执行请求的 Pixa 账号
new_accountString要创建的新账号
ownerString所有者权限,格式为 JSON
activeString活跃权限,格式为 JSON
postingString发帖权限,格式为 JSON
memoString备注公钥
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
requestAddAccountAuthority给予另一个账号对此账号的权限。
参数类型含义
accountString执行请求的 Pixa 账号
authorizedUsernameString获授权的账号
roleString权限类型。可以是 'Posting' 或 'Active'
weightnumber权限权重
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
// Gives @pixtopia active authority with weight 2 to `account`
const keychain = window.pixa_keychain
keychain.requestAddAccountAuthority(account, 'pixtopia', 'Active', 2, (response) => {
  console.log(response);
});
requestRemoveAccountAuthority撤销某个账号的权限。
参数类型含义
accountString执行请求的 Pixa 账号
authorizedUsernameString将失去权限的账号
roleString权限类型。可以是 'Posting' 或 'Active'
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
// Removes @pixtopia's active authority from `account`
const keychain = window.pixa_keychain;
keychain.requestRemoveAccountAuthority(account, 'pixtopia', 'Active', (response) => {
  console.log(response);
});
requestAddKeyAuthority向此账号的权限中添加公钥。
参数类型含义
accountString执行请求的 Pixa 账号
authorizedKeyString要关联到账号的新公钥
roleString权限类型。可以是 'Posting' 或 'Active'
weightnumber密钥权限的权重
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
const keychain = window.pixa_keychain;
keychain.requestAddKeyAuthority(username, publicKey, 'Posting', 1, (response) => {
  console.log(response);
});
requestRemoveKeyAuthority从此账号的权限中移除公钥。
参数类型含义
accountString执行请求的 Pixa 账号
authorizedKeyString要移除的密钥(公钥)。
roleString权限类型。可以是 'Posting' 或 'Active'
callbackfunction处理钱包请求回复的函数
rpc(可选)String忽略。钱包始终使用用户自己的节点
示例
const keychain = window.pixa_keychain;
keychain.requestRemoveKeyAuthority(username, publicKey, 'Posting', (response) => {
  console.log(response);
});

遇到困难,或发现缺漏?

提交问题或修复,所有内容都在 GitHub。如果你用它做了什么,我们很想看看:在 Pixa 上找 @pixtopia。