caver.account
caver.account
はアカウントを更新する際に使用するアカウントに関する機能を提供するパッケージである。
クラス
Account
const account = new caver.account(address, accountKey)
Account
は、kaiaブロックチェーンプラットフォーム(kaia)のアカウントのAccountKeyを更新するために必要な情報を含むクラスです。 これは caver.account
パッケージのデフォルトクラスである。 公開鍵文字列を持つアカウント・インスタンスを作成するには、caver.account.create を参照。
プロパティ
名称 | タイプ | 説明 |
---|---|---|
address | string | 更新するアカウントのアドレス。 |
accountKey | object | アカウントで使用する新しい accountKey。 これは、AccountKeyLegacy、AccountKeyPublic、AccountKeyFail、AccountKeyWeightedMultiSig、またはAccountKeyRoleBasedのインスタンスである。 トランザクションが実行されると、kaiaに保存されているアカウントのaccountKeyがこれに変更される。 |
AccountKeyLegacy
const accountKeyLegacy = new caver.account.accountKey.accountKeyLegacy()
AccountKeyLegacy
は、KaiaのアカウントのAccountKeyをAccountKeyLegacyで更新するために使用される。 AccountKeyLegacy
を持つAccountインスタンスを作成するには、caver.account.createWithAccountKeyLegacy を参照してください。
AccountKeyPublic
const accountKeyPublic = new caver.account.accountKey.accountKeyPublic(publicKey)
AccountKeyPublic
は、kaiaのアカウントのAccountKeyをAccountKeyPublicで更新するために使用 される。 AccountKeyをAccountKeyPublic
に更新することで、既存のAccountKeyを新しい公開鍵に変更することができます。 この変更は、秘密鍵をアカウントのアドレスから切り離すときに必要です。 詳細はAccountUpdateおよびAccountKeyを参照。
AccountKeyPublic
を持つAccountインスタンスを作成するには、caver.account.createまたはcaver.account.createWithAccountKeyPublicを参照してください。
プロパティ
名称 | タイプ | 説明 |
---|---|---|
publicKey | string | 公開鍵の文字列。 |
AccountKeyFail
const accountKeyFail = new caver.account.accountKey.accountKeyFail()
AccountKeyFail
は、AccountKeyFailでカイアのアカウントのAccountKeyを更新するために使用される。 AccountKeyFail
付きのAccountインスタンスを作成するには、caver.account.createWithAccountKeyFail を参照してください。
AccountKeyWeightedMultiSig
const accountKeyWeightedMultiSig = new caver.account.accountKey.accountKeyWeightedMultiSig(threshold, weightedPublicKeys)
AccountKeyWeightedMultiSig
は、AccountKeyWeightedMultiSigを使用してkaiaのアカウントのAccountKeyを更新するために使用される。 AccountKeyWeightedMultiSig
に更新することで、既存のAccountKeyを新しい公開鍵に変更することができます。 この変更は、秘密鍵をアカウントのアドレスから切り離すときに必要です。 詳細はAccountUpdateおよびAccountKeyを参照。
AccountKeyWeightedMultiSig
を使用してAccountインスタンスを作成するには、caver.account.createまたはcaver.account.createWithAccountKeyWeightedMultiSigを参照してください。
プロパティ
名称 | タイプ | 説明 |
---|---|---|
threshold | number | 検証のしきい値。 |
weightedPublicKeys | 配列 | WeightedPublicKey] の配列。 |
AccountKeyRoleBased
const accountKeyRoleBased = new caver.account.accountKey.accountKeyRoleBased(accountKeyArray)
AccountKeyRoleBased
は、AccountKeyRoleBasedでカイアのアカウントのAccountKeyを更新するために使用される。 AccountKeyをAccountKeyRoleBased
に更新すると、ロールごとに割り当てられたAccountKeyを変更することができます。 詳しくはAccountUpdateおよびAccountKeyを参照のこと。
AccountKeyRoleBased
を使用してアカウントインスタンスを作成するには、caver.account.createまたはcaver.account.createWithAccountKeyRoleBasedを参照してください。
プロパティ
名称 | タイプ | 説明 |
---|---|---|
accountKeyArray | 配列 | 各 role で使用する accountKey を定義する配列。 各ロールは、AccountKeyLegacy、AccountKeyPublic、AccountKeyFail、またはAccountKeyWeightedMultiSigで定義できる。 |
WeightedPublicKey
const weightedPublicKey = new caver.account.accountKey.weightedPublicKey(weight, publicKey)
WeightedPublicKey
は公開鍵とその重みを含む。 WeightedPublicKey
は公開鍵と鍵の重みを含むクラスで、AccountKeyWeightedMultiSigで使用される。
プロパティ
名称 | タイプ | 説明 |
---|---|---|
weight | number | 公開鍵の重さ。 ウェイトは、公開鍵の重み付き合計がAccountKeyWeightedMultiSigオブジェクトの閾値より大きいかどうかをチェックするために使用される。 |
publicKey | string | 公開鍵の文字列。 |
WeightedMultiSigOptions
const weightedMultiSigOptions = new caver.account.weightedMultiSigOptions(threshold, weights)
WeightedMultiSigOptions
は閾値と重みを含む。 WeightedMultiSigOptions
は AccountKeyWeightedMultiSig のオプションを定義するクラスである。
プロパティ
名称 | タイプ | 説明 |
---|---|---|
threshold | number | 検証のしきい値。 |
weights | 配列 | キーの重みの配列。 |
caver.account.create
caver.account.create(address, accountKey [, options])
アドレスと accountKey を持つ Account インスタンスを生成します。
accountKey が公開鍵文字列の場合、AccountKeyPublic を accountKey とする Account インスタンスが作成される。 accountKey が公開鍵文字列を含む配列の場合、AccountKeyWeightedMultiSig を accountKey とする Account インスタンスが生成される。 最後のパラメータとしてオプションが定義されていない場合、各キーに対して、しきい値1、重み付け1のデフォルト・オプションを使用して作成される。 accountKey が、ロールごとに使用される accountKey を含む配列である場合、AccountKeyRoleBased を持つ Account インスタンスが作成されます。 オプションはWeightedMultiSigOptionsでロールごとに定義されなければならな い。 オプションが定義されていない場合、複数の公開鍵を使用するロールにはデフォルトのオプションが使用されます。 使い方は下記の例を参考にしてください。
パラメーター
名称 | タイプ | 説明 |
---|---|---|
address | string | 更新するアカウントのアドレス。 |
accountKey | string \ | Array |
options | WeightedMultiSigOptions \ | Array |
リターン・バリュー
タイプ | 説明 |
---|---|
Account | アカウントのインスタンスが返される。 |
例
// Create an Account instance with a public key string -> Account with AccountKeyPublic> caver.account.create('0x{address in hex}', '0x034f1...')Account { _address: '0xc771822ad361898a330df0169f2382ee92f6286d', _accountKey: AccountKeyPublic { _publicKey: '0x034f1...' } }// Create an Account instance with an array of public keys -> Account with AccountKeyWeightedMultiSig> caver.account.create('0x{address in hex}', ['0x034f1...', '0xfe4b8...'])Account { _address: '0xc771822ad361898a330df0169f2382ee92f6286d', _accountKey: AccountKeyWeightedMultiSig { _threshold: 1, _weightedPublicKeys: [ WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' }, WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' } ] } } // Create an Account instance with an array of public keys with WeightedMultiSigOptions -> Account with AccountKeyWeightedMultiSig> const options = new caver.account.weightedMultiSigOptions(2, [1, 1])> caver.account.create('0x{address in hex}', ['0x034f1...', '0xfe4b8...'], options)Account { _address: '0xc771822ad361898a330df0169f2382ee92f6286d', _accountKey: AccountKeyWeightedMultiSig { _threshold: 2, _weightedPublicKeys: [ WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' }, WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' } ] } }// Create an Account instance with an array in which keys to be used for each role are defined as an array -> Account with AccountKeyRoleBased> const publicKeys = [ ['0xd8510...', '0xaa105...'], ['0xd8510...'], ['0xd8510...', '0xceeee...']]> caver.account.create('0x{address in hex}', publicKeys)Account { _address: '0xc771822ad361898a330df0169f2382ee92f6286d', _accountKey: AccountKeyRoleBased { _accountKeys: [ AccountKeyWeightedMultiSig { _threshold: 1, _weightedPublicKeys: [ WeightedPublicKey { _weight: 1, _publicKey: '0xd8510...' }, WeightedPublicKey { _weight: 1, _publicKey: '0xaa105...' } ] }, AccountKeyPublic { _publicKey: '0xd8510...' }, AccountKeyWeightedMultiSig { _threshold: 1, _weightedPublicKeys: [ WeightedPublicKey { _weight: 1, _publicKey: '0xd8510...' }, WeightedPublicKey { _weight: 1, _publicKey: '0xceeee...' } ] } ] }}// Create an Account instance with an array in which keys to be used for each role are defined as an array with an array of WeightedMultiSigOptions -> Account with AccountKeyRoleBased> const publicKeys = [ ['0xd8510...', '0xaa105...'], ['0xd8510...'], ['0xd8510...', '0xceeee...']]> const options = [ new caver.account.weightedMultiSigOptions(2, [1, 1]), new caver.account.weightedMultiSigOptions(), new caver.account.weightedMultiSigOptions(3, [1, 2])]> caver.account.create('0x{address in hex}', publicKeys, options)Account { _address: '0xc771822ad361898a330df0169f2382ee92f6286d', _accountKey: AccountKeyRoleBased { _accountKeys: [ AccountKeyWeightedMultiSig { _threshold: 2, _weightedPublicKeys: [ WeightedPublicKey { _weight: 1, _publicKey: '0xd8510...' }, WeightedPublicKey { _weight: 1, _publicKey: '0xaa105...' } ] }, AccountKeyPublic { _publicKey: '0xd8510...' }, AccountKeyWeightedMultiSig { _threshold: 3, _weightedPublicKeys: [ WeightedPublicKey { _weight: 1, _publicKey: '0xd8510...' }, WeightedPublicKey { _weight: 2, _publicKey: '0xceeee...' } ] } ] }}
caver.account.createFromRLPEncoding
caver.account.createFromRLPEncoding(address, rlpEncodedKey)
RLP エンコードされた AccountKey から Account インスタンスを作成します。
パラメーター
名称 | タイプ | 説明 |
---|---|---|
address | string | 更新するアカウントのアドレス。 |
rlpEncodedKey | string | AccountKeyをRLPエンコードした文字列。 |
リターン・バリュー
タイプ | 説明 |
---|---|
Account | アカウントのインスタンスが返される。 |
例
> caver.account.createFromRLPEncoding('0x{address in hex}', '0x04f84b02f848e301a102c10b598a1a3ba252acc21349d61c2fbd9bc8c15c50a5599f420cccc3291f9bf9e301a1021769a9196f523c419be50c26419ebbec34d3d6aa8b59da834212f13dbec9a9c1')Account { _address: '0x9ea5b871e7bef65868a0d278be3fc6cdbee543ee', _accountKey: AccountKeyWeightedMultiSig { _threshold: 2, _weightedPublicKeys: [ WeightedPublicKey { _weight: 1, _publicKey: '0x02c10...' }, WeightedPublicKey { _weight: 1, _publicKey: '0x02176...' } ] }}
caver.account.createWithAccountKeyLegacy
caver.account.createWithAccountKeyLegacy(address)
AccountKeyLegacy を accountKey として持つ Account インスタンスを作成します。
パラメーター
名称 | タイプ | 説明 |
---|---|---|
address | string | 更新するアカウントのアドレス。 |
リターン・バリュー
タイプ | 説明 |
---|---|
Account | アカウントのインスタンスが返される。 |
例
> caver.account.createWithAccountKeyLegacy('0x{address in hex}')Account { _address: '0x9ea5b871e7bef65868a0d278be3fc6cdbee543ee', _accountKey: AccountKeyLegacy {}}
caver.account.createWithAccountKeyPublic
caver.account.createWithAccountKeyPublic(address, publicKey)
AccountKeyPublic を accountKey として持つ Account インスタンスを作成します。
パラメーター
名称 | タイプ | 説明 |
---|---|---|
address | string | 更新するアカウントのアドレス。 |
publicKey | string | 公開鍵の文字列。 |
リターン・バリュー
タイプ | 説明 |
---|---|
Account | アカウントのインスタンスが返される。 |
例
> caver.account.createWithAccountKeyPublic('0x{address in hex}', '0xb5a9a...')Account { _address: '0x9ea5b871e7bef65868a0d278be3fc6cdbee543ee', _accountKey: AccountKeyPublic { _publicKey: ,'0xb5a9a...' }}
caver.account.createWithAccountKeyFail
caver.account.createWithAccountKeyFail(address)
AccountKeyFail を AccountKey として持つ Account インスタンスを作成します。
パラメーター
名称 | タイプ | 説明 |
---|---|---|
address | string | 更新するアカウントのアドレス。 |
リターン・バリュー
タイプ | 説明 |
---|---|
Account | アカウントのインスタンスが返される。 |
例
> caver.account.createWithAccountKeyFail('0x{address in hex}')Account { _address: '0x9ea5b871e7bef65868a0d278be3fc6cdbee543ee', _accountKey: AccountKeyFail {}}
caver.account.createWithAccountKeyWeightedMultiSig
caver.account.createWithAccountKeyWeightedMultiSig(address, publicKeyArray [, options])
AccountKeyWeightedMultiSig を accountKey とする Account インスタンスを作成します。
パラメーター
名称 | タイプ | 説明 |
---|---|---|
address | string | 更新するアカウントのアドレス。 |
publicKeyArray | 配列 | 複数の公開鍵文字列を含む配列。 |
options | WeightedMultiSigOptions (重み付きマルチシグオプション) | (オプション) しきい値と重みの配列を定義する WeightedMultiSigOptions インスタンス。 |
リターン・バリュー
タイプ | 説明 |
---|---|
Account | アカウントのインスタンスが返される。 |
例
// create an Account instance without options> caver.account.createWithAccountKeyWeightedMultiSig('0x{address in hex}', ['0xb5a9a...', '0xfe4b8...'])Account { _address: '0xc771822ad361898a330df0169f2382ee92f6286d', _accountKey: AccountKeyWeightedMultiSig { _threshold: 1, _weightedPublicKeys: [ WeightedPublicKey { _weight: 1, _publicKey: '0xb5a9a...' }, WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' } ] } }// create an Account instance with options> const options = new caver.account.weightedMultiSigOptions(2, [1, 1])> caver.account.createWithAccountKeyWeightedMultiSig('0x{address in hex}', ['0xb5a9a...', '0xfe4b8...'], options)Account { _address: '0xc771822ad361898a330df0169f2382ee92f6286d', _accountKey: AccountKeyWeightedMultiSig { _threshold: 2, _weightedPublicKeys: [ WeightedPublicKey { _weight: 1, _publicKey: '0xb5a9a...' }, WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' } ] } }
caver.account.createWithAccountKeyRoleBased
caver.account.createWithAccountKeyRoleBased(address, roledBasedPublicKeyArray [, options])
AccountKeyRoleBased を accountKey とする Account インスタンスを作成します。
パラメーター
名称 | タイプ | 説明 |
---|---|---|
address | string | 更新するアカウントのアドレス。 |
roledBasedPublicKeyArray | 配列 | 各ロールの公開鍵文字列の配列を含む二次元配列。 |
options | 配列 | (オプション) 各ロールの WeightedMultiSigOptions インスタンスを含む配列。 |
リターン・バリュー
タイプ | 説明 |
---|---|
Account | アカウントのインスタンスが返される。 |
例
// create an Account instance without options> const publicKeys = [ ['0x034f1...', '0xfe4b8...'], ['0xb5a9a...'], ['0x034f1...', '0xb5a9a...']]> caver.account.createWithAccountKeyRoleBased('0x{address in hex}', publicKeys)Account { _address: '0xc771822ad361898a330df0169f2382ee92f6286d', _accountKey: AccountKeyRoleBased { _accountKeys: [ AccountKeyWeightedMultiSig { _threshold: 1, _weightedPublicKeys: [ WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' }, WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' } ] }, AccountKeyPublic { _publicKey: '0xb5a9a...' }, AccountKeyWeightedMultiSig { _threshold: 1, _weightedPublicKeys: [ WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' }, WeightedPublicKey { _weight: 1, _publicKey: '0xb5a9a...' } ] } ] }}// create an Account instance with options> const publicKeys = [ ['0x034f1...', '0xfe4b8...'], ['0xb5a9a...'], ['0x034f1...', '0xb5a9a...']]> const options = [ new caver.account.weightedMultiSigOptions(2, [1, 1]), new caver.account.weightedMultiSigOptions(), new caver.account.weightedMultiSigOptions(3, [1, 2])]> caver.account.createWithAccountKeyRoleBased('0x{address in hex}', publicKeys, options)Account { _address: '0xc771822ad361898a330df0169f2382ee92f6286d', _accountKey: AccountKeyRoleBased { _accountKeys: [ AccountKeyWeightedMultiSig { _threshold: 2, _weightedPublicKeys: [ WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' }, WeightedPublicKey { _weight: 1, _publicKey: '0xfe4b8...' } ] }, AccountKeyPublic { _publicKey: '0xb5a9a...' }, AccountKeyWeightedMultiSig { _threshold: 3, _weightedPublicKeys: [ WeightedPublicKey { _weight: 1, _publicKey: '0x034f1...' }, WeightedPublicKey { _weight: 2, _publicKey: '0xb5a9a...' } ] } ] }}