From b03bfaec2b4747bd228103fad3f31f9150498a30 Mon Sep 17 00:00:00 2001 From: Joy Wang <108701016+joyqvq@users.noreply.github.com> Date: Wed, 7 Dec 2022 16:10:33 -0500 Subject: [PATCH] ts-sdk: Add getTransactionAuthSigners json rpc (#6616) --- .changeset/lucky-bulldogs-own.md | 5 +++++ .../src/providers/json-rpc-provider.ts | 19 +++++++++++++++++++ sdk/typescript/src/types/index.guard.ts | 14 +++++++++++++- sdk/typescript/src/types/transactions.ts | 4 ++++ .../test/e2e/read-transactions.test.ts | 17 +++++++++++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 .changeset/lucky-bulldogs-own.md diff --git a/.changeset/lucky-bulldogs-own.md b/.changeset/lucky-bulldogs-own.md new file mode 100644 index 0000000000000..7dea7ad897fc4 --- /dev/null +++ b/.changeset/lucky-bulldogs-own.md @@ -0,0 +1,5 @@ +--- +"@mysten/sui.js": minor +--- + +Add getTransactionAuthSigners endpoint diff --git a/sdk/typescript/src/providers/json-rpc-provider.ts b/sdk/typescript/src/providers/json-rpc-provider.ts index 55533ce26d92e..a71bd6f773c0c 100644 --- a/sdk/typescript/src/providers/json-rpc-provider.ts +++ b/sdk/typescript/src/providers/json-rpc-provider.ts @@ -18,6 +18,7 @@ import { isSuiTransactionResponse, isTransactionEffects, isCoinMetadata, + isSuiTransactionAuthSignersResponse, } from '../types/index.guard'; import { Coin, @@ -55,6 +56,7 @@ import { CoinMetadata, versionToString, normalizeSuiAddress, + SuiTransactionAuthSignersResponse, } from '../types'; import { PublicKey, SignatureScheme, SIGNATURE_SCHEME_TO_FLAG } from '../cryptography/publickey'; import { @@ -612,6 +614,23 @@ export class JsonRpcProvider extends Provider { } } + async getTransactionAuthSigners( + digest: TransactionDigest + ): Promise { + try { + return await this.client.requestWithType( + 'sui_getTransactionAuthSigners', + [digest], + isSuiTransactionAuthSignersResponse, + this.options.skipDataValidation + ); + } catch (err) { + throw new Error( + `Error fetching transaction auth signers: ${err}` + ); + } + } + // Events async getEvents( query: EventQuery, diff --git a/sdk/typescript/src/types/index.guard.ts b/sdk/typescript/src/types/index.guard.ts index 31871620d2e25..e81bf24a91b0c 100644 --- a/sdk/typescript/src/types/index.guard.ts +++ b/sdk/typescript/src/types/index.guard.ts @@ -7,7 +7,7 @@ * Generated type guards for "index.ts". * WARNING: Do not manually change this file. */ -import { TransactionDigest, SuiAddress, ObjectOwner, SuiObjectRef, SuiObjectInfo, ObjectContentFields, MovePackageContent, SuiData, SuiMoveObject, SuiMovePackage, SuiMoveFunctionArgTypesResponse, SuiMoveFunctionArgType, SuiMoveFunctionArgTypes, SuiMoveNormalizedModules, SuiMoveNormalizedModule, SuiMoveModuleId, SuiMoveNormalizedStruct, SuiMoveStructTypeParameter, SuiMoveNormalizedField, SuiMoveNormalizedFunction, SuiMoveVisibility, SuiMoveTypeParameterIndex, SuiMoveAbilitySet, SuiMoveNormalizedType, SuiMoveNormalizedTypeParameterType, SuiMoveNormalizedStructType, SuiObject, ObjectStatus, ObjectType, GetOwnedObjectsResponse, GetObjectDataResponse, ObjectDigest, ObjectId, SequenceNumber, Order, MoveEvent, PublishEvent, CoinBalanceChangeEvent, TransferObjectEvent, MutateObjectEvent, DeleteObjectEvent, NewObjectEvent, SuiEvent, MoveEventField, EventQuery, EventId, PaginatedEvents, EventType, BalanceChangeType, SuiEventFilter, SuiEventEnvelope, SuiEvents, SubscriptionId, SubscriptionEvent, TransferObject, SuiTransferSui, SuiChangeEpoch, Pay, PaySui, PayAllSui, ExecuteTransactionRequestType, TransactionKindName, SuiTransactionKind, SuiTransactionData, EpochId, GenericAuthoritySignature, AuthorityQuorumSignInfo, CertifiedTransaction, GasCostSummary, ExecutionStatusType, ExecutionStatus, OwnedObjectRef, TransactionEffects, SuiTransactionResponse, SuiCertifiedTransactionEffects, SuiExecuteTransactionResponse, GatewayTxSeqNumber, GetTxnDigestsResponse, PaginatedTransactionDigests, TransactionQuery, MoveCall, SuiJsonValue, EmptySignInfo, AuthorityName, AuthoritySignature, TransactionBytes, SuiParsedMergeCoinResponse, SuiParsedSplitCoinResponse, SuiParsedPublishResponse, SuiPackage, SuiParsedTransactionResponse, CoinMetadata, DelegationData, DelegationSuiObject, TransferObjectTx, TransferSuiTx, PayTx, PaySuiTx, PayAllSuiTx, PublishTx, SharedObjectRef, ObjectArg, CallArg, StructTag, TypeTag, MoveCallTx, Transaction, TransactionKind, TransactionData, RpcApiVersion, FaucetCoinInfo, FaucetResponse } from "./index"; +import { TransactionDigest, SuiAddress, ObjectOwner, SuiObjectRef, SuiObjectInfo, ObjectContentFields, MovePackageContent, SuiData, SuiMoveObject, SuiMovePackage, SuiMoveFunctionArgTypesResponse, SuiMoveFunctionArgType, SuiMoveFunctionArgTypes, SuiMoveNormalizedModules, SuiMoveNormalizedModule, SuiMoveModuleId, SuiMoveNormalizedStruct, SuiMoveStructTypeParameter, SuiMoveNormalizedField, SuiMoveNormalizedFunction, SuiMoveVisibility, SuiMoveTypeParameterIndex, SuiMoveAbilitySet, SuiMoveNormalizedType, SuiMoveNormalizedTypeParameterType, SuiMoveNormalizedStructType, SuiObject, ObjectStatus, ObjectType, GetOwnedObjectsResponse, GetObjectDataResponse, ObjectDigest, ObjectId, SequenceNumber, Order, MoveEvent, PublishEvent, CoinBalanceChangeEvent, TransferObjectEvent, MutateObjectEvent, DeleteObjectEvent, NewObjectEvent, SuiEvent, MoveEventField, EventQuery, EventId, PaginatedEvents, EventType, BalanceChangeType, SuiEventFilter, SuiEventEnvelope, SuiEvents, SubscriptionId, SubscriptionEvent, TransferObject, SuiTransferSui, SuiChangeEpoch, Pay, PaySui, PayAllSui, ExecuteTransactionRequestType, TransactionKindName, SuiTransactionKind, SuiTransactionData, EpochId, GenericAuthoritySignature, AuthorityQuorumSignInfo, CertifiedTransaction, GasCostSummary, ExecutionStatusType, ExecutionStatus, OwnedObjectRef, TransactionEffects, SuiTransactionResponse, SuiTransactionAuthSignersResponse, SuiCertifiedTransactionEffects, SuiExecuteTransactionResponse, GatewayTxSeqNumber, GetTxnDigestsResponse, PaginatedTransactionDigests, TransactionQuery, MoveCall, SuiJsonValue, EmptySignInfo, AuthorityName, AuthoritySignature, TransactionBytes, SuiParsedMergeCoinResponse, SuiParsedSplitCoinResponse, SuiParsedPublishResponse, SuiPackage, SuiParsedTransactionResponse, CoinMetadata, DelegationData, DelegationSuiObject, TransferObjectTx, TransferSuiTx, PayTx, PaySuiTx, PayAllSuiTx, PublishTx, SharedObjectRef, ObjectArg, CallArg, StructTag, TypeTag, MoveCallTx, Transaction, TransactionKind, TransactionData, RpcApiVersion, FaucetCoinInfo, FaucetResponse } from "./index"; export function isTransactionDigest(obj: any, _argumentName?: string): obj is TransactionDigest { return ( @@ -1051,6 +1051,18 @@ export function isSuiTransactionResponse(obj: any, _argumentName?: string): obj ) } +export function isSuiTransactionAuthSignersResponse(obj: any, _argumentName?: string): obj is SuiTransactionAuthSignersResponse { + return ( + (obj !== null && + typeof obj === "object" || + typeof obj === "function") && + Array.isArray(obj.signers) && + obj.signers.every((e: any) => + isTransactionDigest(e) as boolean + ) + ) +} + export function isSuiCertifiedTransactionEffects(obj: any, _argumentName?: string): obj is SuiCertifiedTransactionEffects { return ( (obj !== null && diff --git a/sdk/typescript/src/types/transactions.ts b/sdk/typescript/src/types/transactions.ts index ba952d75f1684..5eb6c0e60848d 100644 --- a/sdk/typescript/src/types/transactions.ts +++ b/sdk/typescript/src/types/transactions.ts @@ -147,6 +147,10 @@ export type SuiTransactionResponse = { parsed_data: SuiParsedTransactionResponse | null; }; +export type SuiTransactionAuthSignersResponse = { + signers: AuthorityName[] +}; + // TODO: this is likely to go away after https://github.com/MystenLabs/sui/issues/4207 export type SuiCertifiedTransactionEffects = { effects: TransactionEffects; diff --git a/sdk/typescript/test/e2e/read-transactions.test.ts b/sdk/typescript/test/e2e/read-transactions.test.ts index ea89c7cf40681..a495886a1c211 100644 --- a/sdk/typescript/test/e2e/read-transactions.test.ts +++ b/sdk/typescript/test/e2e/read-transactions.test.ts @@ -27,6 +27,23 @@ describe('Transaction Reading API', () => { expect(txn.certificate.transactionDigest).toEqual(digest); }); + it('Get Transaction Auth Signers', async () => { + const version = await toolbox.provider.getRpcApiVersion(); + // This endpoint is only available in 0.18 and above + if (version?.major === 0 && version?.minor < 18) { + return; + } + + const resp = await toolbox.provider.getTransactions( + 'All', + null, + 1, + ); + const digest = resp.data[0]; + const res = await toolbox.provider.getTransactionAuthSigners(digest); + expect(res.signers.length).greaterThan(0); + }); + it('Get Transactions', async () => { const resp = await toolbox.provider.getTransactionsForAddress( toolbox.address(),