1.4.3 • Published 7 months ago

arweave-account v1.4.3

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

Arweave Account

中文版

ℹ️ This npm package is paired with the permadapp Account.

Arweave Account is a composible and customizable profile protocol (DID) on Arweave. It relies on the native gateways operations to write and retrieve users data.

Who uses it?

Here is some example of the same profile displayed by different applications in the ecosystem:

PermaDappvisual
now
Permanotes
Metaweave

ℹ️ ❕

Do you know an application using Arweave Account? Feel free to add it to the list via a PR ❤️


Documentation

ℹ️ If it's your first time trying arweave-account, we recommend to try the interactive documentation.

If you're in for a deeper look at arweave account, you are at the right place

Installation & Import

Installation

npm install arweave-account

Usage

import Account from 'arweave-account'

const account = new Account();

If you are using Typescript, see typescript imports section.

Optional object initializer

In some cases, you may want to pass an object to the constructor to customize the library behavior. Here is the list of available options:

Property nameDefault valuedescription
cacheIsActivatedtrueIf true, the library will cache the latest account data for each wallet address. This is useful to avoid unnecessary requests to the gateway.
cacheSize100The maximum number of cached account data.
cacheTime60000The time in milliseconds before the cache is invalidated.
gateway{ host: 'arweave.net', port: 443, protocol: 'https', timeout: 20000, logging: false }The gateway used to fetch account data.
defaultAvatarUri"ar://OrG-ZG2WN3wdcwvpjz1ihPe4MI24QBJUpsJGIdL85wA"The default avatar URI used when user has no avatar set.
defaultBannerUri"ar://a0ieiziq2JkYhWamlrUCHxrGYnHWUAMcONxRmfkWt-k"The default banner URI used when user has no banner set.

Basic usages

Get user profile by wallet address

await account.get(walletAddr);

Search user profile by handle name

await account.search(handle);

Find user profile by wallet address & handle name

await account.find(handle#uniqID);

Example: Display user's avatar, handle name and bio

import Account from 'arweave-account'

const account = new Account()

(async () => {
  const user = await account.get(await arweaveWallet.getActiveAddress())

  setHandle(user.handle);
  setAvatar(user.profile.avatarURL);
  setbio(user.profile.bio);
})()

Creation/update flow

With the 3 methods above, you are able to display any arweave account without requiring your user to even have an Arweave wallet. A permanent application is available for your users to create and update their arweave account profile. Further more, we have made available a redirection link that will bring your users to the latest deployed version of the permadapp.

ℹ️ What is a permanent application?

Feel free to make your own redirection link with your own branding or create an issue to enhance the onboarding flow so everyone can benefit from it.

Although, if you want to implement your own onboarding flow right inside your app, the arweave-account, see the following Advanced usages section.

Advanced usages

Connect the user wallet

await account.connect(jwk?);

If no argument is passed, account will use the injected arweaveWallet object. In that case, make sure you have handled the wallet connection flow with the right permissions before calling this method to avoid any unexpected behavior.

Create/update arweave account profile

await account.updateProfile(profileObj, tags?);

Make sure connect() is called before.

ℹ️ Optionaly you can pass an array of tags to be added to the transaction. This is useful if you want to attach Asset Discoverability (ANS-110) or even a Stampable Asset.

Example: Update user's handle name and bio

If the user doesn't have an account, it will create it.

import Account, {ArAccount} from 'arweave-account'

const account = new Account()

(async () => {
  const user: ArAccount = await account.get(await arweaveWallet.getActiveAddress())

  displayProfile(user.profile);

  await account.connect();
  user.profile.handleName = "DMac"
  user.profile.bio = "Accelerating the worlds transition to decentralized messaging"
  await account.updateProfile(user.profile)
})()

Note

The advanced usages are only compatible with wallets injecting the arweaveWallet object with dispatch().

ℹ️ If you wish having more wallets compatible, feel free to open a discussion here (issue) or DM me on discord: cromatikap#6039

References

Typescript imports

import { ArAccount, ArProfile } from 'arweave-account';

ArAccount object

When getting account information, the library request the relevant transaction through the gateway, decode the information stored and return an account object formatted the following way:

Property nameNo account default valuedescription
txidnullCurrent transaction associated with the arweave account
addrtx.owner.addressWallet address of the arweave account
handletruncated wallet address (ex: aIUm...zdog)Unique handle derived from profile.handleName and the wallet address (ex: cromatikap#aIUdog)
profile-ArProfile object
apps-WIP from this discussion: maybe named storage?

ArProfile object

Property nameNo account default valuedescription
avatar"ar://OrG-ZG2WN3wdcwvpjz1ihPe4MI24QBJUpsJGIdL85wA"picture URI of the user avatar supporting multiple protocols
avatarURL"https://arweave.net/OrG-ZG2WN3wdcwvpjz1ihPe4MI24QBJUpsJGIdL85wA"Out of the box URL picture of the user avatar
banner"ar://a0ieiziq2JkYhWamlrUCHxrGYnHWUAMcONxRmfkWt-k"picture URI of the user banner supporting multiple protocols
bannerURL"https://arweave.net/a0ieiziq2JkYhWamlrUCHxrGYnHWUAMcONxRmfkWt-k"Out of the box URL picture of the user banner
handleName""The handle name chosen by the user, this is a required constituent to generate account unique handle
name""A secondary name
bio""Biography information
links{}user social links
wallets{}Other wallet addresses for crosschain identification

avatar and banner properties

Image properties such as avatar and banner can refer to an NFT from different chains. The following protocols are supported:

  • http://
  • https://
  • ar://

ℹ️ If you wish to add other protocol, we would be happy to do so. Please feel free to reach out!

❣️ Also, the Metaweave team gives grants for merged Pull Requests.

For each image property, an https URL is generated according to the original URI provided. You can access it with the suffix URL.

For example:

Property namevalue
profile.avatarar://xqjVvn9b8hmtDJhfVw80OZzAsn-ErpWbaFCPZWG5vKI
profile.avatarURLhttps://arweave.net/xqjVvn9b8hmtDJhfVw80OZzAsn-ErpWbaFCPZWG5vKI

Data protocol

Account is a simple native data protocol on Arweave. It consists of a simple transaction containing the latest data state. A wallet key is attached to its own latest write with the tag Protocol-Name: 'Account-<version>'

Exemple:

Request the latest updated account profile using ArQL

{
  transactions(
    first: 1
    tags: [{name:"Protocol-Name",values:"Account-0.2"}]
  ) {
    edges {
      node {
        id
        owner {
          key
          address
        }
        tags {
          name
          value
        }
        block {
          timestamp
        }
      }
    }
  }
}

Data architecture

In the arweave account protocol, a set of data representing the user profile is encoded to be stored in a transaction and decoded to a ArAccount type object.

Here is an exemple of an encoded and decoded account dataset for the wallet aIUmY9Iy4qoW3HOikTy6aJww-mM4Y-CUJ7mXoPdzdog:

Encoded arweave account data (written on-chain)

{
  "handle":"cromatikap",
  "avatar": "ar://xqjVvn9b8hmtDJhfVw80OZzAsn-ErpWbaFCPZWG5vKI",
  "banner": "ar://a0ieiziq2JkYhWamlrUCHxrGYnHWUAMcONxRmfkWt-k",
  "name":"Axel",
  "bio":"Founder of Metaweave.xyz\nI love dogs",
  "links": {
    "twitter":"cromatikap",
    "github":"cromatikap",
    "instagram":"cromatikap",
    "discord":"cromatikap#6039",
    "linkedin": "",
    "facebook": "",
    "youtube": "",
    "twitch": ""
  },
  "wallets": {
    "eth": "0xeEEe8f7922E99ce6CEd5Cb2DaEdA5FE80Df7C95e"
  }
}

Decoded arweave account data

Here is the dataset you get by using the library

{
  "txid": "NPJJoq-9EwUeAce_bSbSyqICaGs4_7Hg6VxCyoCY8UQ",
  "addr": "aIUmY9Iy4qoW3HOikTy6aJww-mM4Y-CUJ7mXoPdzdog",
  "handle": "cromatikap#aIUdog",
  "profile": {
    "avatar": "ar://xqjVvn9b8hmtDJhfVw80OZzAsn-ErpWbaFCPZWG5vKI",
    "avatarURL": "https://arweave.net/xqjVvn9b8hmtDJhfVw80OZzAsn-ErpWbaFCPZWG5vKI",
    "banner": "ar://a0ieiziq2JkYhWamlrUCHxrGYnHWUAMcONxRmfkWt-k",
    "bannerURL": "https://arweave.net/a0ieiziq2JkYhWamlrUCHxrGYnHWUAMcONxRmfkWt-k",
    "handleName": "cromatikap",
    "name": "Axel",
    "bio": "Founder of Metaweave.xyz\nI love dogs",
    "links": {
      "twitter": "cromatikap",
      "github": "cromatikap",
      "instagram": "cromatikap",
      "discord": "cromatikap#6039",
      "linkedin": "",
      "facebook": "",
      "youtube": "",
      "twitch": ""
    },
    "wallets": {
      "eth": "0xeEEe8f7922E99ce6CEd5Cb2DaEdA5FE80Df7C95e",
    }
  }
}

For convenience, the related txid and wallet addr is added. As well, you have access to the full unique handle derived from the user chosen handle and their wallet address

Migrate from 1.2.5 to 1.3.x

  1. The unique handle (name#xxxxxx) is at the Account level

account.profile.handle -> account.handle

The unique handle derived from the user chosen handle name and their wallet address is now accessible at the account level.

In the account.profile object, a new property handleName is available which constitutes the name part only of the user handle.

  1. URL ressources comes auto generated

You no longer need to craft an URL from the avatar property. The library now delivers an URL ready to use in any standard tag

1.4.3

7 months ago

1.4.2

7 months ago

1.4.1

8 months ago

1.4.0

10 months ago

1.3.6

1 year ago

1.3.5

1 year ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.3.0-rc.2

2 years ago

1.3.0-rc.3

2 years ago

1.3.0-rc.0

2 years ago

1.3.0-rc.1

2 years ago

1.2.0

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago