Skip to content

Commit

Permalink
ts-sdk: Add getTransactionAuthSigners json rpc (MystenLabs#6616)
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqvq authored Dec 7, 2022
1 parent 79e87e9 commit b03bfae
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lucky-bulldogs-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mysten/sui.js": minor
---

Add getTransactionAuthSigners endpoint
19 changes: 19 additions & 0 deletions sdk/typescript/src/providers/json-rpc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
isSuiTransactionResponse,
isTransactionEffects,
isCoinMetadata,
isSuiTransactionAuthSignersResponse,
} from '../types/index.guard';
import {
Coin,
Expand Down Expand Up @@ -55,6 +56,7 @@ import {
CoinMetadata,
versionToString,
normalizeSuiAddress,
SuiTransactionAuthSignersResponse,
} from '../types';
import { PublicKey, SignatureScheme, SIGNATURE_SCHEME_TO_FLAG } from '../cryptography/publickey';
import {
Expand Down Expand Up @@ -612,6 +614,23 @@ export class JsonRpcProvider extends Provider {
}
}

async getTransactionAuthSigners(
digest: TransactionDigest
): Promise<SuiTransactionAuthSignersResponse> {
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,
Expand Down
14 changes: 13 additions & 1 deletion sdk/typescript/src/types/index.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 &&
Expand Down
4 changes: 4 additions & 0 deletions sdk/typescript/src/types/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions sdk/typescript/test/e2e/read-transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit b03bfae

Please sign in to comment.