0.7.7 • Published 2 years ago

@communitiesid/id v0.7.7

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Communities ID SDK

Install

npm i @communitiesid/id

Usage

Initialze

import CommunitiesID from '@communitiesid/id';

const OPTIONS: CommunitiesIDInput = {
  isTestnet: false,
  openseaKey: '<Your opensea api key>',
  Ethereum: {
    RPCUrl: '<Your rpc url for this chain>'
  },
  Polygon: {
    RPCUrl: '<Your rpc url for this chain>'
  },
  Base: {
    RPCUrl: '<Your rpc url for this chain>'
  },
  OP: {
    RPCUrl: '<Your rpc url for this chain>'
  },
  BSC: {
    RPCUrl: '<Your rpc url for this chain>'
  },
  Scroll: {
    RPCUrl: '<Your rpc url for this chain>'
  },
  // This is for resolve name for space id only
  arbitrum: {
    RPCUrl: '<Your rpc url for this chain>'
  },
}

const { resolver, collector, operator } = new CommunitiesID(options);

You can also initialize it with provider (except arbitrum, because it is only used for resolve name for space id)

const OPTIONS: CommunitiesIDInput = {
  isTestnet: false,
  openseaKey: '<Your opensea api key>',
  Ethereum: {
    provider: new ethers.providers.JsonRpcProvider('xxx')
  },
  ...
}

If you want to use this sdk on communitiesID testnet, you can initialize it like this:

const OPTIONS: CommunitiesIDInput = {
  isTestnet: true,
  openseaKey: '<Your opensea api key>',
  Goerli: {
    RPCUrl: '<Your rpc url for this chain>',
  },
  'Polygon Mumbai': {
    RPCUrl: '<Your rpc url for this chain>',
  },
  'Base Goerli Testnet': {
    RPCUrl: '<Your rpc url for this chain>',
  },
  'Optimism Goerli Testnet': {
    RPCUrl: '<Your rpc url for this chain>',
  },
  'BNB Smart Chain Testnet': {
    RPCUrl: '<Your rpc url for this chain>',
  },
  'Scroll Sepolia Testnet': {
    RPCUrl: '<Your rpc url for this chain>',
  }
}

collector

collector.searchBrandDID

Get the brand DID info by name

Input:

NameTypeDescriptionrequired
namestringThe name of the brand DIDtrue

Output: Promise<BrandDID | null>

Example:

const res = await collector.searchBrandDID('did')

collector.searchBrandDIDByTokenId

Get the brand DID info by name

Input:

NameTypeDescriptionrequired
tokenIdnumberThe token ID of this brand DIDtrue
chainIdSupportedChainIdsThe chain ID that that this brand DID is ontrue

Output: Promise<BrandDID | null>

Example:

const res = await collector.searchBrandDIDByTokenId(1, 80001)

collector.searchUserDID

Get the user DID info by name

Input:

NameTypeDescriptionrequired
namestringThe name of the user DID, the format should be ${userDID}.${brandDID}true

Output: Promise<UserDID | null>

Example:

const res = await collector.searchUserDID('a.did')

collector.searchUserDIDByTokenId

Get the brand DID info by name

Input:

NameTypeDescriptionrequired
registrystringThe registry address of this user DIDtrue
tokenIdnumberThe token ID of this brand DIDtrue
chainIdSupportedChainIdsThe chain ID that that this brand DID is ontrue

Output: Promise<UserDID | null>

Example:

const res = await collector.searchUserDIDByTokenId('0x123...', 1, 80001)

collector.getAllBrandDIDs

Get all brand DID in specific chain, if you call this on mainnet, opensea Key is required

Input:

NameTypeDescriptionrequired
chainIdSupportedChainIdsThe chain ID that you want to get brand DIDstrue

Output: Promise<object[]>

Example:

const res = await collector.getAllBrandDIDs(5)

collector.getAllBrandDIDsOwnedByAddress

Get all brand DIDs owned by an address in specific chain, if you call this on mainnet, opensea Key is required

Input:

NameTypeDescriptionrequired
addressstringThe address you want to get brand DIDstrue
chainIdSupportedChainIdsThe chain ID that you want to get brand DIDstrue

Output: Promise<object[]>

Example:

const res = await collector.getAllBrandDIDsOwnedByAddress('0x0000000000000000000000000000000000000000', 5)

collector.getAllUserDIDsOwnedByAddress

Get all user DIDs owned by an address in specific chain, if you call this on mainnet, opensea Key is required

Input:

NameTypeDescriptionrequired
addressstringThe address you want to get user DIDstrue
chainIdSupportedChainIdsThe chain ID that you want to get brand DIDstrue

Output: Promise<object[]>

Example:

const res = await collector.getAllUserDIDsOwnedByAddress('0x0000000000000000000000000000000000000000', 5)

collector.getAllBrandDIDsJoinedByAddress

Get all brand DIDs joined by an address in specific chain, if you call this on mainnet, opensea Key is required

Input:

NameTypeDescriptionrequired
addressstringThe address you want to get brand DIDstrue
chainIdSupportedChainIdsThe chain ID that you want to get brand DIDstrue

Output: Promise<object[]>

Example:

const res = await collector.getAllBrandDIDsJoinedByAddress('0x0000000000000000000000000000000000000000', 5)

collector.getAllUserDIDsOwnedByBrand

Get all user DIDs under specific brand DID, if you call this on mainnet, opensea Key is required

Input:

NameTypeDescriptionrequired
namestringThe name of the brand DID, if registry and chain is provided, the name will be ignored, and the query efficiency will improvetrue
registrystringThe registry of this brand DIDfalse
chainIdSupportedChainIdsThe chain ID that you want to get brand DIDsfalse

Output: Promise<object[]>

Example:

const res = await collector.getAllUserDIDsOwnedByBrand('did')
const res = await collector.getAllUserDIDsOwnedByBrand('', '0x123', 5)

collector.getAllUserDIDsOfOneWalletInOneBrand

Get all user DIDs owned by specific address under specific brand DID

Input:

NameTypeDescriptionrequired
addressstringhe address you want to get user DIDstrue
namestringThe name of the brand DID, if registry and chain is provided, the name will be ignored, and the query efficiency will improvetrue
registrystringThe registry of this brand DIDfalse
chainIdSupportedChainIdsThe chain ID that you want to get brand DIDsfalse

Output: Promise<object[]>

Example:

const res = await collector.getAllUserDIDsOfOneWalletInOneBrand('0x123', 'did')
const res = await collector.getAllUserDIDsOfOneWalletInOneBrand('0x123', '', '0x123', 5)

resolver

resolver.resolveName

Get the owner of a userDID. If not found in communities ID, it will find in ens. If you pass binance or arbitrum rpc url, it will also find address in space id.

Input:

NameTypeDescriptionrequired
namestringThe name of the userDID, the format should be ${userDID}.${brandDID}true

Output: Promise<string | null>

Example:

const res = await resolver.resolveName('a.did')

resolver.lookupAddress

Get primary did of an address. If not found in communities ID, it will find in ens. If you pass binance or arbitrum rpc url, it will also find address in space id.

Input:

NameTypeDescriptionrequired
addressstringThe address of the user DIDtruetrue

Output: Promise<string | null>

Example:

const res = await resolver.lookupAddress('0x0000000000000000000000000000000000000000')

operator

operator.setSigner

Set signer for write operation. For some secnarios, like frontend, we are not able to get the private key of the user, so we need to set signer for write operation.

Input:

NameTypeDescriptionrequired
signerethers.Signerethers.Signer objecttrue

Example:

communitiesidSDK.operator.setSigner(signer)

operator.getMintUserDIDPrice

Get the price of minting a user DID

Input:

NameTypeDescriptionrequired
namestringThe name of the user DIDtrue
optionsobjectmint optionsfalse
options.brandDIDobjectthe brand DID object from searchBrandDID, if not pass it, the method will call searchBrandDID itselffalse

Example:

const res = await operator.getMintUserDIDPrice('test.did')
const brandDID = await collector.searchBrandDID('did')
const res = await operator.getMintUserDIDPrice('test.did', { brandDID })

