Skip to content

Instantly share code, notes, and snippets.

@nekomeowww
Last active April 2, 2021 09:55
Show Gist options
  • Save nekomeowww/57faf84254995245cef35249185698ab to your computer and use it in GitHub Desktop.
Save nekomeowww/57faf84254995245cef35249185698ab to your computer and use it in GitHub Desktop.
Arweave Owner to Address
import Arweave from 'arweave'
const arweave = Arweave.init({
host: 'arweave.net',
port: 443,
protocol: 'https',
timeout: 20000,
logging: false
})
/**
* Convert the value of owner field from Arweave transaction to Arweave Address
* @param {String} owner - owner field from Arweave transaction
* @returns - Arweave address
*/
async function ownerToAddress(owner) {
const pubJwk = {
kty: 'RSA',
e: 'AQAB',
n: owner,
}
return await arweave.wallets.getAddress(pubJwk)
}
@nekomeowww
Copy link
Author

中文注释的版本:

import Arweave from 'arweave'

const arweave = Arweave.init({
  host: 'arweave.net',
  port: 443,
  protocol: 'https',
  timeout: 20000,
  logging: false
})

/**
 * 将 Arweave 交易中 owner 字段的值转换为 Arweave 钱包地址
 * @param {String} owner - Arweave 交易中 owner 字段的值
 * @returns         - Arweave 钱包地址
 */
async function ownerToAddress(owner) {
  const pubJwk = {
      kty: 'RSA',
      e: 'AQAB',
      n: owner,
  }
  
  return await arweave.wallets.getAddress(pubJwk)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment