caver.account는 계정 업데이트시 사용 되며 Account에 관련된 기능을 제공하는 패키지입니다.
Class
계정
const account = new caver.account(address, accountKey)
Account는 Klaytn 계정의 AccountKey를 업데이트하기 위해 필요한 정보를 포함하는 클래스입니다. caver.account 패키지의 기본 클래스입니다. 공개키(들)을 이용해 Account 인스턴스를 만들고자 한다면 caver.account.create를 참고하세요.
속성
Name
Type
Description
address
string
업데이트 할 계정의 주소입니다.
accountKey
object
AccountKeyLegacy
const accountKeyLegacy = new caver.account.accountKey.accountKeyLegacy()
const accountKeyPublic = new caver.account.accountKey.accountKeyPublic(publicKey)
AccountKeyPublic는 AccountKeyPublic를 이용해 Klaytn 계정의 AccountKey를 업데이트할 때 사용됩니다. AccountKey를 AccountKeyPublic로 업데이트하면 기존의 AccountKey가 새로운 공개키로 바뀌며, 이는 Klaytn 트랜잭션 검증에 사용됩니다. 계정의 개인키를 주소로부터 분리할 때 필요한 업데이트입니다. 자세한 사항은 AccountUpdate와 AccountKey를 참고하세요.
const accountKeyWeightedMultiSig = new caver.account.accountKey.accountKeyWeightedMultiSig(threshold, weightedPublicKeys)
AccountKeyWeightedMultiSig는 AccountKeyWeightedMultiSig를 사용해 Klaytn 계정의 AccountKey를 업데이트할 때 사용합니다. AccountKey를 AccountKeyWeightedMultiSig로 업데이트하면 기존의 AccountKey가 새로운 공개키로 바뀌며, 이는 Klaytn 트랜잭션 검증에 사용됩니다. This change is necessary when you decouple your private key from the address of your account. See AccountUpdate and AccountKey for details.
const accountKeyRoleBased = new caver.account.accountKey.accountKeyRoleBased(accountKeyArray)
AccountKeyRoleBased는 AccountKeyRoleBased를 통해 Klaytn 계정의 AccountKey를 업데이트할 때 사용됩니다. AccountKey를 AccountKeyRoleBased로 업데이트함으로써 Klaytn 트랜잭션 검증에 사용되는 각 역할에 할당된 AccountKey(들)을 변경할 수 있습니다. 자세한 사항은 AccountUpdate와 AccountKey를 참고하세요.
accountKey가 공개키 문자열인 경우, accountKey가 AccountKeyPublic인 Account 인스턴스가 생성됩니다. accountKey가 공개키 문자열을 포함한 배열인 경우, accountKey가 AccountKeyWeightedMultiSig인 Account 인스턴스가 생성됩니다. 옵션들이 마지막 파라미터로 정의되지 않은 경우 기본값으로 임계값이 1, 각 키의 가중치가 1로 설정되어 생성됩니다. accountKey가 각 역할에 사용되는 accountKeys를 포함한 배열인 경우, AccountKeyRoleBased를 지닌 Account 인스턴스가 생성됩니다. 옵션들은 WeightedMultiSigOptions를 통해 각 역할에 정의되어야 합니다. 옵션들이 정의되어 있지 않다면, 다수의 공개키를 사용하는 역할들에 대해 기본 옵션이 사용됩니다. 사용법은 아래 예시를 참고하세요.
Parameters
Name
Type
Description
address
string
The address of account to be updated.
accountKey
string | Array
공개키 문자열, 공개키(들)의 배열, 또는 각 요소가 각 역할에 사용될 키(들) 의 배열을 포함하는 2차원 배열입니다.
options
(선택 사항) AccountKeyWeigthedMultiSig에 대한 옵션들입니다.
Return Value
Type
Description
Account 인스턴스가 반환됩니다.
Example
// 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...' }
]
}
]
}
}