fix: rename signData
to serializeMessage()
This commit is contained in:
committed by
Michael Vines
parent
403448a91f
commit
7e642d5456
2
web3.js/module.d.ts
vendored
2
web3.js/module.d.ts
vendored
@ -403,7 +403,7 @@ declare module '@solana/web3.js' {
|
|||||||
Transaction | TransactionInstruction | TransactionInstructionCtorFields
|
Transaction | TransactionInstruction | TransactionInstructionCtorFields
|
||||||
>
|
>
|
||||||
): Transaction;
|
): Transaction;
|
||||||
signData: Buffer;
|
serializeMessage(): Buffer;
|
||||||
sign(...signers: Array<Account>): void;
|
sign(...signers: Array<Account>): void;
|
||||||
signPartial(...partialSigners: Array<PublicKey | Account>): void;
|
signPartial(...partialSigners: Array<PublicKey | Account>): void;
|
||||||
addSignature(pubkey: PublicKey, signature: Buffer): void;
|
addSignature(pubkey: PublicKey, signature: Buffer): void;
|
||||||
|
@ -411,7 +411,7 @@ declare module '@solana/web3.js' {
|
|||||||
Transaction | TransactionInstruction | TransactionInstructionCtorFields,
|
Transaction | TransactionInstruction | TransactionInstructionCtorFields,
|
||||||
>
|
>
|
||||||
): Transaction;
|
): Transaction;
|
||||||
signData: Buffer;
|
serializeMessage(): Buffer;
|
||||||
sign(...signers: Array<Account>): void;
|
sign(...signers: Array<Account>): void;
|
||||||
signPartial(...partialSigners: Array<PublicKey | Account>): void;
|
signPartial(...partialSigners: Array<PublicKey | Account>): void;
|
||||||
addSigner(signer: Account): void;
|
addSigner(signer: Account): void;
|
||||||
|
@ -182,7 +182,7 @@ export class Transaction {
|
|||||||
/**
|
/**
|
||||||
* Get a buffer of the Transaction data that need to be covered by signatures
|
* Get a buffer of the Transaction data that need to be covered by signatures
|
||||||
*/
|
*/
|
||||||
get signData(): Buffer {
|
serializeMessage(): Buffer {
|
||||||
const {nonceInfo} = this;
|
const {nonceInfo} = this;
|
||||||
if (nonceInfo && this.instructions[0] != nonceInfo.nonceInstruction) {
|
if (nonceInfo && this.instructions[0] != nonceInfo.nonceInstruction) {
|
||||||
this.recentBlockhash = nonceInfo.nonce;
|
this.recentBlockhash = nonceInfo.nonce;
|
||||||
@ -377,7 +377,7 @@ export class Transaction {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
this.signatures = signatures;
|
this.signatures = signatures;
|
||||||
const signData = this.signData;
|
const signData = this.serializeMessage();
|
||||||
|
|
||||||
partialSigners.forEach((accountOrPublicKey, index) => {
|
partialSigners.forEach((accountOrPublicKey, index) => {
|
||||||
if (accountOrPublicKey instanceof PublicKey) {
|
if (accountOrPublicKey instanceof PublicKey) {
|
||||||
@ -398,7 +398,7 @@ export class Transaction {
|
|||||||
* `signPartial`
|
* `signPartial`
|
||||||
*/
|
*/
|
||||||
addSigner(signer: Account) {
|
addSigner(signer: Account) {
|
||||||
const signData = this.signData;
|
const signData = this.serializeMessage();
|
||||||
const signature = nacl.sign.detached(signData, signer.secretKey);
|
const signature = nacl.sign.detached(signData, signer.secretKey);
|
||||||
this.addSignature(signer.publicKey, signature);
|
this.addSignature(signer.publicKey, signature);
|
||||||
}
|
}
|
||||||
@ -424,7 +424,7 @@ export class Transaction {
|
|||||||
*/
|
*/
|
||||||
verifySignatures(): boolean {
|
verifySignatures(): boolean {
|
||||||
let verified = true;
|
let verified = true;
|
||||||
const signData = this.signData;
|
const signData = this.serializeMessage();
|
||||||
for (const {signature, publicKey} of this.signatures) {
|
for (const {signature, publicKey} of this.signatures) {
|
||||||
if (
|
if (
|
||||||
!nacl.sign.detached.verify(signData, signature, publicKey.toBuffer())
|
!nacl.sign.detached.verify(signData, signature, publicKey.toBuffer())
|
||||||
@ -446,7 +446,7 @@ export class Transaction {
|
|||||||
throw new Error('Transaction has not been signed');
|
throw new Error('Transaction has not been signed');
|
||||||
}
|
}
|
||||||
|
|
||||||
const signData = this.signData;
|
const signData = this.serializeMessage();
|
||||||
const signatureCount = [];
|
const signatureCount = [];
|
||||||
shortvec.encodeLength(signatureCount, signatures.length);
|
shortvec.encodeLength(signatureCount, signatures.length);
|
||||||
const transactionLength =
|
const transactionLength =
|
||||||
|
@ -453,7 +453,7 @@ test('get sign data for transaction', () => {
|
|||||||
lamports: 42,
|
lamports: 42,
|
||||||
});
|
});
|
||||||
tx.recentBlockhash = bs58.encode(recentBlockhash);
|
tx.recentBlockhash = bs58.encode(recentBlockhash);
|
||||||
const tx_bytes = tx.signData;
|
const tx_bytes = tx.serializeMessage();
|
||||||
const signature = nacl.sign.detached(tx_bytes, from.secretKey);
|
const signature = nacl.sign.detached(tx_bytes, from.secretKey);
|
||||||
tx.addSignature(from.publicKey, signature);
|
tx.addSignature(from.publicKey, signature);
|
||||||
expect(tx.verifySignatures()).toBe(true);
|
expect(tx.verifySignatures()).toBe(true);
|
||||||
|
Reference in New Issue
Block a user