operator.mintUserDID

Mint a user DID (This is a write method, the generateSigner function of the chain which this user DID on is required)

Input:

NameTypeDescriptionrequired
namestringThe name of the user DIDtrue
mintTostringThe address that you want mint this user DID totrue
optionsMintUserDIDOptionsmint optionsfalse
options.signaturestringThe signature to mint user DIDfalse
options.ownerstringThe owner in signaturefalse
options.mintPriceBigNumber | number | stringThe price to mint this brand DID, if you do not pass this, this function will get the price by itselffalse
options.refundRecipientstringIf you passed higher value than mint price, the excees part will transfer to this wallet, default is address of signerfalse
options.brandDIDBrandDIDThe brand DID that this user DID belongs to, if you do not pass this, this function will get the brand DID by itselffalse
options.txConfigObjectThe config for sending transactionfalse
options.onTransactionCreated(transaction: object) => anyThe callback function when the transaction is createdfalse

Example:

const res = await operator.mintUserDID('test.did', '0x123456')

operator.getRenewUserDIDPrice

Get the price of renew a user DID

Input:

NameTypeDescriptionrequired
namestringThe name of the user DIDtrue
optionsobjectmint optionsfalse
options.userDIDobjectthe user DID object from searchuserDID, if not pass it, the method will call searchuserDID itselffalse

Example:

const res = await operator.getRenewUserDIDPrice('test.did')
const userDID = await collector.searchUserDID('test.did')
const res = await operator.getRenewUserDIDPrice('test.did', { userDID })

operator.renewUserDID

Mint a user DID (This is a write method, the generateSigner function of the chain which this user DID on is required)

Input:

NameTypeDescriptionrequired
namestringThe name of the user DIDtrue
optionsRenewUserDIDOptionsrenew optionsfalse
options.mintPriceBigNumber | number | stringThe price to mint this brand DID, if you do not pass this, this function will get the price by itselffalse
options.brandDIDBrandDIDThe brand DID that this user DID belongs to, if you do not pass this, this function will get the brand DID by itselffalse
options.userDIDUserDIDThe user DID object that you want to renew, if you do not pass this, this function will get the brand DID by itselffalse
options.refundRecipientstringIf you passed higher value than mint price, the excees part will transfer to this wallet, default is address of signerfalse
options.txConfigObjectThe config for sending transactionfalse
options.onTransactionCreated(transaction: object) => anyThe callback function when the transaction is createdfalse

Example:

const res = await operator.renewUserDID('test.did')

operator.burnUserDID

Burn a user DID (This is a write method, the generateSigner function of the chain which this user DID on is required)

Input:

NameTypeDescriptionrequired
namestringThe name of the user DIDtrue
optionsBurnUserDIDOptionsburn optionsfalse
options.brandDIDBrandDIDThe brand DID that this user DID belongs to, if you do not pass this, this function will get the brand DID by itselffalse
options.txConfigObjectThe config for sending transactionfalse
options.onTransactionCreated(transaction: object) => anyThe callback function when the transaction is createdfalse

Example:

const res = await operator.burnUserDID('test.did')

operator.setAsPrimary

Set a user DID as primary (This is a write method, the generateSigner function of the chain which this user DID on is required)

Input:

NameTypeDescriptionrequired
namestringThe name of the user DIDtrue
optionsobjectsetAsPrimary optionsfalse
options.txConfigObjectThe config for sending transactionfalse
options.onTransactionCreated(transaction: object) => anyThe callback function when the transaction is createdfalse

Example:

const res = await operator.setAsPrimary('test.did')
0.7.6

2 years ago

0.7.5

2 years ago

0.7.7

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.4

2 years ago

0.7.3

2 years ago

0.7.0

2 years ago

0.6.2

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.14

2 years ago

0.5.13

2 years ago

0.5.12

2 years ago

0.5.11

2 years ago

0.5.10

2 years ago

0.5.9

2 years ago

0.5.8

2 years ago

0.5.7

2 years ago

0.5.6

2 years ago

0.5.5

2 years ago

0.5.4

2 years ago

0.5.3

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.8

2 years ago