반응형
Transaction
객체를 생성하고Keypair
객체를 제공하면,sendAndConfirmTransaction
함수를 통해 서명과 동시에 전송이 된다.- HSM 처럼 개인키를 네트워크에 전송하지 못하는 경우에는 솔라나 서명 알고리즘 (Ed25519) 를 제공하는
tweetnacl
패키지를 통해서 서버사이드에서 서명하여raw transaction
에signature
를 동봉하여 보내게 된다. - 이 때 사용하는 함수는
web3
의sendAndConfirmRawTransaction
이다.
서명 오류
[Nest] 13400 - 05/16/2022, 6:16:46 PM ERROR [ExceptionsHandler] Signature verification failed
Error: Signature verification failed
at Transaction.serialize (/home/gus/solana_middleware/node_modules/@solana/web3.js/src/transaction.ts:666:13)
at mintGenerativeNft (/home/gus/solana_middleware/src/solana-nft/commands/mint-nftV2.ts:344:42)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at SolanaNftService.mintGenerativeNft (/home/gus/solana_middleware/src/solana-nft/solana-nft.service.ts:32:16)
at SolanaNftController.mintGenerative (/home/gus/solana_middleware/src/solana-nft/solana-nft.controller.ts:16:16)
at /home/gus/solana_middleware/node_modules/@nestjs/core/router/router-execution-context.js:46:28
at /home/gus/solana_middleware/node_modules/@nestjs/core/router/router-proxy.js:9:17
sendAndConfirmRawTransaction
함수를 실행할 때Transaction
객체에서 요구하는signer
들의 서명을 모두 동봉하지 않으면 위와 같은 에러가 발생한다.
Transaction {
signatures: [
{
signature: <Buffer 41 2b 65 dc 91 f6 07 71 29 4c 09 a0 19 37 0d 60 09 e4 b5 d2 38 06 ae 29 63 f1 ed e1 50 88 40 69 8e 9d 04 49 0b ef d0 d6 29 4f c6 38 fa c4 5c 3c bc 09 ... 14 more bytes>,
publicKey: [PublicKey]
},
{
signature: <Buffer e3 16 69 ba ef 6b ea ea fe 0d 43 21 38 47 25 0d d1 f4 ae f9 e6 13 20 6d 25 c5 53 49 d6 e9 ab 27 b3 59 26 dd 5c f7 96 ed 8e 7f 5f 46 5a e8 1b ce c1 76 ... 14 more bytes>,
publicKey: [PublicKey]
}
],
feePayer: PublicKey {
_bn: <BN: e24c40aed6fb86b5a0897e1947aa942032cc4facd666f0a948b202297192f9c7>
},
instructions: [
TransactionInstruction {
keys: [Array],
programId: [PublicKey],
data: <Buffer 00 00 00 00 f0 1d 1f 00 00 00 00 00 a5 00 00 00 00 00 00 00 06 dd f6 e1 d7 65 a1 93 d9 cb e1 46 ce eb 79 ac 1c b4 85 ed 5f 5b 37 91 3a 8c f5 85 7e ff ... 2 more bytes>
},
TransactionInstruction {
keys: [Array],
programId: [PublicKey],
data: <Buffer 01>
},
TransactionInstruction {
keys: [Array],
programId: [PublicKey],
data: <Buffer 07 01 00 00 00 00 00 00 00>
}
],
recentBlockhash: '3sxwC1KiYEUNxZPTZ7b8EFb3mYLoZyis5YcdbjAvtscy',
nonceInfo: undefined,
_message: undefined,
_json: undefined
}
- 전송하기 위한
Transaction
객체를 분석해보면signatures
들이 존재한다. - 성공적인 서명은
feePayer
와TransactionInstruction
중keys
에서 명시된isSigner
역할이 부여된 키 들로 전부 서명했을 경우이다.
Payer GENaXC37Q8L2mQAkRkJebudNKPZELwU3H1sVD1Hno7JN
Instruction [0]
key { GENaXC37Q8L2mQAkRkJebudNKPZELwU3H1sVD1Hno7JN isSigner true isWritable true
key { 4fK7n3haNyFvBcyYrmAep5YDz2qPyK3ovRnF6PoRZRj2 isSigner true isWritable true
Instruction [1]
key { 4fK7n3haNyFvBcyYrmAep5YDz2qPyK3ovRnF6PoRZRj2 isSigner false isWritable true
key { AL3iZrc5QW1UMXSWUgzcVKbxikdwRwdqhzBP7PNgNaWB isSigner false isWritable false
key { GENaXC37Q8L2mQAkRkJebudNKPZELwU3H1sVD1Hno7JN isSigner false isWritable false
key { SysvarRent111111111111111111111111111111111 isSigner false isWritable false
Instruction [2]
key { AL3iZrc5QW1UMXSWUgzcVKbxikdwRwdqhzBP7PNgNaWB isSigner false isWritable true
key { 4fK7n3haNyFvBcyYrmAep5YDz2qPyK3ovRnF6PoRZRj2 isSigner false isWritable true
key { GENaXC37Q8L2mQAkRkJebudNKPZELwU3H1sVD1Hno7JN isSigner true isWritable false
- 서명해야할 키들을 알아내기 위해 위
Transaction
의feePayer
와 모든instruction
에 대한key
와isSigner
를 출력해보았다.
Tip
sendAndConfirmRawTransaction
함수를 사용할 경우에는, 즉 Keypair 를 제공하는 경우가 아니라면,Transaction
에 포함되어야하는 모든instruction
들을 추가하고 나서 요구된key
들로 서명을 해야 한다.
반응형
'블록체인 > 솔라나' 카테고리의 다른 글
서명 검증 함수 소개 (0) | 2022.05.23 |
---|---|
[beet FixableBeetStruct.deserialize 에러]"offset" is out of range (0) | 2022.05.18 |
솔라나 Generative Art 생성 방법 (0) | 2022.04.28 |
솔라나 NFT on-chain metadata "tokenStandard" (0) | 2022.04.26 |
솔라나 개발툴 설치 (0) | 2022.03.22 |