arJWK
配置项功能
此配置项用于通过 arweave 钱包 来操作 everPay arweave 账户模型
的 账户,对该账户进行:
- 充值:使用
arJWK
进行 arweave 转账 至 everPay arweave 锁仓地址(通过门限签名实现了多签)。 - 转账:使用
arJWK
进行 arweaveRSA-PSS SHA-256
签名,来确保该 everPay 账户的操作权限。 - 提现:使用
arJWK
进行 arweaveRSA-PSS SHA-256
签名,来确保该 everPay 账户的操作权限。
配置项类型
everpay-js 集成了 arweave-js 用于 arweave 签名、发送交易。
此配置项类型:
export type ArJWK = JWKInterface | 'use_wallet'
使用 arweave-js JWKInterface
作为其中之一的同时,也使用了一个 'use_wallet'
字符串作为参数,用于适配 Chrome 浏览器 arweave 插件钱包 ArConnect(一个类似 MetaMask 的钱包工具)。
如何配置
JWKInterface 方式
arweave 的私钥格式,一个 KEY JSON,例如:
const arAddress = 'GRQ7swQO1AMyFgnuAPI7AvGQlW3lzuQuwlJbIpWV7xk'
const arJWK = {
kty: 'RSA',
e: 'AQAB',
n: 'ovFF6EbOtXeg7VnojIgtChgxfU6GZ16JjVj5JFHh6NGHJnq4p059BnMphcDx1mqb3yxM73FxhEszSFLcJiPzway6eIDiXuYiT-Sf_0Wl6_wDLvEmlz43psp7WYJumwpaSyiI_1FWmOVQnTnoAIKaOYKVqzUlteiECQj7XjJl0MZH16RlEfVqVpJ_8Ier4_QXIJ8Y3pe2KF3Lg9UANFU97nuvEM94CSzX-0WIju6Lykt3DBb2YtFFg4bJjOFv3T38nCZmDh8lYjm25_1qILalsB0XRoDxQy9FLxWb4zd09JsDhL0EYAQ_hNfOnQFVOBtYEHVYMCHYH6GoTcNgxmUkZPk4AfpAqZmjDzKfVJrw4Fr68pPTEQOQEzBcIWp61P21BSkhqO4QuFinkQsSH6NdTB_3FpbhYf34Hjf-iH7hdpdWo4aoRLb8eZeZcqBRZoRmlhQnOD-PVxQR_vb9rjXSjGkCWwRbsurVLWdBh_FQn0S9Q6EHqiV8nbW-R0Rk2E76JwgMFkqGUtZj8DeEqXJ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sT18GkMH4B6PXDHBAhsNrRh2O0XOeWsfZStoyj5Mdt3b9JJfPFMW3h38yQ_lrmKYZQfJQ',
qi: 'aDsPYxE-JBYsYhCYXSU7WsCrnFxNsRpFMcYXdmdryYIdQUpeemChDGzVJXLnJhE4cAS9TtLcNg82xZSKZvHrnkbFpRfSJxzEnvIXW4V0LHkxkxbmM0e9B7UrpYm6LKtvEY6I7L8wHFpHdOwV6NjY925oULEV156X0r55V7N0XF-jy3rbm71DCWRh6IDRghhCZQ3aNgJxE-OtnABqasaY6CQnTDRXLkGE0kq9GCx85-92fQLHMzvrMhr9m_2MHYJ_gZehL4j95CQzhD3Zh602D0YYYwRSsU4h5HGjlmN52pe-rfTLgwCJq5295s7qUP8TTMzbZAOM_hehksHpAaFghA'
}
const everpay = new Everpay({
account: arAddress,
chainType: 'arweave',
arJWK: arJWK
})
私钥泄漏风险
此方式在代码中明文传递私钥(arJWK),存在安全风险。
浏览器 + ArConnect
当用户 浏览器安装了 ArConnect 后,可以传递 arJWK: 'use_wallet'
来指定使用 ArConnect 进行 arweave 转账(对应 everPay 充值)、签名(对应 everPay 转账与提现) 操作。
- Typescript
- Javascript
const checkArPermissions = async (permissions: string[] | string): Promise<void> => {
let existingPermissions: string[] = []
const isString = (content: any) => {
return Object.prototype.toString.call(content) === "[object String]"
}
permissions = isString(permissions) ? [permissions] : permissions
try {
existingPermissions = await window.arweaveWallet.getPermissions()
} catch {
throw new Error('PLEASE_INSTALL_ARCONNECT')
}
if (permissions.length === 0) {
return
}
if (
permissions.some((permission) => {
return !existingPermissions.includes(permission)
})
) {
await window.arweaveWallet.connect(permissions as never[])
}
}
await checkArPermissions([
'ACCESS_ADDRESS',
'ACCESS_ALL_ADDRESSES',
'ACCESS_PUBLIC_KEY',
'SIGN_TRANSACTION',
'SIGNATURE'
])
const arAddress = await window.arweaveWallet.getActiveAddress()
const everpay = new Everpay({
account: arAddress,
chainType: 'arweave',
arJWK: 'use_wallet'
})
const checkArPermissions = async (permissions) => {
let existingPermissions = []
const isString = (content) => {
return Object.prototype.toString.call(content) === "[object String]"
}
permissions = isString(permissions) ? [permissions] : permissions
try {
existingPermissions = await window.arweaveWallet.getPermissions()
} catch {
throw new Error('PLEASE_INSTALL_ARCONNECT')
}
if (permissions.length === 0) {
return
}
if (
permissions.some((permission) => {
return !existingPermissions.includes(permission)
})
) {
await window.arweaveWallet.connect(permissions)
}
}
await checkArPermissions([
'ACCESS_ADDRESS',
'ACCESS_ALL_ADDRESSES',
'ACCESS_PUBLIC_KEY',
'SIGN_TRANSACTION',
'SIGNATURE'
])
const arAddress = await window.arweaveWallet.getActiveAddress()
const everpay = new Everpay({
account: arAddress,
chainType: 'arweave',
arJWK: 'use_wallet'
})
为什么 要使用 'use_wallet'?
- arweave-js 也支持在浏览器端使用
'use_wallet'
作为jwk
参数,来使用 ArConnect 获取 arweave 钱包地址,以及进行 arweave 转账、签名。详见arweave-js Search · use_wallet - everpay-js 集成了 arweave-js,来进行 arweave 转账,使用
'use_wallet'
可让 arweave-js 去调用 ArConnect,从而减少开发者适配 ArConnect 的成本。 - 在 Web 端,使用
'use_wallet'
代表的 ArConnect,更安全。