@mysten/sui.js
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -10,2 +10,3 @@ export * from './cryptography/ed25519-keypair'; | ||
export * from './signers/txn-data-serializers/txn-data-serializer'; | ||
export * from './signers/signer'; | ||
export * from './signers/raw-signer'; | ||
@@ -12,0 +13,0 @@ export * from './signers/signer-with-provider'; |
@@ -1,2 +0,2 @@ | ||
import { Ed25519KeypairData, Keypair, PublicKeyInitData, PublicKeyData, TransferCoinTransaction, TxnDataSerializer, TransactionDigest, SuiAddress, ObjectOwner, SuiObjectRef, ObjectContentFields, MovePackageContent, SuiData, SuiMoveObject, SuiMovePackage, SuiObject, ObjectStatus, ObjectType, GetOwnedObjectRefsResponse, GetObjectInfoResponse, ObjectDigest, ObjectId, SequenceNumber, TransferCoin, RawAuthoritySignInfo, TransactionKindName, SuiTransactionKind, TransactionData, EpochId, AuthorityQuorumSignInfo, CertifiedTransaction, GasCostSummary, ExecutionStatusType, ExecutionStatus, OwnedObjectRef, TransactionEffects, TransactionEffectsResponse, GatewayTxSeqNumber, GetTxnDigestsResponse, Event, MoveCall, SuiJsonValue, EmptySignInfo, AuthorityName, AuthoritySignature, TransactionBytes, SplitCoinResponse, TransactionResponse } from "./index"; | ||
import { Ed25519KeypairData, Keypair, PublicKeyInitData, PublicKeyData, TransferCoinTransaction, MergeCoinTransaction, SplitCoinTransaction, MoveCallTransaction, TxnDataSerializer, SignaturePubkeyPair, Signer, TransactionDigest, SuiAddress, ObjectOwner, SuiObjectRef, SuiObjectInfo, ObjectContentFields, MovePackageContent, SuiData, SuiMoveObject, SuiMovePackage, SuiObject, ObjectStatus, ObjectType, GetOwnedObjectsResponse, GetObjectDataResponse, ObjectDigest, ObjectId, SequenceNumber, TransferCoin, RawAuthoritySignInfo, TransactionKindName, SuiTransactionKind, TransactionData, EpochId, AuthorityQuorumSignInfo, CertifiedTransaction, GasCostSummary, ExecutionStatusType, ExecutionStatus, OwnedObjectRef, TransactionEffects, TransactionEffectsResponse, GatewayTxSeqNumber, GetTxnDigestsResponse, Event, MoveCall, SuiJsonValue, EmptySignInfo, AuthorityName, AuthoritySignature, TransactionBytes, MergeCoinResponse, SplitCoinResponse, TransactionResponse } from "./index"; | ||
export declare function isEd25519KeypairData(obj: any, _argumentName?: string): obj is Ed25519KeypairData; | ||
@@ -7,3 +7,8 @@ export declare function isKeypair(obj: any, _argumentName?: string): obj is Keypair; | ||
export declare function isTransferCoinTransaction(obj: any, _argumentName?: string): obj is TransferCoinTransaction; | ||
export declare function isMergeCoinTransaction(obj: any, _argumentName?: string): obj is MergeCoinTransaction; | ||
export declare function isSplitCoinTransaction(obj: any, _argumentName?: string): obj is SplitCoinTransaction; | ||
export declare function isMoveCallTransaction(obj: any, _argumentName?: string): obj is MoveCallTransaction; | ||
export declare function isTxnDataSerializer(obj: any, _argumentName?: string): obj is TxnDataSerializer; | ||
export declare function isSignaturePubkeyPair(obj: any, _argumentName?: string): obj is SignaturePubkeyPair; | ||
export declare function isSigner(obj: any, _argumentName?: string): obj is Signer; | ||
export declare function isTransactionDigest(obj: any, _argumentName?: string): obj is TransactionDigest; | ||
@@ -13,2 +18,3 @@ export declare function isSuiAddress(obj: any, _argumentName?: string): obj is SuiAddress; | ||
export declare function isSuiObjectRef(obj: any, _argumentName?: string): obj is SuiObjectRef; | ||
export declare function isSuiObjectInfo(obj: any, _argumentName?: string): obj is SuiObjectInfo; | ||
export declare function isObjectContentFields(obj: any, _argumentName?: string): obj is ObjectContentFields; | ||
@@ -22,4 +28,4 @@ export declare function isMovePackageContent(obj: any, _argumentName?: string): obj is MovePackageContent; | ||
export declare function isObjectType(obj: any, _argumentName?: string): obj is ObjectType; | ||
export declare function isGetOwnedObjectRefsResponse(obj: any, _argumentName?: string): obj is GetOwnedObjectRefsResponse; | ||
export declare function isGetObjectInfoResponse(obj: any, _argumentName?: string): obj is GetObjectInfoResponse; | ||
export declare function isGetOwnedObjectsResponse(obj: any, _argumentName?: string): obj is GetOwnedObjectsResponse; | ||
export declare function isGetObjectDataResponse(obj: any, _argumentName?: string): obj is GetObjectDataResponse; | ||
export declare function isObjectDigest(obj: any, _argumentName?: string): obj is ObjectDigest; | ||
@@ -51,3 +57,4 @@ export declare function isObjectId(obj: any, _argumentName?: string): obj is ObjectId; | ||
export declare function isTransactionBytes(obj: any, _argumentName?: string): obj is TransactionBytes; | ||
export declare function isMergeCoinResponse(obj: any, _argumentName?: string): obj is MergeCoinResponse; | ||
export declare function isSplitCoinResponse(obj: any, _argumentName?: string): obj is SplitCoinResponse; | ||
export declare function isTransactionResponse(obj: any, _argumentName?: string): obj is TransactionResponse; |
import { Provider } from './provider'; | ||
import { GatewayTxSeqNumber, GetTxnDigestsResponse, GetObjectInfoResponse, SuiObjectRef, TransactionDigest, TransactionEffectsResponse, TransactionResponse } from '../types'; | ||
import { GatewayTxSeqNumber, GetTxnDigestsResponse, GetObjectDataResponse, SuiObjectInfo, TransactionDigest, TransactionEffectsResponse, TransactionResponse } from '../types'; | ||
export declare class JsonRpcProvider extends Provider { | ||
@@ -12,5 +12,6 @@ endpoint: string; | ||
constructor(endpoint: string); | ||
getOwnedObjectRefs(address: string): Promise<SuiObjectRef[]>; | ||
getObjectInfo(objectId: string): Promise<GetObjectInfoResponse>; | ||
getObjectInfoBatch(objectIds: string[]): Promise<GetObjectInfoResponse[]>; | ||
getObjectsOwnedByAddress(address: string): Promise<SuiObjectInfo[]>; | ||
getObjectsOwnedByObject(objectId: string): Promise<SuiObjectInfo[]>; | ||
getObject(objectId: string): Promise<GetObjectDataResponse>; | ||
getObjectBatch(objectIds: string[]): Promise<GetObjectDataResponse[]>; | ||
getTransactionWithEffects(digest: TransactionDigest): Promise<TransactionEffectsResponse>; | ||
@@ -17,0 +18,0 @@ getTransactionWithEffectsBatch(digests: TransactionDigest[]): Promise<TransactionEffectsResponse[]>; |
@@ -1,2 +0,2 @@ | ||
import { GetObjectInfoResponse, SuiObjectRef, GatewayTxSeqNumber, GetTxnDigestsResponse, TransactionResponse } from '../types'; | ||
import { GetObjectDataResponse, SuiObjectInfo, GatewayTxSeqNumber, GetTxnDigestsResponse, TransactionResponse } from '../types'; | ||
export declare abstract class Provider { | ||
@@ -6,7 +6,7 @@ /** | ||
*/ | ||
abstract getOwnedObjectRefs(address: string): Promise<SuiObjectRef[]>; | ||
abstract getObjectsOwnedByAddress(addressOrObjectId: string): Promise<SuiObjectInfo[]>; | ||
/** | ||
* Get information about an object | ||
* Get details about an object | ||
*/ | ||
abstract getObjectInfo(objectId: string): Promise<GetObjectInfoResponse>; | ||
abstract getObject(objectId: string): Promise<GetObjectDataResponse>; | ||
/** | ||
@@ -13,0 +13,0 @@ * Get transaction digests for a given range |
@@ -1,6 +0,6 @@ | ||
import { CertifiedTransaction, TransactionDigest, GetTxnDigestsResponse, GatewayTxSeqNumber, SuiObjectRef, GetObjectInfoResponse, TransactionResponse } from '../types'; | ||
import { CertifiedTransaction, TransactionDigest, GetTxnDigestsResponse, GatewayTxSeqNumber, SuiObjectInfo, GetObjectDataResponse, TransactionResponse } from '../types'; | ||
import { Provider } from './provider'; | ||
export declare class VoidProvider extends Provider { | ||
getOwnedObjectRefs(_address: string): Promise<SuiObjectRef[]>; | ||
getObjectInfo(_objectId: string): Promise<GetObjectInfoResponse>; | ||
getObjectsOwnedByAddress(_address: string): Promise<SuiObjectInfo[]>; | ||
getObject(_objectId: string): Promise<GetObjectDataResponse>; | ||
getTransaction(_digest: TransactionDigest): Promise<CertifiedTransaction>; | ||
@@ -7,0 +7,0 @@ executeTransaction(_txnBytes: string, _signature: string, _pubkey: string): Promise<TransactionResponse>; |
import { Ed25519Keypair } from '../cryptography/ed25519-keypair'; | ||
import { Provider } from '../providers/provider'; | ||
import { Base64DataBuffer } from '../serialization/base64'; | ||
import { SuiAddress } from '../types'; | ||
import { SignaturePubkeyPair } from './signer'; | ||
@@ -10,5 +11,5 @@ import { SignerWithProvider } from './signer-with-provider'; | ||
constructor(keypair: Ed25519Keypair, provider?: Provider, serializer?: TxnDataSerializer); | ||
getAddress(): Promise<string>; | ||
getAddress(): Promise<SuiAddress>; | ||
signData(data: Base64DataBuffer): Promise<SignaturePubkeyPair>; | ||
connect(provider: Provider): SignerWithProvider; | ||
} |
import { Provider } from '../providers/provider'; | ||
import { Base64DataBuffer } from '../serialization/base64'; | ||
import { TransactionResponse } from '../types'; | ||
import { SuiAddress, TransactionResponse } from '../types'; | ||
import { SignaturePubkeyPair, Signer } from './signer'; | ||
import { TransferCoinTransaction, TxnDataSerializer } from './txn-data-serializers/txn-data-serializer'; | ||
import { MoveCallTransaction, MergeCoinTransaction, SplitCoinTransaction, TransferCoinTransaction, TxnDataSerializer } from './txn-data-serializers/txn-data-serializer'; | ||
export declare abstract class SignerWithProvider implements Signer { | ||
readonly provider: Provider; | ||
readonly serializer: TxnDataSerializer; | ||
abstract getAddress(): Promise<string>; | ||
abstract getAddress(): Promise<SuiAddress>; | ||
/** | ||
@@ -26,2 +26,14 @@ * Returns the signature for the data and the public key of the signer | ||
transferCoin(transaction: TransferCoinTransaction): Promise<TransactionResponse>; | ||
/** | ||
* Serialize and Sign a `MergeCoin` transaction and submit to the Gateway for execution | ||
*/ | ||
mergeCoin(transaction: MergeCoinTransaction): Promise<TransactionResponse>; | ||
/** | ||
* Serialize and Sign a `SplitCoin` transaction and submit to the Gateway for execution | ||
*/ | ||
splitCoin(transaction: SplitCoinTransaction): Promise<TransactionResponse>; | ||
/** | ||
* Serialize and Sign a `MoveCall` transaction and submit to the Gateway for execution | ||
*/ | ||
executeMoveCall(transaction: MoveCallTransaction): Promise<TransactionResponse>; | ||
} |
import { Base64DataBuffer } from '../../serialization/base64'; | ||
import { TransferCoinTransaction, TxnDataSerializer } from './txn-data-serializer'; | ||
import { SuiAddress } from '../../types'; | ||
import { MoveCallTransaction, MergeCoinTransaction, SplitCoinTransaction, TransferCoinTransaction, TxnDataSerializer } from './txn-data-serializer'; | ||
/** | ||
@@ -18,3 +19,6 @@ * This is a temporary implementation of the `TxnDataSerializer` class | ||
constructor(endpoint: string); | ||
newTransferCoin(t: TransferCoinTransaction): Promise<Base64DataBuffer>; | ||
newTransferCoin(signerAddress: SuiAddress, t: TransferCoinTransaction): Promise<Base64DataBuffer>; | ||
newMoveCall(signerAddress: SuiAddress, t: MoveCallTransaction): Promise<Base64DataBuffer>; | ||
newMergeCoin(signerAddress: SuiAddress, t: MergeCoinTransaction): Promise<Base64DataBuffer>; | ||
newSplitCoin(signerAddress: SuiAddress, t: SplitCoinTransaction): Promise<Base64DataBuffer>; | ||
} |
import { Base64DataBuffer } from '../../serialization/base64'; | ||
import { ObjectId, SuiAddress } from '../../types'; | ||
import { ObjectId, SuiAddress, SuiJsonValue } from '../../types'; | ||
export interface TransferCoinTransaction { | ||
signer: SuiAddress; | ||
objectId: ObjectId; | ||
gasPayment: ObjectId; | ||
gasPayment?: ObjectId; | ||
gasBudget: number; | ||
recipient: SuiAddress; | ||
} | ||
export interface MergeCoinTransaction { | ||
primaryCoin: ObjectId; | ||
coinToMerge: ObjectId; | ||
gasPayment?: ObjectId; | ||
gasBudget: number; | ||
} | ||
export interface SplitCoinTransaction { | ||
coinObjectId: ObjectId; | ||
splitAmounts: number[]; | ||
gasPayment?: ObjectId; | ||
gasBudget: number; | ||
} | ||
export interface MoveCallTransaction { | ||
packageObjectId: ObjectId; | ||
module: string; | ||
function: string; | ||
typeArguments: string[]; | ||
arguments: SuiJsonValue[]; | ||
gasPayment?: ObjectId; | ||
gasBudget: number; | ||
} | ||
/** | ||
@@ -14,3 +34,6 @@ * Serializes a transaction to a string that can be signed by a `Signer`. | ||
export interface TxnDataSerializer { | ||
newTransferCoin(txn: TransferCoinTransaction): Promise<Base64DataBuffer>; | ||
newTransferCoin(signerAddress: SuiAddress, txn: TransferCoinTransaction): Promise<Base64DataBuffer>; | ||
newMoveCall(signerAddress: SuiAddress, txn: MoveCallTransaction): Promise<Base64DataBuffer>; | ||
newMergeCoin(signerAddress: SuiAddress, txn: MergeCoinTransaction): Promise<Base64DataBuffer>; | ||
newSplitCoin(signerAddress: SuiAddress, txn: SplitCoinTransaction): Promise<Base64DataBuffer>; | ||
} |
@@ -1,2 +0,2 @@ | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("tweetnacl")),r=require("buffer"),n=require("bn.js"),o=t(n),i=require("js-sha3"),u=require("util"),a=t(require("jayson/lib/client/browser")),s=t(require("cross-fetch")),c=function(){function t(t){this.data="string"==typeof t?new Uint8Array(r.Buffer.from(t,"base64")):t}var e=t.prototype;return e.getData=function(){return this.data},e.getLength=function(){return this.data.length},e.toString=function(){return r.Buffer.from(this.data).toString("base64")},t}(),f=function(){function t(t){if(function(t){return void 0!==t._bn}(t))this._bn=t._bn;else{if("string"==typeof t){var e=r.Buffer.from(t,"base64");if(32!==e.length)throw new Error("Invalid public key input. Expected 32 bytes, got "+e.length);this._bn=new o(e)}else this._bn=new o(t);if(this._bn.byteLength()>32)throw new Error("Invalid public key input")}}var e=t.prototype;return e.equals=function(t){return this._bn.eq(t._bn)},e.toBase64=function(){return this.toBuffer().toString("base64")},e.toBytes=function(){return this.toBuffer()},e.toBuffer=function(){var t=this._bn.toArrayLike(r.Buffer);if(32===t.length)return t;var e=r.Buffer.alloc(32);return t.copy(e,32-t.length),e},e.toString=function(){return this.toBase64()},e.toSuiAddress=function(){var t=i.sha3_256(this.toBytes());return new o(t,16).toArray(void 0,32).slice(0,20).reduce((function(t,e){return t+("0"+e.toString(16)).slice(-2)}),"")},t}(),p=function(){function t(t){this.keypair=t||e.sign.keyPair()}t.generate=function(){return new t(e.sign.keyPair())},t.fromSecretKey=function(r,n){var o=e.sign.keyPair.fromSecretKey(r);if(!n||!n.skipValidation){var i=(new u.TextEncoder).encode("sui validation"),a=e.sign.detached(i,o.secretKey);if(!e.sign.detached.verify(i,a,o.publicKey))throw new Error("provided secretKey is invalid")}return new t(o)},t.fromSeed=function(r){return new t(e.sign.keyPair.fromSeed(r))};var r=t.prototype;return r.getPublicKey=function(){return new f(this.keypair.publicKey)},r.signData=function(t){return new c(e.sign.detached(t.getData(),this.keypair.secretKey))},t}(),h=function(){};function y(t,e,r,n,o,i,u){try{var a=t[i](u),s=a.value}catch(t){return void r(t)}a.done?e(s):Promise.resolve(s).then(n,o)}function l(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function u(t){y(i,n,o,u,a,"next",t)}function a(t){y(i,n,o,u,a,"throw",t)}u(void 0)}))}}function d(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,(Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function v(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function g(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return v(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?v(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var w,b=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",u=n.toStringTag||"@@toStringTag";function a(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{a({},"")}catch(t){a=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof p?e:p).prototype),i=new j(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var u=r.delegate;if(u){var a=x(u,r);if(a){if(a===f)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=c(t,e,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===f)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}(t,r,i),o}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f={};function p(){}function h(){}function y(){}var l={};a(l,o,(function(){return this}));var d=Object.getPrototypeOf,v=d&&d(d(E([])));v&&v!==e&&r.call(v,o)&&(l=v);var g=y.prototype=p.prototype=Object.create(l);function w(t){["next","throw","return"].forEach((function(e){a(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var n;this._invoke=function(o,i){function u(){return new e((function(n,u){!function n(o,i,u,a){var s=c(t[o],t,i);if("throw"!==s.type){var f=s.arg,p=f.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,u,a)}),(function(t){n("throw",t,u,a)})):e.resolve(p).then((function(t){f.value=t,u(f)}),(function(t){return n("throw",t,u,a)}))}a(s.arg)}(o,i,n,u)}))}return n=n?n.then(u,u):u()}}function x(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=c(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function m(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function j(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(m,this),this.reset(!0)}function E(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:O}}function O(){return{value:void 0,done:!0}}return h.prototype=y,a(g,"constructor",y),a(y,"constructor",h),h.displayName=a(y,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,a(t,u,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},w(b.prototype),a(b.prototype,i,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var u=new b(s(e,r,n,o),i);return t.isGeneratorFunction(r)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},w(g),a(g,u,"Generator"),a(g,o,(function(){return this})),a(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=E,j.prototype={constructor:j,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(T),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return u.type="throw",u.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],u=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=r.call(i,"catchLoc"),s=r.call(i,"finallyLoc");if(a&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var u=i?i.completion:{};return u.type=t,u.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(u)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),T(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;T(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:E(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(w={exports:{}}),w.exports);function x(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&t._bn instanceof n.BN}function m(t,e){return"string"==typeof t}function T(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.AddressOwner)||(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.ObjectOwner)||"Shared"===t||"Immutable"===t}function j(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.digest)&&m(t.objectId)&&I(t.version)}function E(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&Object.entries(t).every((function(t){return m(t[0])}))}function O(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&Object.entries(t).every((function(t){var e=t[0];return m(t[1])&&m(e)}))}function S(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&B(t.dataType)&&A(t)||(null!==t&&"object"==typeof t||"function"==typeof t)&&B(t.dataType)&&k(t)}function A(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.type)&&E(t.fields)}function k(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&O(t.disassembled)}function _(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&S(t.data)&&T(t.owner)&&m(t.previousTransaction)&&I(t.storageRebate)&&j(t.reference)}function R(t,e){return"Exists"===t||"NotExists"===t||"Deleted"===t}function B(t,e){return"moveObject"===t||"package"===t}function P(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&Array.isArray(t.objects)&&t.objects.every((function(t){return j(t)}))}function C(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&R(t.status)&&(m(t.details)||j(t.details)||_(t.details))}function I(t,e){return"number"==typeof t}function L(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.recipient)&&j(t.objectRef)}function N(t,e){return Array.isArray(t)&&m(t[0])&&m(t[1])}function D(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&L(t.TransferCoin)||(null!==t&&"object"==typeof t||"function"==typeof t)&&k(t.Publish)||(null!==t&&"object"==typeof t||"function"==typeof t)&&$(t.Call)}function U(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&Array.isArray(t.transactions)&&t.transactions.every((function(t){return D(t)}))&&m(t.sender)&&j(t.gasPayment)&&I(t.gasBudget)}function q(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&I(t.epoch)&&Array.isArray(t.signatures)&&t.signatures.every((function(t){return N(t)}))}function V(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.transactionDigest)&&U(t.data)&&m(t.txSignature)&&q(t.authSignInfo)}function K(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&I(t.computationCost)&&I(t.storageCost)&&I(t.storageRebate)}function G(t,e){return"success"===t||"failure"===t}function W(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&G(t.status)&&K(t.gas_cost)&&(void 0===t.error||m(t.error))}function M(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&T(t.owner)&&j(t.reference)}function z(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&W(t.status)&&(void 0===t.sharedObjects||Array.isArray(t.sharedObjects)&&t.sharedObjects.every((function(t){return j(t)})))&&m(t.transactionDigest)&&(void 0===t.created||Array.isArray(t.created)&&t.created.every((function(t){return M(t)})))&&(void 0===t.mutated||Array.isArray(t.mutated)&&t.mutated.every((function(t){return M(t)})))&&(void 0===t.unwrapped||Array.isArray(t.unwrapped)&&t.unwrapped.every((function(t){return M(t)})))&&(void 0===t.deleted||Array.isArray(t.deleted)&&t.deleted.every((function(t){return j(t)})))&&(void 0===t.wrapped||Array.isArray(t.wrapped)&&t.wrapped.every((function(t){return j(t)})))&&M(t.gasObject)&&(void 0===t.events||Array.isArray(t.events)&&t.events.every((function(t){return J(t)})))&&(void 0===t.dependencies||Array.isArray(t.dependencies)&&t.dependencies.every((function(t){return m(t)})))}function F(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&V(t.certificate)&&z(t.effects)}function Z(t,e){return Array.isArray(t)&&t.every((function(t){return Array.isArray(t)&&I(t[0])&&m(t[1])}))}function J(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.type_)}function $(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&j(t.package)&&m(t.module)&&m(t.function)&&(void 0===t.typeArguments||Array.isArray(t.typeArguments)&&t.typeArguments.every((function(t){return m(t)})))&&(void 0===t.arguments||Array.isArray(t.arguments)&&t.arguments.every((function(t){return Y(t)})))}function Y(t,e){return m(t)||I(t)||!1===t||!0===t||Array.isArray(t)&&t.every((function(t){return m(t)||I(t)||!1===t||!0===t}))}function Q(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.txBytes)&&j(t.gas)}function X(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&V(t.certificate)&&_(t.updatedCoin)&&Array.isArray(t.newCoins)&&t.newCoins.every((function(t){return _(t)}))&&_(t.updatedGas)}function H(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&F(t.EffectResponse)||(null!==t&&"object"==typeof t||"function"==typeof t)&&X(t.SplitCoinResponse)}function tt(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&"2.0"===t.jsonrpc&&m(t.id)}var et=require("lossless-json"),rt=function(){function t(t,e){this.rpcClient=this.createRpcClient(t,e)}var e=t.prototype;return e.createRpcClient=function(t,e){return new a(function(){var r=l(b.mark((function r(n,o){var i,u,a,c;return b.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return i={method:"POST",body:n,headers:Object.assign({"Content-Type":"application/json"},e||{})},r.prev=1,r.next=4,s(t,i);case 4:return u=r.sent,r.next=7,u.text();case 7:a=r.sent,c=JSON.stringify(et.parse(a,(function(t,e){return"balance"===t?e.toString():e.isLosslessNumber?e.valueOf():e}))),u.ok?o(null,c):o(new Error(u.status+" "+u.statusText+": "+a)),r.next=15;break;case 12:r.prev=12,r.t0=r.catch(1),r.t0 instanceof Error&&o(r.t0);case 15:case"end":return r.stop()}}),r,null,[[1,12]])})));return function(t,e){return r.apply(this,arguments)}}(),{})},e.requestWithType=function(){var t=l(b.mark((function t(e,r,n){var o;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.request(e,r);case 2:if((null===(i=o=t.sent)||"object"!=typeof i)&&"function"!=typeof i||"2.0"!==i.jsonrpc||!m(i.id)||(null===i.error||"object"!=typeof i.error)&&"function"!=typeof i.error||!m(i.error.message)){t.next=7;break}throw new Error("RPC Error: "+o.error.message);case 7:if(!tt(o)){t.next=13;break}if(!n(o.result)){t.next=12;break}return t.abrupt("return",o.result);case 12:throw new Error("RPC Error: result not of expected type. Result received was: "+JSON.stringify(o.result));case 13:throw new Error("Unexpected RPC Response: "+o);case 14:case"end":return t.stop()}var i}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),e.request=function(){var t=l(b.mark((function t(e,r){var n=this;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise((function(t,o){n.rpcClient.request(e,r,(function(e,r){e?o(e):t(r)}))})));case 1:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),e.batchRequestWithType=function(){var t=l(b.mark((function t(e,r){var n;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.batchRequest(e);case 2:return n=t.sent.filter((function(t){return tt(t)&&r(t.result)})),t.abrupt("return",n.map((function(t){return t.result})));case 5:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.batchRequest=function(){var t=l(b.mark((function t(e){var r=this;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise((function(t,n){0===e.length&&t([]);var o=e.map((function(t){return r.rpcClient.request(t.method,t.args)}));r.rpcClient.request(o,(function(e,r){e?n(e):t(r)}))})));case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t}(),nt=function(t){return"number"==typeof t},ot=function(t){function e(e){var r;return(r=t.call(this)||this).endpoint=e,r.client=new rt(e),r}d(e,t);var r=e.prototype;return r.getOwnedObjectRefs=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_getOwnedObjects",[e],P);case 3:return t.abrupt("return",t.sent.objects);case 7:throw t.prev=7,t.t0=t.catch(0),new Error("Error fetching owned object refs: "+t.t0+" for address "+e);case 10:case"end":return t.stop()}}),t,this,[[0,7]])})));return function(e){return t.apply(this,arguments)}}(),r.getObjectInfo=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_getObjectInfo",[e],C);case 3:return t.abrupt("return",t.sent);case 6:throw t.prev=6,t.t0=t.catch(0),new Error("Error fetching object info: "+t.t0+" for id "+e);case 9:case"end":return t.stop()}}),t,this,[[0,6]])})));return function(e){return t.apply(this,arguments)}}(),r.getObjectInfoBatch=function(){var t=l(b.mark((function t(e){var r;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.map((function(t){return{method:"sui_getObjectInfo",args:[t]}})),t.prev=1,t.next=4,this.client.batchRequestWithType(r,C);case 4:return t.abrupt("return",t.sent);case 7:throw t.prev=7,t.t0=t.catch(1),new Error("Error fetching object info: "+t.t0+" for id "+e);case 10:case"end":return t.stop()}}),t,this,[[1,7]])})));return function(e){return t.apply(this,arguments)}}(),r.getTransactionWithEffects=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_getTransaction",[e],F);case 3:return t.abrupt("return",t.sent);case 7:throw t.prev=7,t.t0=t.catch(0),new Error("Error getting transaction with effects: "+t.t0+" for digest "+e);case 10:case"end":return t.stop()}}),t,this,[[0,7]])})));return function(e){return t.apply(this,arguments)}}(),r.getTransactionWithEffectsBatch=function(){var t=l(b.mark((function t(e){var r,n;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.map((function(t){return{method:"sui_getTransaction",args:[t]}})),t.prev=1,t.next=4,this.client.batchRequestWithType(r,F);case 4:return t.abrupt("return",t.sent);case 7:throw t.prev=7,t.t0=t.catch(1),n=e.join(", ").substring(0,-2),new Error("Error getting transaction effects: "+t.t0+" for digests ["+n+"]");case 11:case"end":return t.stop()}}),t,this,[[1,7]])})));return function(e){return t.apply(this,arguments)}}(),r.executeTransaction=function(){var t=l(b.mark((function t(e,r,n){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_executeTransaction",[e,r,n],H);case 3:return t.abrupt("return",t.sent);case 7:throw t.prev=7,t.t0=t.catch(0),new Error("Error executing transaction: "+t.t0+"}");case 10:case"end":return t.stop()}}),t,this,[[0,7]])})));return function(e,r,n){return t.apply(this,arguments)}}(),r.getTotalTransactionNumber=function(){var t=l(b.mark((function t(){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_getTotalTransactionNumber",[],nt);case 3:return t.abrupt("return",t.sent);case 7:throw t.prev=7,t.t0=t.catch(0),new Error("Error fetching total transaction number: "+t.t0);case 10:case"end":return t.stop()}}),t,this,[[0,7]])})));return function(){return t.apply(this,arguments)}}(),r.getTransactionDigestsInRange=function(){var t=l(b.mark((function t(e,r){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_getTransactionsInRange",[e,r],Z);case 3:return t.abrupt("return",t.sent);case 6:throw t.prev=6,t.t0=t.catch(0),new Error("Error fetching transaction digests in range: "+t.t0+" for range "+e+"-"+r);case 9:case"end":return t.stop()}}),t,this,[[0,6]])})));return function(e,r){return t.apply(this,arguments)}}(),r.getRecentTransactions=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_getRecentTransactions",[e],Z);case 3:return t.abrupt("return",t.sent);case 6:throw t.prev=6,t.t0=t.catch(0),new Error("Error fetching recent transactions: "+t.t0+" for count "+e);case 9:case"end":return t.stop()}}),t,this,[[0,6]])})));return function(e){return t.apply(this,arguments)}}(),e}(h),it=function(){function t(t){this._data="string"==typeof t?new Uint8Array(r.Buffer.from(t,"hex")):t}var e=t.prototype;return e.getData=function(){return this._data},e.getLength=function(){return this._data.length},e.toString=function(){return r.Buffer.from(this._data).toString("hex")},t}(),ut=function(){function t(t){this.client=new rt(t)}return t.prototype.newTransferCoin=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_transferCoin",[e.signer,e.objectId,e.gasPayment,e.gasBudget,e.recipient],Q);case 3:return t.abrupt("return",new c(t.sent.txBytes));case 7:throw t.prev=7,t.t0=t.catch(0),new Error("Error transferring coin: "+t.t0);case 10:case"end":return t.stop()}}),t,this,[[0,7]])})));return function(e){return t.apply(this,arguments)}}(),t}(),at=function(t){function e(){return t.apply(this,arguments)||this}d(e,t);var r=e.prototype;return r.getOwnedObjectRefs=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw this.newError("getOwnedObjectRefs");case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getObjectInfo=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw this.newError("getObjectInfo");case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getTransaction=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw this.newError("getTransaction");case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.executeTransaction=function(){var t=l(b.mark((function t(e,r,n){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw this.newError("executeTransaction");case 1:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.getTotalTransactionNumber=function(){var t=l(b.mark((function t(){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw this.newError("getTotalTransactionNumber");case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.getTransactionDigestsInRange=function(){var t=l(b.mark((function t(e,r){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw this.newError("getTransactionDigestsInRange");case 1:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r.getRecentTransactions=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw this.newError("getRecentTransactions");case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.newError=function(t){return new Error("Please use a valid provider for "+t)},e}(h),st=function(){function t(t,e){this.provider=t||new at;var r="";this.provider instanceof ot&&(r=this.provider.endpoint),this.serializer=e||new ut(r)}var e=t.prototype;return e.signAndExecuteTransaction=function(){var t=l(b.mark((function t(e){var r;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.signData(e);case 2:return r=t.sent,t.next=5,this.provider.executeTransaction(e.toString(),r.signature.toString(),r.pubKey.toString());case 5:return t.abrupt("return",t.sent);case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.transferCoin=function(){var t=l(b.mark((function t(e){var r;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.serializer.newTransferCoin(e);case 2:return r=t.sent,t.next=5,this.signAndExecuteTransaction(r);case 5:return t.abrupt("return",t.sent);case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(),ct=function(t){function e(e,r,n){var o;return(o=t.call(this,r,n)||this).keypair=e,o}d(e,t);var r=e.prototype;return r.getAddress=function(){var t=l(b.mark((function t(){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw this.keypair.getPublicKey().toSuiAddress();case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.signData=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",{signature:this.keypair.signData(e),pubKey:this.keypair.getPublicKey()});case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.connect=function(t){return new e(this.keypair,t)},e}(st),ft=/^(?:[a-zA-Z0-9+\/]{4})*(?:|(?:[a-zA-Z0-9+\/]{3}=)|(?:[a-zA-Z0-9+\/]{2}==)|(?:[a-zA-Z0-9+\/]{1}===))$/;function pt(t){return function(t){return/^(0x|0X)?[a-fA-F0-9]+$/.test(t)&&t.length%2==0}(t)&&20===function(t){return/^(0x|0X)/.test(t)?(t.length-2)/2:t.length/2}(t)}function ht(t){return"Exists"!==t.status?void 0:t.details}function yt(t){return"Deleted"!==t.status?void 0:t.details}function lt(t){return"NotExists"!==t.status?void 0:t.details}function dt(t){var e;return(null==(e=ht(t))?void 0:e.reference)||yt(t)}function vt(t){var e;return null==(e=wt(t))?void 0:e.type}function gt(t){var e;return null==(e=wt(t))?void 0:e.fields}function wt(t){var e=ht(t);if("moveObject"===(null==e?void 0:e.data.dataType))return e.data}function bt(t){return t.effects.status}function xt(t){return bt(t).gas_cost}var mt=function(){function t(){}return t.isCoin=function(t){var e,r;return null!=(e=null==(r=vt(t))?void 0:r.startsWith("0x2::Coin::Coin"))&&e},t.getBalance=function(e){var r;if(t.isCoin(e)){var n=null==(r=gt(e))?void 0:r.balance;return new o.BN(n,10)}},t.getZero=function(){return new o.BN("0",10)},t}(),Tt=function(){function t(t){this.bytePosition=0,this.dataView=new DataView(t.buffer)}var e=t.prototype;return e.shift=function(t){return this.bytePosition+=t,this},e.read8=function(){var t=this.dataView.getUint8(this.bytePosition);return this.shift(1),new n.BN(t,10)},e.read16=function(){var t=this.dataView.getUint16(this.bytePosition,!0);return this.shift(2),new n.BN(t,10)},e.read32=function(){var t=this.dataView.getUint32(this.bytePosition,!0);return this.shift(4),new n.BN(t,10)},e.read64=function(){var t=this.read32(),e=this.read32().toString(16)+t.toString(16).padStart(8,"0");return new n.BN(e,16)},e.read128=function(){var t=this.read64(),e=this.read64().toString(16)+t.toString(16).padStart(8,"0");return new n.BN(e,16)},e.readBytes=function(t){var e=new Uint8Array(this.dataView.buffer,this.bytePosition+this.dataView.byteOffset,t);return this.shift(t),e},e.readULEB=function(){var t=function(t){for(var e=0,r=0,n=0;;){var o=t[n];if(n+=1,e|=(127&o)<<r,0==(128&o))break;r+=7}return{value:e,length:n}}(new Uint8Array(this.dataView.buffer,this.bytePosition+this.dataView.byteOffset)),e=t.value;return this.shift(t.length),e},e.readVec=function(t){for(var e=this.readULEB(),r=[],n=0;n<e;n++)r.push(t(this,n,e));return r},t}(),jt=function(){function t(t){void 0===t&&(t=1024),this.bytePosition=0,this.dataView=new DataView(new ArrayBuffer(t))}t.toBN=function(t){switch(typeof t){case"bigint":return new n.BN(t.toString());default:return new n.BN(t)}};var e=t.prototype;return e.shift=function(t){return this.bytePosition+=t,this},e.write8=function(e){return this.dataView.setUint8(this.bytePosition,+t.toBN(e)),this.shift(1)},e.write16=function(e){return this.dataView.setUint16(this.bytePosition,+t.toBN(e),!0),this.shift(2)},e.write32=function(e){return this.dataView.setUint32(this.bytePosition,+t.toBN(e),!0),this.shift(4)},e.write64=function(e){var r=this;return t.toBN(e).toArray("le",8).forEach((function(t){return r.write8(t)})),this},e.write128=function(e){var r=this;return t.toBN(e).toArray("le",16).forEach((function(t){return r.write8(t)})),this},e.writeULEB=function(t){var e=this;return function(t){var e=[],r=0;if(0===t)return[0];for(;t>0;)e[r]=127&t,(t>>=7)&&(e[r]|=128),r+=1;return e}(t).forEach((function(t){return e.write8(t)})),this},e.writeVec=function(t,e){var r=this;return this.writeULEB(t.length),Array.from(t).forEach((function(n,o){return e(r,n,o,t.length)})),this},e.toBytes=function(){return new Uint8Array(this.dataView.buffer.slice(0,this.bytePosition))},e.toString=function(t){switch(t){case"base64":return new c(this.toBytes()).toString();case"hex":return new it(this.toBytes()).toString();default:throw new Error("Unsupported encoding, supported values are: base64, hex")}},t}(),Et=function(){function t(){}return t.set=function(t,e,r){return void 0===r&&(r=1024),this.getTypeInterface(t).encode(e,r)},t.de=function(t,e){return this.getTypeInterface(t).decode(e)},t.hasType=function(t){return this.types.has(t)},t.registerType=function(t,e,r,n){return void 0===n&&(n=function(){return!0}),this.types.set(t,{encode:function(t,e){return void 0===e&&(e=1024),this._encodeRaw(new jt(e),t)},decode:function(t){return this._decodeRaw(new Tt(t))},_encodeRaw:function(r,o){if(n(o))return e(r,o);throw new Error("Validation failed for type "+t+", data: "+o)},_decodeRaw:function(t){return r(t)}}),this},t.registerAddressType=function(t,e){return this.registerType(t,(function(t,e){return new it(e).getData().reduce((function(t,e){return t.write8(e)}),t)}),(function(t){return new it(t.readBytes(e)).toString()}))},t.registerVectorType=function(e,r){return this.registerType(e,(function(e,n){return e.writeVec(n,(function(e,n){return t.getTypeInterface(r)._encodeRaw(e,n)}))}),(function(e){return e.readVec((function(e){return t.getTypeInterface(r)._decodeRaw(e)}))}))},t.registerStructType=function(e,r){var n=Object.freeze(r),o=Object.keys(n);return this.registerType(e,(function(e,r){for(var i,u=g(o);!(i=u()).done;){var a=i.value;t.getTypeInterface(n[a])._encodeRaw(e,r[a])}return e}),(function(e){for(var r,i={},u=g(o);!(r=u()).done;){var a=r.value;i[a]=t.getTypeInterface(n[a])._decodeRaw(e)}return i}))},t.registerEnumType=function(e,r){var n=Object.freeze(r),o=Object.keys(n);return this.registerType(e,(function(r,i){var u=Object.keys(i)[0];if(void 0===u)throw new Error("Unknown invariant of the enum "+e);var a=o.indexOf(u);if(-1===a)throw new Error("Unknown invariant of the enum "+e+", allowed values: "+o);var s=n[o[a]];return r.write8(a),null!==s?t.getTypeInterface(s)._encodeRaw(r,i[u]):r}),(function(r){var i,u=r.readULEB(),a=o[u],s=n[a];if(-1===u)throw new Error("Decoding type mismatch, expected enum "+e+" invariant index, received "+u);return(i={})[a]=null===s||t.getTypeInterface(s)._decodeRaw(r),i}))},t.getTypeInterface=function(e){var r=t.types.get(e);if(void 0===r)throw new Error("Type "+e+" is not registered");return r},t}();Et.U8="u8",Et.U32="u32",Et.U64="u64",Et.U128="u128",Et.BOOL="bool",Et.VECTOR="vector",Et.ADDRESS="address",Et.STRING="string",Et.types=new Map,Et.registerType(Et.U8,(function(t,e){return t.write8(e)}),(function(t){return t.read8()}),(function(t){return t<256})),Et.registerType(Et.U32,(function(t,e){return t.write32(e)}),(function(t){return t.read32()}),(function(t){return t<4294967296})),Et.registerType(Et.U64,(function(t,e){return t.write64(e)}),(function(t){return t.read64()}),(function(t){return!0})),Et.registerType(Et.U128,(function(t,e){return t.write128(e)}),(function(t){return t.read128()}),(function(t){return!0})),Et.registerType(Et.BOOL,(function(t,e){return t.write8(e)}),(function(t){return"1"==t.read8().toString(10)}),(function(t){return!0})),Et.registerType(Et.STRING,(function(t,e){return t.writeVec(Array.from(e),(function(t,e){return t.write8(e.charCodeAt(0))}))}),(function(t){return t.readVec((function(t){return t.read8()})).map((function(t){return String.fromCharCode(t)})).join("")}),(function(t){return/^[\x00-\x7F]*$/.test(t)})),exports.BCS={__proto__:null,BcsReader:Tt,BcsWriter:jt,BCS:Et},exports.Base64DataBuffer=c,exports.Coin=mt,exports.Ed25519Keypair=p,exports.HexDataBuffer=it,exports.JsonRpcProvider=ot,exports.PUBLIC_KEY_SIZE=32,exports.Provider=h,exports.PublicKey=f,exports.RawSigner=ct,exports.RpcTxnDataSerializer=ut,exports.SignerWithProvider=st,exports.getExecutionStatus=bt,exports.getExecutionStatusError=function(t){return bt(t).error},exports.getExecutionStatusGasSummary=xt,exports.getExecutionStatusType=function(t){return bt(t).status},exports.getMoveCallTransaction=function(t){return"Call"in t?t.Call:void 0},exports.getMoveObject=wt,exports.getMoveObjectType=vt,exports.getMovePackageContent=function(t){if("disassembled"in t)return t.disassembled;var e=ht(t);return"package"===(null==e?void 0:e.data.dataType)?e.data.disassembled:void 0},exports.getObjectDeletedResponse=yt,exports.getObjectExistsResponse=ht,exports.getObjectFields=gt,exports.getObjectId=function(t){var e,r;return"objectId"in t?t.objectId:null!=(e=null==(r=dt(t))?void 0:r.objectId)?e:lt(t)},exports.getObjectNotExistsResponse=lt,exports.getObjectOwner=function(t){var e;return null==(e=ht(t))?void 0:e.owner},exports.getObjectPreviousTransactionDigest=function(t){var e;return null==(e=ht(t))?void 0:e.previousTransaction},exports.getObjectReference=dt,exports.getObjectType=function(t){var e;return null==(e=ht(t))?void 0:e.data.dataType},exports.getObjectVersion=function(t){var e;return"version"in t?t.version:null==(e=dt(t))?void 0:e.version},exports.getPublishTransaction=function(t){return"Publish"in t?t.Publish:void 0},exports.getTotalGasUsed=function(t){var e=xt(t);return e.computationCost+e.storageCost-e.storageRebate},exports.getTransactionAuthorityQuorumSignInfo=function(t){return t.authSignInfo},exports.getTransactionData=function(t){return t.data},exports.getTransactionDigest=function(t){return t.transactionDigest},exports.getTransactionGasBudget=function(t){return t.data.gasBudget},exports.getTransactionGasObject=function(t){return t.data.gasPayment},exports.getTransactionKindName=function(t){return Object.keys(t)[0]},exports.getTransactionSender=function(t){return t.data.sender},exports.getTransactionSignature=function(t){return t.txSignature},exports.getTransactions=function(t){return t.data.transactions},exports.getTransferCoinTransaction=function(t){return"TransferCoin"in t?t.TransferCoin:void 0},exports.isAuthorityName=function(t,e){return"string"==typeof t},exports.isAuthorityQuorumSignInfo=q,exports.isAuthoritySignature=function(t,e){return"string"==typeof t},exports.isCertifiedTransaction=V,exports.isEd25519KeypairData=function(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&t.publicKey instanceof Uint8Array&&t.secretKey instanceof Uint8Array},exports.isEmptySignInfo=function(t,e){return"object"==typeof t},exports.isEpochId=function(t,e){return"number"==typeof t},exports.isEvent=J,exports.isExecutionStatus=W,exports.isExecutionStatusType=G,exports.isGasCostSummary=K,exports.isGatewayTxSeqNumber=function(t,e){return"number"==typeof t},exports.isGetObjectInfoResponse=C,exports.isGetOwnedObjectRefsResponse=P,exports.isGetTxnDigestsResponse=Z,exports.isKeypair=function(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&"function"==typeof t.getPublicKey&&"function"==typeof t.signData},exports.isMoveCall=$,exports.isMovePackageContent=O,exports.isObjectContentFields=E,exports.isObjectDigest=function(t,e){return"string"==typeof t},exports.isObjectId=function(t,e){return"string"==typeof t},exports.isObjectOwner=T,exports.isObjectStatus=R,exports.isObjectType=B,exports.isOwnedObjectRef=M,exports.isPublicKeyData=x,exports.isPublicKeyInitData=function(t,e){return m(t)||I(t)||t instanceof Buffer||t instanceof Uint8Array||Array.isArray(t)&&t.every((function(t){return I(t)}))||x(t)},exports.isRawAuthoritySignInfo=N,exports.isSequenceNumber=I,exports.isSplitCoinResponse=X,exports.isSuiAddress=function(t,e){return"string"==typeof t},exports.isSuiData=S,exports.isSuiJsonValue=Y,exports.isSuiMoveObject=A,exports.isSuiMovePackage=k,exports.isSuiObject=_,exports.isSuiObjectRef=j,exports.isSuiTransactionKind=D,exports.isTransactionBytes=Q,exports.isTransactionData=U,exports.isTransactionDigest=m,exports.isTransactionEffects=z,exports.isTransactionEffectsResponse=F,exports.isTransactionKindName=function(t,e){return"TransferCoin"===t||"Publish"===t||"Call"===t},exports.isTransactionResponse=H,exports.isTransferCoin=L,exports.isTransferCoinTransaction=function(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.signer)&&m(t.objectId)&&m(t.gasPayment)&&I(t.gasBudget)&&m(t.recipient)},exports.isTxnDataSerializer=function(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&"function"==typeof t.newTransferCoin},exports.isValidSuiAddress=pt,exports.isValidSuiObjectId=function(t){return pt(t)},exports.isValidTransactionDigest=function(t){return 32===new c(t).getLength()&&ft.test(t)}; | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("tweetnacl")),r=require("buffer"),n=require("bn.js"),i=t(n),o=require("js-sha3"),u=require("util"),s=t(require("jayson/lib/client/browser")),a=t(require("cross-fetch")),c=function(){function t(t){this.data="string"==typeof t?new Uint8Array(r.Buffer.from(t,"base64")):t}var e=t.prototype;return e.getData=function(){return this.data},e.getLength=function(){return this.data.length},e.toString=function(){return r.Buffer.from(this.data).toString("base64")},t}(),f=function(){function t(t){if(function(t){return void 0!==t._bn}(t))this._bn=t._bn;else{if("string"==typeof t){var e=r.Buffer.from(t,"base64");if(32!==e.length)throw new Error("Invalid public key input. Expected 32 bytes, got "+e.length);this._bn=new i(e)}else this._bn=new i(t);if(this._bn.byteLength()>32)throw new Error("Invalid public key input")}}var e=t.prototype;return e.equals=function(t){return this._bn.eq(t._bn)},e.toBase64=function(){return this.toBuffer().toString("base64")},e.toBytes=function(){return this.toBuffer()},e.toBuffer=function(){var t=this._bn.toArrayLike(r.Buffer);if(32===t.length)return t;var e=r.Buffer.alloc(32);return t.copy(e,32-t.length),e},e.toString=function(){return this.toBase64()},e.toSuiAddress=function(){var t=o.sha3_256(this.toBytes());return new i(t,16).toArray(void 0,32).slice(0,20).reduce((function(t,e){return t+("0"+e.toString(16)).slice(-2)}),"")},t}(),p=function(){function t(t){this.keypair=t||e.sign.keyPair()}t.generate=function(){return new t(e.sign.keyPair())},t.fromSecretKey=function(r,n){var i=e.sign.keyPair.fromSecretKey(r);if(!n||!n.skipValidation){var o=(new u.TextEncoder).encode("sui validation"),s=e.sign.detached(o,i.secretKey);if(!e.sign.detached.verify(o,s,i.publicKey))throw new Error("provided secretKey is invalid")}return new t(i)},t.fromSeed=function(r){return new t(e.sign.keyPair.fromSeed(r))};var r=t.prototype;return r.getPublicKey=function(){return new f(this.keypair.publicKey)},r.signData=function(t){return new c(e.sign.detached(t.getData(),this.keypair.secretKey))},t}(),h=function(){};function y(t,e,r,n,i,o,u){try{var s=t[o](u),a=s.value}catch(t){return void r(t)}s.done?e(a):Promise.resolve(a).then(n,i)}function l(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function u(t){y(o,n,i,u,s,"next",t)}function s(t){y(o,n,i,u,s,"throw",t)}u(void 0)}))}}function d(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,(Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function v(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function g(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return v(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?v(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var w,b=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",u=n.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function a(t,e,r,n){var i=Object.create((e&&e.prototype instanceof p?e:p).prototype),o=new T(n||[]);return i._invoke=function(t,e,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(r.method=i,r.arg=o;;){var u=r.delegate;if(u){var s=x(u,r);if(s){if(s===f)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var a=c(t,e,r);if("normal"===a.type){if(n=r.done?"completed":"suspendedYield",a.arg===f)continue;return{value:a.arg,done:r.done}}"throw"===a.type&&(n="completed",r.method="throw",r.arg=a.arg)}}}(t,r,o),i}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=a;var f={};function p(){}function h(){}function y(){}var l={};s(l,i,(function(){return this}));var d=Object.getPrototypeOf,v=d&&d(d(E([])));v&&v!==e&&r.call(v,i)&&(l=v);var g=y.prototype=p.prototype=Object.create(l);function w(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var n;this._invoke=function(i,o){function u(){return new e((function(n,u){!function n(i,o,u,s){var a=c(t[i],t,o);if("throw"!==a.type){var f=a.arg,p=f.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,u,s)}),(function(t){n("throw",t,u,s)})):e.resolve(p).then((function(t){f.value=t,u(f)}),(function(t){return n("throw",t,u,s)}))}s(a.arg)}(i,o,n,u)}))}return n=n?n.then(u,u):u()}}function x(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=c(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var i=n.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function m(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function T(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(m,this),this.reset(!0)}function E(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:A}}function A(){return{value:void 0,done:!0}}return h.prototype=y,s(g,"constructor",y),s(y,"constructor",h),h.displayName=s(y,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,s(t,u,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},w(b.prototype),s(b.prototype,o,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var u=new b(a(e,r,n,i),o);return t.isGeneratorFunction(r)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},w(g),s(g,u,"Generator"),s(g,i,(function(){return this})),s(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=E,T.prototype={constructor:T,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(j),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return u.type="throw",u.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],u=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var s=r.call(o,"catchLoc"),a=r.call(o,"finallyLoc");if(s&&a){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!a)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var u=o?o.completion:{};return u.type=t,u.arg=e,o?(this.method="next",this.next=o.finallyLoc,f):this.complete(u)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;j(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:E(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(w={exports:{}}),w.exports);function x(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&t._bn instanceof n.BN}function m(t,e){return"string"==typeof t}function j(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.AddressOwner)||(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.ObjectOwner)||"Shared"===t||"Immutable"===t}function T(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.digest)&&m(t.objectId)&&L(t.version)}function E(t,e){return T(t)&&(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.type)&&j(t.owner)&&m(t.previousTransaction)}function A(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&Object.entries(t).every((function(t){return m(t[0])}))}function S(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&Object.entries(t).every((function(t){var e=t[0];return m(t[1])&&m(e)}))}function O(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&P(t.dataType)&&C(t)||(null!==t&&"object"==typeof t||"function"==typeof t)&&P(t.dataType)&&k(t)}function C(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.type)&&A(t.fields)}function k(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&S(t.disassembled)}function B(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&O(t.data)&&j(t.owner)&&m(t.previousTransaction)&&L(t.storageRebate)&&T(t.reference)}function R(t,e){return"Exists"===t||"NotExists"===t||"Deleted"===t}function P(t,e){return"moveObject"===t||"package"===t}function _(t,e){return Array.isArray(t)&&t.every((function(t){return E(t)}))}function I(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&R(t.status)&&(m(t.details)||T(t.details)||B(t.details))}function L(t,e){return"number"==typeof t}function N(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.recipient)&&T(t.objectRef)}function D(t,e){return Array.isArray(t)&&m(t[0])&&m(t[1])}function q(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&N(t.TransferCoin)||(null!==t&&"object"==typeof t||"function"==typeof t)&&k(t.Publish)||(null!==t&&"object"==typeof t||"function"==typeof t)&&Y(t.Call)}function U(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&Array.isArray(t.transactions)&&t.transactions.every((function(t){return q(t)}))&&m(t.sender)&&T(t.gasPayment)&&L(t.gasBudget)}function V(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&L(t.epoch)&&Array.isArray(t.signatures)&&t.signatures.every((function(t){return D(t)}))}function M(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.transactionDigest)&&U(t.data)&&m(t.txSignature)&&V(t.authSignInfo)}function K(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&L(t.computationCost)&&L(t.storageCost)&&L(t.storageRebate)}function G(t,e){return"success"===t||"failure"===t}function W(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&G(t.status)&&K(t.gas_cost)&&(void 0===t.error||m(t.error))}function z(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&j(t.owner)&&T(t.reference)}function F(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&W(t.status)&&(void 0===t.sharedObjects||Array.isArray(t.sharedObjects)&&t.sharedObjects.every((function(t){return T(t)})))&&m(t.transactionDigest)&&(void 0===t.created||Array.isArray(t.created)&&t.created.every((function(t){return z(t)})))&&(void 0===t.mutated||Array.isArray(t.mutated)&&t.mutated.every((function(t){return z(t)})))&&(void 0===t.unwrapped||Array.isArray(t.unwrapped)&&t.unwrapped.every((function(t){return z(t)})))&&(void 0===t.deleted||Array.isArray(t.deleted)&&t.deleted.every((function(t){return T(t)})))&&(void 0===t.wrapped||Array.isArray(t.wrapped)&&t.wrapped.every((function(t){return T(t)})))&&z(t.gasObject)&&(void 0===t.events||Array.isArray(t.events)&&t.events.every((function(t){return $(t)})))&&(void 0===t.dependencies||Array.isArray(t.dependencies)&&t.dependencies.every((function(t){return m(t)})))}function Z(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&M(t.certificate)&&F(t.effects)}function J(t,e){return Array.isArray(t)&&t.every((function(t){return Array.isArray(t)&&L(t[0])&&m(t[1])}))}function $(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.type_)}function Y(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&T(t.package)&&m(t.module)&&m(t.function)&&(void 0===t.typeArguments||Array.isArray(t.typeArguments)&&t.typeArguments.every((function(t){return m(t)})))&&(void 0===t.arguments||Array.isArray(t.arguments)&&t.arguments.every((function(t){return Q(t)})))}function Q(t,e){return m(t)||L(t)||!1===t||!0===t||Array.isArray(t)&&t.every((function(t){return m(t)||L(t)||!1===t||!0===t}))}function X(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.txBytes)&&T(t.gas)}function H(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&M(t.certificate)&&B(t.updatedCoin)&&B(t.updatedGas)}function tt(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&M(t.certificate)&&B(t.updatedCoin)&&Array.isArray(t.newCoins)&&t.newCoins.every((function(t){return B(t)}))&&B(t.updatedGas)}function et(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&Z(t.EffectResponse)||(null!==t&&"object"==typeof t||"function"==typeof t)&&tt(t.SplitCoinResponse)||(null!==t&&"object"==typeof t||"function"==typeof t)&&H(t.MergeCoinResponse)}function rt(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&"2.0"===t.jsonrpc&&m(t.id)}var nt=require("lossless-json"),it=function(){function t(t,e){this.rpcClient=this.createRpcClient(t,e)}var e=t.prototype;return e.createRpcClient=function(t,e){return new s(function(){var r=l(b.mark((function r(n,i){var o,u,s,c;return b.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return o={method:"POST",body:n,headers:Object.assign({"Content-Type":"application/json"},e||{})},r.prev=1,r.next=4,a(t,o);case 4:return u=r.sent,r.next=7,u.text();case 7:s=r.sent,c=JSON.stringify(nt.parse(s,(function(t,e){if("balance"===t)return e.toString();try{if(e.isLosslessNumber)return e.valueOf()}catch(t){return e.toString()}return e}))),u.ok?i(null,c):i(new Error(u.status+" "+u.statusText+": "+s)),r.next=15;break;case 12:r.prev=12,r.t0=r.catch(1),r.t0 instanceof Error&&i(r.t0);case 15:case"end":return r.stop()}}),r,null,[[1,12]])})));return function(t,e){return r.apply(this,arguments)}}(),{})},e.requestWithType=function(){var t=l(b.mark((function t(e,r,n){var i;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.request(e,r);case 2:if((null===(o=i=t.sent)||"object"!=typeof o)&&"function"!=typeof o||"2.0"!==o.jsonrpc||!m(o.id)||(null===o.error||"object"!=typeof o.error)&&"function"!=typeof o.error||!m(o.error.message)){t.next=7;break}throw new Error("RPC Error: "+i.error.message);case 7:if(!rt(i)){t.next=13;break}if(!n(i.result)){t.next=12;break}return t.abrupt("return",i.result);case 12:throw new Error("RPC Error: result not of expected type. Result received was: "+JSON.stringify(i.result));case 13:throw new Error("Unexpected RPC Response: "+i);case 14:case"end":return t.stop()}var o}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),e.request=function(){var t=l(b.mark((function t(e,r){var n=this;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise((function(t,i){n.rpcClient.request(e,r,(function(e,r){e?i(e):t(r)}))})));case 1:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),e.batchRequestWithType=function(){var t=l(b.mark((function t(e,r){var n;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.batchRequest(e);case 2:return n=t.sent.filter((function(t){return rt(t)&&r(t.result)})),t.abrupt("return",n.map((function(t){return t.result})));case 5:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.batchRequest=function(){var t=l(b.mark((function t(e){var r=this;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise((function(t,n){0===e.length&&t([]);var i=e.map((function(t){return r.rpcClient.request(t.method,t.args)}));r.rpcClient.request(i,(function(e,r){e?n(e):t(r)}))})));case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t}(),ot=function(t){return"number"==typeof t},ut=function(t){function e(e){var r;return(r=t.call(this)||this).endpoint=e,r.client=new it(e),r}d(e,t);var r=e.prototype;return r.getObjectsOwnedByAddress=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_getObjectsOwnedByAddress",[e],_);case 3:return t.abrupt("return",t.sent);case 6:throw t.prev=6,t.t0=t.catch(0),new Error("Error fetching owned object: "+t.t0+" for address "+e);case 9:case"end":return t.stop()}}),t,this,[[0,6]])})));return function(e){return t.apply(this,arguments)}}(),r.getObjectsOwnedByObject=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_getObjectsOwnedByObject",[e],_);case 3:return t.abrupt("return",t.sent);case 6:throw t.prev=6,t.t0=t.catch(0),new Error("Error fetching owned object: "+t.t0+" for objectId "+e);case 9:case"end":return t.stop()}}),t,this,[[0,6]])})));return function(e){return t.apply(this,arguments)}}(),r.getObject=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_getObject",[e],I);case 3:return t.abrupt("return",t.sent);case 6:throw t.prev=6,t.t0=t.catch(0),new Error("Error fetching object info: "+t.t0+" for id "+e);case 9:case"end":return t.stop()}}),t,this,[[0,6]])})));return function(e){return t.apply(this,arguments)}}(),r.getObjectBatch=function(){var t=l(b.mark((function t(e){var r;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.map((function(t){return{method:"sui_getObject",args:[t]}})),t.prev=1,t.next=4,this.client.batchRequestWithType(r,I);case 4:return t.abrupt("return",t.sent);case 7:throw t.prev=7,t.t0=t.catch(1),new Error("Error fetching object info: "+t.t0+" for id "+e);case 10:case"end":return t.stop()}}),t,this,[[1,7]])})));return function(e){return t.apply(this,arguments)}}(),r.getTransactionWithEffects=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_getTransaction",[e],Z);case 3:return t.abrupt("return",t.sent);case 7:throw t.prev=7,t.t0=t.catch(0),new Error("Error getting transaction with effects: "+t.t0+" for digest "+e);case 10:case"end":return t.stop()}}),t,this,[[0,7]])})));return function(e){return t.apply(this,arguments)}}(),r.getTransactionWithEffectsBatch=function(){var t=l(b.mark((function t(e){var r,n;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.map((function(t){return{method:"sui_getTransaction",args:[t]}})),t.prev=1,t.next=4,this.client.batchRequestWithType(r,Z);case 4:return t.abrupt("return",t.sent);case 7:throw t.prev=7,t.t0=t.catch(1),n=e.join(", ").substring(0,-2),new Error("Error getting transaction effects: "+t.t0+" for digests ["+n+"]");case 11:case"end":return t.stop()}}),t,this,[[1,7]])})));return function(e){return t.apply(this,arguments)}}(),r.executeTransaction=function(){var t=l(b.mark((function t(e,r,n){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_executeTransaction",[e,r,n],et);case 3:return t.abrupt("return",t.sent);case 7:throw t.prev=7,t.t0=t.catch(0),new Error("Error executing transaction: "+t.t0+"}");case 10:case"end":return t.stop()}}),t,this,[[0,7]])})));return function(e,r,n){return t.apply(this,arguments)}}(),r.getTotalTransactionNumber=function(){var t=l(b.mark((function t(){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_getTotalTransactionNumber",[],ot);case 3:return t.abrupt("return",t.sent);case 7:throw t.prev=7,t.t0=t.catch(0),new Error("Error fetching total transaction number: "+t.t0);case 10:case"end":return t.stop()}}),t,this,[[0,7]])})));return function(){return t.apply(this,arguments)}}(),r.getTransactionDigestsInRange=function(){var t=l(b.mark((function t(e,r){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_getTransactionsInRange",[e,r],J);case 3:return t.abrupt("return",t.sent);case 6:throw t.prev=6,t.t0=t.catch(0),new Error("Error fetching transaction digests in range: "+t.t0+" for range "+e+"-"+r);case 9:case"end":return t.stop()}}),t,this,[[0,6]])})));return function(e,r){return t.apply(this,arguments)}}(),r.getRecentTransactions=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_getRecentTransactions",[e],J);case 3:return t.abrupt("return",t.sent);case 6:throw t.prev=6,t.t0=t.catch(0),new Error("Error fetching recent transactions: "+t.t0+" for count "+e);case 9:case"end":return t.stop()}}),t,this,[[0,6]])})));return function(e){return t.apply(this,arguments)}}(),e}(h),st=function(){function t(t){this._data="string"==typeof t?new Uint8Array(r.Buffer.from(t,"hex")):t}var e=t.prototype;return e.getData=function(){return this._data},e.getLength=function(){return this._data.length},e.toString=function(){return r.Buffer.from(this._data).toString("hex")},t}(),at=function(){function t(t){this.client=new it(t)}var e=t.prototype;return e.newTransferCoin=function(){var t=l(b.mark((function t(e,r){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_transferCoin",[e,r.objectId,r.gasPayment,r.gasBudget,r.recipient],X);case 3:return t.abrupt("return",new c(t.sent.txBytes));case 7:throw t.prev=7,t.t0=t.catch(0),new Error("Error transferring coin: "+t.t0+" with args "+r);case 10:case"end":return t.stop()}}),t,this,[[0,7]])})));return function(e,r){return t.apply(this,arguments)}}(),e.newMoveCall=function(){var t=l(b.mark((function t(e,r){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_moveCall",[e,r.packageObjectId,r.module,r.function,r.typeArguments,r.arguments,r.gasPayment,r.gasBudget],X);case 3:return t.abrupt("return",new c(t.sent.txBytes));case 7:throw t.prev=7,t.t0=t.catch(0),new Error("Error executing a move call: "+t.t0+" with args "+r);case 10:case"end":return t.stop()}}),t,this,[[0,7]])})));return function(e,r){return t.apply(this,arguments)}}(),e.newMergeCoin=function(){var t=l(b.mark((function t(e,r){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_mergeCoins",[e,r.primaryCoin,r.coinToMerge,r.gasPayment,r.gasBudget],X);case 3:return t.abrupt("return",new c(t.sent.txBytes));case 7:throw t.prev=7,t.t0=t.catch(0),new Error("Error merging coin: "+t.t0);case 10:case"end":return t.stop()}}),t,this,[[0,7]])})));return function(e,r){return t.apply(this,arguments)}}(),e.newSplitCoin=function(){var t=l(b.mark((function t(e,r){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.requestWithType("sui_splitCoin",[e,r.coinObjectId,r.splitAmounts,r.gasPayment,r.gasBudget],X);case 3:return t.abrupt("return",new c(t.sent.txBytes));case 7:throw t.prev=7,t.t0=t.catch(0),new Error("Error splitting coin: "+t.t0);case 10:case"end":return t.stop()}}),t,this,[[0,7]])})));return function(e,r){return t.apply(this,arguments)}}(),t}(),ct=function(t){function e(){return t.apply(this,arguments)||this}d(e,t);var r=e.prototype;return r.getObjectsOwnedByAddress=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw this.newError("getOwnedObjects");case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getObject=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw this.newError("getObject");case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getTransaction=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw this.newError("getTransaction");case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.executeTransaction=function(){var t=l(b.mark((function t(e,r,n){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw this.newError("executeTransaction");case 1:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.getTotalTransactionNumber=function(){var t=l(b.mark((function t(){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw this.newError("getTotalTransactionNumber");case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.getTransactionDigestsInRange=function(){var t=l(b.mark((function t(e,r){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw this.newError("getTransactionDigestsInRange");case 1:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r.getRecentTransactions=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw this.newError("getRecentTransactions");case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.newError=function(t){return new Error("Please use a valid provider for "+t)},e}(h),ft=function(){function t(t,e){this.provider=t||new ct;var r="";this.provider instanceof ut&&(r=this.provider.endpoint),this.serializer=e||new at(r)}var e=t.prototype;return e.signAndExecuteTransaction=function(){var t=l(b.mark((function t(e){var r;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.signData(e);case 2:return r=t.sent,t.next=5,this.provider.executeTransaction(e.toString(),r.signature.toString(),r.pubKey.toString());case 5:return t.abrupt("return",t.sent);case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.transferCoin=function(){var t=l(b.mark((function t(e){var r,n;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getAddress();case 2:return r=t.sent,t.next=5,this.serializer.newTransferCoin(r,e);case 5:return n=t.sent,t.next=8,this.signAndExecuteTransaction(n);case 8:return t.abrupt("return",t.sent);case 9:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.mergeCoin=function(){var t=l(b.mark((function t(e){var r,n;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getAddress();case 2:return r=t.sent,t.next=5,this.serializer.newMergeCoin(r,e);case 5:return n=t.sent,t.next=8,this.signAndExecuteTransaction(n);case 8:return t.abrupt("return",t.sent);case 9:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.splitCoin=function(){var t=l(b.mark((function t(e){var r,n;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getAddress();case 2:return r=t.sent,t.next=5,this.serializer.newSplitCoin(r,e);case 5:return n=t.sent,t.next=8,this.signAndExecuteTransaction(n);case 8:return t.abrupt("return",t.sent);case 9:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.executeMoveCall=function(){var t=l(b.mark((function t(e){var r,n;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getAddress();case 2:return r=t.sent,t.next=5,this.serializer.newMoveCall(r,e);case 5:return n=t.sent,t.next=8,this.signAndExecuteTransaction(n);case 8:return t.abrupt("return",t.sent);case 9:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(),pt=function(t){function e(e,r,n){var i;return(i=t.call(this,r,n)||this).keypair=e,i}d(e,t);var r=e.prototype;return r.getAddress=function(){var t=l(b.mark((function t(){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.keypair.getPublicKey().toSuiAddress());case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.signData=function(){var t=l(b.mark((function t(e){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",{signature:this.keypair.signData(e),pubKey:this.keypair.getPublicKey()});case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.connect=function(t){return new e(this.keypair,t)},e}(ft),ht=/^(?:[a-zA-Z0-9+\/]{4})*(?:|(?:[a-zA-Z0-9+\/]{3}=)|(?:[a-zA-Z0-9+\/]{2}==)|(?:[a-zA-Z0-9+\/]{1}===))$/;function yt(t){return function(t){return/^(0x|0X)?[a-fA-F0-9]+$/.test(t)&&t.length%2==0}(t)&&20===function(t){return/^(0x|0X)/.test(t)?(t.length-2)/2:t.length/2}(t)}function lt(t){return"Exists"!==t.status?void 0:t.details}function dt(t){return"Deleted"!==t.status?void 0:t.details}function vt(t){return"NotExists"!==t.status?void 0:t.details}function gt(t){var e;return(null==(e=lt(t))?void 0:e.reference)||dt(t)}function wt(t){var e;return null==(e=xt(t))?void 0:e.type}function bt(t){var e;return null==(e=xt(t))?void 0:e.fields}function xt(t){var e="data"in t?t:lt(t);if("moveObject"===(null==e?void 0:e.data.dataType))return e.data}function mt(t){return t.effects.status}function jt(t){return mt(t).gas_cost}function Tt(t){return"SplitCoinResponse"in t?t.SplitCoinResponse:void 0}function Et(t){return"MergeCoinResponse"in t?t.MergeCoinResponse:void 0}var At=function(){function t(){}return t.isCoin=function(t){var e,r;return null!=(e=null==(r=wt(t))?void 0:r.startsWith("0x2::Coin::Coin"))&&e},t.getBalance=function(e){var r;if(t.isCoin(e)){var n=null==(r=bt(e))?void 0:r.balance;return new i.BN(n,10)}},t.getZero=function(){return new i.BN("0",10)},t}(),St=function(){function t(t){this.bytePosition=0,this.dataView=new DataView(t.buffer)}var e=t.prototype;return e.shift=function(t){return this.bytePosition+=t,this},e.read8=function(){var t=this.dataView.getUint8(this.bytePosition);return this.shift(1),new n.BN(t,10)},e.read16=function(){var t=this.dataView.getUint16(this.bytePosition,!0);return this.shift(2),new n.BN(t,10)},e.read32=function(){var t=this.dataView.getUint32(this.bytePosition,!0);return this.shift(4),new n.BN(t,10)},e.read64=function(){var t=this.read32(),e=this.read32().toString(16)+t.toString(16).padStart(8,"0");return new n.BN(e,16)},e.read128=function(){var t=this.read64(),e=this.read64().toString(16)+t.toString(16).padStart(8,"0");return new n.BN(e,16)},e.readBytes=function(t){var e=new Uint8Array(this.dataView.buffer,this.bytePosition+this.dataView.byteOffset,t);return this.shift(t),e},e.readULEB=function(){var t=function(t){for(var e=0,r=0,n=0;;){var i=t[n];if(n+=1,e|=(127&i)<<r,0==(128&i))break;r+=7}return{value:e,length:n}}(new Uint8Array(this.dataView.buffer,this.bytePosition+this.dataView.byteOffset)),e=t.value;return this.shift(t.length),e},e.readVec=function(t){for(var e=this.readULEB(),r=[],n=0;n<e;n++)r.push(t(this,n,e));return r},t}(),Ot=function(){function t(t){void 0===t&&(t=1024),this.bytePosition=0,this.dataView=new DataView(new ArrayBuffer(t))}t.toBN=function(t){switch(typeof t){case"bigint":return new n.BN(t.toString());default:return new n.BN(t)}};var e=t.prototype;return e.shift=function(t){return this.bytePosition+=t,this},e.write8=function(e){return this.dataView.setUint8(this.bytePosition,+t.toBN(e)),this.shift(1)},e.write16=function(e){return this.dataView.setUint16(this.bytePosition,+t.toBN(e),!0),this.shift(2)},e.write32=function(e){return this.dataView.setUint32(this.bytePosition,+t.toBN(e),!0),this.shift(4)},e.write64=function(e){var r=this;return t.toBN(e).toArray("le",8).forEach((function(t){return r.write8(t)})),this},e.write128=function(e){var r=this;return t.toBN(e).toArray("le",16).forEach((function(t){return r.write8(t)})),this},e.writeULEB=function(t){var e=this;return function(t){var e=[],r=0;if(0===t)return[0];for(;t>0;)e[r]=127&t,(t>>=7)&&(e[r]|=128),r+=1;return e}(t).forEach((function(t){return e.write8(t)})),this},e.writeVec=function(t,e){var r=this;return this.writeULEB(t.length),Array.from(t).forEach((function(n,i){return e(r,n,i,t.length)})),this},e.toBytes=function(){return new Uint8Array(this.dataView.buffer.slice(0,this.bytePosition))},e.toString=function(t){switch(t){case"base64":return new c(this.toBytes()).toString();case"hex":return new st(this.toBytes()).toString();default:throw new Error("Unsupported encoding, supported values are: base64, hex")}},t}(),Ct=function(){function t(){}return t.set=function(t,e,r){return void 0===r&&(r=1024),this.getTypeInterface(t).encode(e,r)},t.de=function(t,e){return this.getTypeInterface(t).decode(e)},t.hasType=function(t){return this.types.has(t)},t.registerType=function(t,e,r,n){return void 0===n&&(n=function(){return!0}),this.types.set(t,{encode:function(t,e){return void 0===e&&(e=1024),this._encodeRaw(new Ot(e),t)},decode:function(t){return this._decodeRaw(new St(t))},_encodeRaw:function(r,i){if(n(i))return e(r,i);throw new Error("Validation failed for type "+t+", data: "+i)},_decodeRaw:function(t){return r(t)}}),this},t.registerAddressType=function(t,e){return this.registerType(t,(function(t,e){return new st(e).getData().reduce((function(t,e){return t.write8(e)}),t)}),(function(t){return new st(t.readBytes(e)).toString()}))},t.registerVectorType=function(e,r){return this.registerType(e,(function(e,n){return e.writeVec(n,(function(e,n){return t.getTypeInterface(r)._encodeRaw(e,n)}))}),(function(e){return e.readVec((function(e){return t.getTypeInterface(r)._decodeRaw(e)}))}))},t.registerStructType=function(e,r){var n=Object.freeze(r),i=Object.keys(n);return this.registerType(e,(function(e,r){for(var o,u=g(i);!(o=u()).done;){var s=o.value;t.getTypeInterface(n[s])._encodeRaw(e,r[s])}return e}),(function(e){for(var r,o={},u=g(i);!(r=u()).done;){var s=r.value;o[s]=t.getTypeInterface(n[s])._decodeRaw(e)}return o}))},t.registerEnumType=function(e,r){var n=Object.freeze(r),i=Object.keys(n);return this.registerType(e,(function(r,o){var u=Object.keys(o)[0];if(void 0===u)throw new Error("Unknown invariant of the enum "+e);var s=i.indexOf(u);if(-1===s)throw new Error("Unknown invariant of the enum "+e+", allowed values: "+i);var a=n[i[s]];return r.write8(s),null!==a?t.getTypeInterface(a)._encodeRaw(r,o[u]):r}),(function(r){var o,u=r.readULEB(),s=i[u],a=n[s];if(-1===u)throw new Error("Decoding type mismatch, expected enum "+e+" invariant index, received "+u);return(o={})[s]=null===a||t.getTypeInterface(a)._decodeRaw(r),o}))},t.getTypeInterface=function(e){var r=t.types.get(e);if(void 0===r)throw new Error("Type "+e+" is not registered");return r},t}();Ct.U8="u8",Ct.U32="u32",Ct.U64="u64",Ct.U128="u128",Ct.BOOL="bool",Ct.VECTOR="vector",Ct.ADDRESS="address",Ct.STRING="string",Ct.types=new Map,Ct.registerType(Ct.U8,(function(t,e){return t.write8(e)}),(function(t){return t.read8()}),(function(t){return t<256})),Ct.registerType(Ct.U32,(function(t,e){return t.write32(e)}),(function(t){return t.read32()}),(function(t){return t<4294967296})),Ct.registerType(Ct.U64,(function(t,e){return t.write64(e)}),(function(t){return t.read64()}),(function(t){return!0})),Ct.registerType(Ct.U128,(function(t,e){return t.write128(e)}),(function(t){return t.read128()}),(function(t){return!0})),Ct.registerType(Ct.BOOL,(function(t,e){return t.write8(e)}),(function(t){return"1"==t.read8().toString(10)}),(function(t){return!0})),Ct.registerType(Ct.STRING,(function(t,e){return t.writeVec(Array.from(e),(function(t,e){return t.write8(e.charCodeAt(0))}))}),(function(t){return t.readVec((function(t){return t.read8()})).map((function(t){return String.fromCharCode(t)})).join("")}),(function(t){return/^[\x00-\x7F]*$/.test(t)})),exports.BCS={__proto__:null,BcsReader:St,BcsWriter:Ot,BCS:Ct},exports.Base64DataBuffer=c,exports.Coin=At,exports.Ed25519Keypair=p,exports.HexDataBuffer=st,exports.JsonRpcProvider=ut,exports.PUBLIC_KEY_SIZE=32,exports.Provider=h,exports.PublicKey=f,exports.RawSigner=pt,exports.RpcTxnDataSerializer=at,exports.SignerWithProvider=ft,exports.getCoinAfterMerge=function(t){var e;return null==(e=Et(t))?void 0:e.updatedCoin},exports.getCoinAfterSplit=function(t){var e;return null==(e=Tt(t))?void 0:e.updatedCoin},exports.getExecutionStatus=mt,exports.getExecutionStatusError=function(t){return mt(t).error},exports.getExecutionStatusGasSummary=jt,exports.getExecutionStatusType=function(t){return mt(t).status},exports.getMergeCoinResponse=Et,exports.getMoveCallTransaction=function(t){return"Call"in t?t.Call:void 0},exports.getMoveObject=xt,exports.getMoveObjectType=wt,exports.getMovePackageContent=function(t){if("disassembled"in t)return t.disassembled;var e=lt(t);return"package"===(null==e?void 0:e.data.dataType)?e.data.disassembled:void 0},exports.getNewlyCreatedCoinsAfterSplit=function(t){var e;return null==(e=Tt(t))?void 0:e.newCoins},exports.getObjectDeletedResponse=dt,exports.getObjectExistsResponse=lt,exports.getObjectFields=bt,exports.getObjectId=function(t){var e,r;return"objectId"in t?t.objectId:null!=(e=null==(r=gt(t))?void 0:r.objectId)?e:vt(t)},exports.getObjectNotExistsResponse=vt,exports.getObjectOwner=function(t){var e;return null==(e=lt(t))?void 0:e.owner},exports.getObjectPreviousTransactionDigest=function(t){var e;return null==(e=lt(t))?void 0:e.previousTransaction},exports.getObjectReference=gt,exports.getObjectType=function(t){var e;return null==(e=lt(t))?void 0:e.data.dataType},exports.getObjectVersion=function(t){var e;return"version"in t?t.version:null==(e=gt(t))?void 0:e.version},exports.getPublishTransaction=function(t){return"Publish"in t?t.Publish:void 0},exports.getSplitCoinResponse=Tt,exports.getTotalGasUsed=function(t){var e=jt(t);return e.computationCost+e.storageCost-e.storageRebate},exports.getTransactionAuthorityQuorumSignInfo=function(t){return t.authSignInfo},exports.getTransactionData=function(t){return t.data},exports.getTransactionDigest=function(t){return t.transactionDigest},exports.getTransactionEffectsResponse=function(t){return"EffectResponse"in t?t.EffectResponse:void 0},exports.getTransactionGasBudget=function(t){return t.data.gasBudget},exports.getTransactionGasObject=function(t){return t.data.gasPayment},exports.getTransactionKindName=function(t){return Object.keys(t)[0]},exports.getTransactionSender=function(t){return t.data.sender},exports.getTransactionSignature=function(t){return t.txSignature},exports.getTransactions=function(t){return t.data.transactions},exports.getTransferCoinTransaction=function(t){return"TransferCoin"in t?t.TransferCoin:void 0},exports.isAuthorityName=function(t,e){return"string"==typeof t},exports.isAuthorityQuorumSignInfo=V,exports.isAuthoritySignature=function(t,e){return"string"==typeof t},exports.isCertifiedTransaction=M,exports.isEd25519KeypairData=function(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&t.publicKey instanceof Uint8Array&&t.secretKey instanceof Uint8Array},exports.isEmptySignInfo=function(t,e){return"object"==typeof t},exports.isEpochId=function(t,e){return"number"==typeof t},exports.isEvent=$,exports.isExecutionStatus=W,exports.isExecutionStatusType=G,exports.isGasCostSummary=K,exports.isGatewayTxSeqNumber=function(t,e){return"number"==typeof t},exports.isGetObjectDataResponse=I,exports.isGetOwnedObjectsResponse=_,exports.isGetTxnDigestsResponse=J,exports.isKeypair=function(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&"function"==typeof t.getPublicKey&&"function"==typeof t.signData},exports.isMergeCoinResponse=H,exports.isMergeCoinTransaction=function(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.primaryCoin)&&m(t.coinToMerge)&&(void 0===t.gasPayment||m(t.gasPayment))&&L(t.gasBudget)},exports.isMoveCall=Y,exports.isMoveCallTransaction=function(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.packageObjectId)&&m(t.module)&&m(t.function)&&Array.isArray(t.typeArguments)&&t.typeArguments.every((function(t){return m(t)}))&&Array.isArray(t.arguments)&&t.arguments.every((function(t){return Q(t)}))&&(void 0===t.gasPayment||m(t.gasPayment))&&L(t.gasBudget)},exports.isMovePackageContent=S,exports.isObjectContentFields=A,exports.isObjectDigest=function(t,e){return"string"==typeof t},exports.isObjectId=function(t,e){return"string"==typeof t},exports.isObjectOwner=j,exports.isObjectStatus=R,exports.isObjectType=P,exports.isOwnedObjectRef=z,exports.isPublicKeyData=x,exports.isPublicKeyInitData=function(t,e){return m(t)||L(t)||t instanceof Buffer||t instanceof Uint8Array||Array.isArray(t)&&t.every((function(t){return L(t)}))||x(t)},exports.isRawAuthoritySignInfo=D,exports.isSequenceNumber=L,exports.isSignaturePubkeyPair=function(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&t.signature instanceof c&&t.pubKey instanceof f},exports.isSigner=function(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&"function"==typeof t.getAddress&&"function"==typeof t.signData},exports.isSplitCoinResponse=tt,exports.isSplitCoinTransaction=function(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.coinObjectId)&&Array.isArray(t.splitAmounts)&&t.splitAmounts.every((function(t){return L(t)}))&&(void 0===t.gasPayment||m(t.gasPayment))&&L(t.gasBudget)},exports.isSuiAddress=function(t,e){return"string"==typeof t},exports.isSuiData=O,exports.isSuiJsonValue=Q,exports.isSuiMoveObject=C,exports.isSuiMovePackage=k,exports.isSuiObject=B,exports.isSuiObjectInfo=E,exports.isSuiObjectRef=T,exports.isSuiTransactionKind=q,exports.isTransactionBytes=X,exports.isTransactionData=U,exports.isTransactionDigest=m,exports.isTransactionEffects=F,exports.isTransactionEffectsResponse=Z,exports.isTransactionKindName=function(t,e){return"TransferCoin"===t||"Publish"===t||"Call"===t},exports.isTransactionResponse=et,exports.isTransferCoin=N,exports.isTransferCoinTransaction=function(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&m(t.objectId)&&(void 0===t.gasPayment||m(t.gasPayment))&&L(t.gasBudget)&&m(t.recipient)},exports.isTxnDataSerializer=function(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&"function"==typeof t.newTransferCoin&&"function"==typeof t.newMoveCall&&"function"==typeof t.newMergeCoin&&"function"==typeof t.newSplitCoin},exports.isValidSuiAddress=yt,exports.isValidSuiObjectId=function(t){return yt(t)},exports.isValidTransactionDigest=function(t){return 32===new c(t).getLength()&&ht.test(t)}; | ||
//# sourceMappingURL=sui.js.cjs.production.min.js.map |
@@ -1,2 +0,2 @@ | ||
import { GetObjectInfoResponse } from './objects'; | ||
import { GetObjectDataResponse } from './objects'; | ||
import BN from 'bn.js'; | ||
@@ -8,5 +8,5 @@ /** | ||
export declare class Coin { | ||
static isCoin(data: GetObjectInfoResponse): boolean; | ||
static getBalance(data: GetObjectInfoResponse): BN | undefined; | ||
static isCoin(data: GetObjectDataResponse): boolean; | ||
static getBalance(data: GetObjectDataResponse): BN | undefined; | ||
static getZero(): BN; | ||
} |
@@ -11,2 +11,7 @@ import { ObjectOwner } from './common'; | ||
}; | ||
export declare type SuiObjectInfo = SuiObjectRef & { | ||
type: string; | ||
owner: ObjectOwner; | ||
previousTransaction: TransactionDigest; | ||
}; | ||
export declare type ObjectContentFields = Record<string, any>; | ||
@@ -44,6 +49,4 @@ export declare type MovePackageContent = Record<string, string>; | ||
export declare type ObjectType = 'moveObject' | 'package'; | ||
export declare type GetOwnedObjectRefsResponse = { | ||
objects: SuiObjectRef[]; | ||
}; | ||
export declare type GetObjectInfoResponse = { | ||
export declare type GetOwnedObjectsResponse = SuiObjectInfo[]; | ||
export declare type GetObjectDataResponse = { | ||
status: ObjectStatus; | ||
@@ -55,14 +58,14 @@ details: SuiObject | ObjectId | SuiObjectRef; | ||
export declare type SequenceNumber = number; | ||
export declare function getObjectExistsResponse(resp: GetObjectInfoResponse): SuiObject | undefined; | ||
export declare function getObjectDeletedResponse(resp: GetObjectInfoResponse): SuiObjectRef | undefined; | ||
export declare function getObjectNotExistsResponse(resp: GetObjectInfoResponse): ObjectId | undefined; | ||
export declare function getObjectReference(resp: GetObjectInfoResponse): SuiObjectRef | undefined; | ||
export declare function getObjectId(data: GetObjectInfoResponse | SuiObjectRef): ObjectId; | ||
export declare function getObjectVersion(data: GetObjectInfoResponse | SuiObjectRef): number | undefined; | ||
export declare function getObjectType(resp: GetObjectInfoResponse): ObjectType | undefined; | ||
export declare function getObjectPreviousTransactionDigest(resp: GetObjectInfoResponse): TransactionDigest | undefined; | ||
export declare function getObjectOwner(resp: GetObjectInfoResponse): ObjectOwner | undefined; | ||
export declare function getMoveObjectType(resp: GetObjectInfoResponse): string | undefined; | ||
export declare function getObjectFields(resp: GetObjectInfoResponse): ObjectContentFields | undefined; | ||
export declare function getMoveObject(resp: GetObjectInfoResponse): SuiMoveObject | undefined; | ||
export declare function getMovePackageContent(data: GetObjectInfoResponse | SuiMovePackage): MovePackageContent | undefined; | ||
export declare function getObjectExistsResponse(resp: GetObjectDataResponse): SuiObject | undefined; | ||
export declare function getObjectDeletedResponse(resp: GetObjectDataResponse): SuiObjectRef | undefined; | ||
export declare function getObjectNotExistsResponse(resp: GetObjectDataResponse): ObjectId | undefined; | ||
export declare function getObjectReference(resp: GetObjectDataResponse): SuiObjectRef | undefined; | ||
export declare function getObjectId(data: GetObjectDataResponse | SuiObjectRef): ObjectId; | ||
export declare function getObjectVersion(data: GetObjectDataResponse | SuiObjectRef): number | undefined; | ||
export declare function getObjectType(resp: GetObjectDataResponse): ObjectType | undefined; | ||
export declare function getObjectPreviousTransactionDigest(resp: GetObjectDataResponse): TransactionDigest | undefined; | ||
export declare function getObjectOwner(resp: GetObjectDataResponse): ObjectOwner | undefined; | ||
export declare function getMoveObjectType(resp: GetObjectDataResponse): string | undefined; | ||
export declare function getObjectFields(resp: GetObjectDataResponse): ObjectContentFields | undefined; | ||
export declare function getMoveObject(data: GetObjectDataResponse | SuiObject): SuiMoveObject | undefined; | ||
export declare function getMovePackageContent(data: GetObjectDataResponse | SuiMovePackage): MovePackageContent | undefined; |
@@ -104,2 +104,7 @@ import { ObjectOwner, SuiAddress, TransactionDigest } from './common'; | ||
}; | ||
export declare type MergeCoinResponse = { | ||
certificate: CertifiedTransaction; | ||
updatedCoin: SuiObject; | ||
updatedGas: SuiObject; | ||
}; | ||
export declare type SplitCoinResponse = { | ||
@@ -115,2 +120,4 @@ certificate: CertifiedTransaction; | ||
SplitCoinResponse: SplitCoinResponse; | ||
} | { | ||
MergeCoinResponse: MergeCoinResponse; | ||
}; | ||
@@ -134,1 +141,22 @@ export declare function getTransactionDigest(tx: CertifiedTransaction): TransactionDigest; | ||
export declare function getTotalGasUsed(data: TransactionEffectsResponse): number; | ||
export declare function getTransactionEffectsResponse(data: TransactionResponse): TransactionEffectsResponse | undefined; | ||
export declare function getSplitCoinResponse(data: TransactionResponse): SplitCoinResponse | undefined; | ||
export declare function getMergeCoinResponse(data: TransactionResponse): MergeCoinResponse | undefined; | ||
/** | ||
* Get the updated coin after a merge. | ||
* @param data the response for executing a merge coin transaction | ||
* @returns the updated state of the primary coin after the merge | ||
*/ | ||
export declare function getCoinAfterMerge(data: TransactionResponse): SuiObject | undefined; | ||
/** | ||
* Get the updated coin after a split. | ||
* @param data the response for executing a Split coin transaction | ||
* @returns the updated state of the original coin object used for the split | ||
*/ | ||
export declare function getCoinAfterSplit(data: TransactionResponse): SuiObject | undefined; | ||
/** | ||
* Get the newly created coin after a split. | ||
* @param data the response for executing a Split coin transaction | ||
* @returns the updated state of the original coin object used for the split | ||
*/ | ||
export declare function getNewlyCreatedCoinsAfterSplit(data: TransactionResponse): SuiObject[] | undefined; |
{ | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"license": "Apache-2.0", | ||
@@ -16,2 +16,3 @@ "main": "dist/index.js", | ||
"build": "./type_guards.sh; tsdx build", | ||
"doc": "typedoc", | ||
"test": "tsdx test", | ||
@@ -64,2 +65,3 @@ "lint": "tsdx lint", | ||
"tslib": "^2.3.1", | ||
"typedoc": "^0.22.17", | ||
"typescript": "^4.6.3" | ||
@@ -66,0 +68,0 @@ }, |
122
README.md
@@ -5,6 +5,8 @@ # Sui TypeScript SDK | ||
Note that the SDK is still in development mode and some API functions are subject to change. | ||
WARNING: Note that we are still iterating on the RPC and SDK API before TestNet, therefore please expect frequent breaking changes in the short-term. We expect the API to stabilize after the upcoming TestNet launch. | ||
## Installation | ||
## Working with DevNet | ||
The SDK will be published to [npm registry](https://www.npmjs.com/package/@mysten/sui.js) with the same bi-weekly release cycle as the DevNet validators and [RPC Server](https://github.com/MystenLabs/sui/blob/main/doc/src/build/json-rpc.md). To use the SDK in your project, you can do: | ||
```bash | ||
@@ -14,10 +16,38 @@ $ yarn add @mysten/sui.js | ||
## Local Development Environment Setup | ||
## Working with local network | ||
Follow the [JSON RPC doc](https://github.com/MystenLabs/sui/blob/main/doc/src/build/json-rpc.md) to start a local network and local RPC server | ||
Note that the [published SDK](https://www.npmjs.com/package/@mysten/sui.js) might go out of sync with the RPC server on the `main` branch until the next bi-weekly release, therefore it's recommended to build the SDK locally if you want to test against the local network. | ||
Run the following command in the `sui/sdk/typescript` directory to build the SDK and [create a symlink](https://docs.npmjs.com/cli/v8/commands/npm-link) in the global folder. | ||
```bash | ||
$ cd <path to sui repo>/sdk/typescript | ||
$ yarn && yarn build | ||
$ npm link | ||
``` | ||
Next, go to your project directory and create a symbolic link from globally-installed `@mysten/sui.js` to the `node_modules/` of your project directory. | ||
```bash | ||
cd <your project directory> | ||
npm link @mysten/sui.js | ||
``` | ||
Refer to the [JSON RPC doc](https://github.com/MystenLabs/sui/blob/main/doc/src/build/json-rpc.md) for instructions about how to start a local network and local RPC server | ||
## Type Doc | ||
You can view the generated [Type Doc](https://typedoc.org/) for the [current release of the SDK](https://www.npmjs.com/package/@mysten/sui.js) at http://typescript-sdk-docs.s3-website-us-east-1.amazonaws.com/. | ||
For the latest docs for the `main` branch, run `yarn doc` and open the [doc/index.html](doc/index.html) in your browser. | ||
## Usage | ||
The `JsonRpcProvider` class provides a connection to the JSON-RPC Server and should be used for all read-only operations. For example: | ||
The `JsonRpcProvider` class provides a connection to the JSON-RPC Server and should be used for all read-only operations. The default URLs to connect with the RPC server are: | ||
- local: http://127.0.0.1:5001 | ||
- DevNet: https://gateway.devnet.sui.io:443 | ||
Examples: | ||
Fetch objects owned by the address `0xbff6ccc8707aa517b4f1b95750a2a8c666012df3` | ||
@@ -27,3 +57,3 @@ | ||
import { JsonRpcProvider } from '@mysten/sui.js'; | ||
const provider = new JsonRpcProvider('https://gateway.devnet.sui.io:9000/'); | ||
const provider = new JsonRpcProvider('https://gateway.devnet.sui.io:443'); | ||
const objects = await provider.getOwnedObjectRefs( | ||
@@ -38,3 +68,3 @@ '0xbff6ccc8707aa517b4f1b95750a2a8c666012df3' | ||
import { JsonRpcProvider } from '@mysten/sui.js'; | ||
const provider = new JsonRpcProvider('https://gateway.devnet.sui.io:9000/'); | ||
const provider = new JsonRpcProvider('https://gateway.devnet.sui.io:443'); | ||
const txn = await provider.getTransaction( | ||
@@ -47,3 +77,3 @@ '6mn5W1CczLwitHCO9OIUbqirNrQ0cuKdyxaNe16SAME=' | ||
To transfer a Coin<SUI>: | ||
To transfer a `0x2::Coin::Coin<SUI>`: | ||
@@ -56,14 +86,74 @@ ```typescript | ||
keypair, | ||
new JsonRpcProvider('https://gateway.devnet.sui.io:9000/') | ||
new JsonRpcProvider('https://gateway.devnet.sui.io:443') | ||
); | ||
const txn = await signer.transferCoin({ | ||
signer: keypair.getPublicKey().toSuiAddress(), | ||
const transferTxn = await signer.transferCoin({ | ||
objectId: '0x5015b016ab570df14c87649eda918e09e5cc61e0', | ||
gasPayment: '0x0a8c2a0fd59bf41678b2e22c3dd2b84425fb3673', | ||
gasBudget: 1000, | ||
recipient: '0xd84058cb73bdeabe123b56632713dcd65e1a6c92', | ||
}); | ||
console.log('transferTxn', transferTxn); | ||
``` | ||
To split a `0x2::Coin::Coin<SUI>` into multiple coins | ||
```typescript | ||
import { Ed25519Keypair, JsonRpcProvider, RawSigner } from '@mysten/sui.js'; | ||
// Generate a new Keypair | ||
const keypair = new Ed25519Keypair(); | ||
const signer = new RawSigner( | ||
keypair, | ||
new JsonRpcProvider('https://gateway.devnet.sui.io:443') | ||
); | ||
const splitTxn = await signer..splitCoin({ | ||
coinObjectId: '0x5015b016ab570df14c87649eda918e09e5cc61e0', | ||
// Say if the original coin has a balance of 100, | ||
// This function will create three new coins of amount 10, 20, 30, | ||
// respectively, the original coin will retain the remaining balance(40). | ||
splitAmounts: [10, 20, 30], | ||
gasBudget: 1000, | ||
}); | ||
console.log('SplitCoin txn', splitTxn); | ||
``` | ||
To merge two coins: | ||
```typescript | ||
import { Ed25519Keypair, JsonRpcProvider, RawSigner } from '@mysten/sui.js'; | ||
// Generate a new Keypair | ||
const keypair = new Ed25519Keypair(); | ||
const signer = new RawSigner( | ||
keypair, | ||
new JsonRpcProvider('https://gateway.devnet.sui.io:443') | ||
); | ||
const mergeTxn = await signer.mergeCoin({ | ||
primaryCoin: '0x5015b016ab570df14c87649eda918e09e5cc61e0', | ||
coinToMerge: '0xcc460051569bfb888dedaf5182e76f473ee351af', | ||
gasBudget: 1000, | ||
}); | ||
console.log('MergeCoin txn', mergeTxn); | ||
``` | ||
To make a move call: | ||
```typescript | ||
import { Ed25519Keypair, JsonRpcProvider, RawSigner } from '@mysten/sui.js'; | ||
// Generate a new Keypair | ||
const keypair = new Ed25519Keypair(); | ||
const signer = new RawSigner( | ||
keypair, | ||
new JsonRpcProvider('https://gateway.devnet.sui.io:443') | ||
); | ||
const moveCallTxn = await signer.executeMoveCall({ | ||
packageObjectId: '0x2', | ||
module: 'DevNetNFT', | ||
function: 'mint', | ||
typeArguments: [], | ||
arguments: [ | ||
'Example NFT', | ||
'An NFT created by the wallet Command Line Tool', | ||
'ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty', | ||
], | ||
gasBudget: 10000, | ||
recipient: '0xBFF6CCC8707AA517B4F1B95750A2A8C666012DF3', | ||
}); | ||
console.log('moveCallTxn', moveCallTxn); | ||
``` | ||
To sign a raw message: | ||
TODO |
@@ -8,4 +8,6 @@ // Copyright (c) 2022, Mysten Labs, Inc. | ||
*/ | ||
import { Ed25519KeypairData, Keypair, PublicKeyInitData, PublicKeyData, TransferCoinTransaction, TxnDataSerializer, TransactionDigest, SuiAddress, ObjectOwner, SuiObjectRef, ObjectContentFields, MovePackageContent, SuiData, SuiMoveObject, SuiMovePackage, SuiObject, ObjectStatus, ObjectType, GetOwnedObjectRefsResponse, GetObjectInfoResponse, ObjectDigest, ObjectId, SequenceNumber, TransferCoin, RawAuthoritySignInfo, TransactionKindName, SuiTransactionKind, TransactionData, EpochId, AuthorityQuorumSignInfo, CertifiedTransaction, GasCostSummary, ExecutionStatusType, ExecutionStatus, OwnedObjectRef, TransactionEffects, TransactionEffectsResponse, GatewayTxSeqNumber, GetTxnDigestsResponse, Event, MoveCall, SuiJsonValue, EmptySignInfo, AuthorityName, AuthoritySignature, TransactionBytes, SplitCoinResponse, TransactionResponse } from "./index"; | ||
import { Ed25519KeypairData, Keypair, PublicKeyInitData, PublicKeyData, TransferCoinTransaction, MergeCoinTransaction, SplitCoinTransaction, MoveCallTransaction, TxnDataSerializer, SignaturePubkeyPair, Signer, TransactionDigest, SuiAddress, ObjectOwner, SuiObjectRef, SuiObjectInfo, ObjectContentFields, MovePackageContent, SuiData, SuiMoveObject, SuiMovePackage, SuiObject, ObjectStatus, ObjectType, GetOwnedObjectsResponse, GetObjectDataResponse, ObjectDigest, ObjectId, SequenceNumber, TransferCoin, RawAuthoritySignInfo, TransactionKindName, SuiTransactionKind, TransactionData, EpochId, AuthorityQuorumSignInfo, CertifiedTransaction, GasCostSummary, ExecutionStatusType, ExecutionStatus, OwnedObjectRef, TransactionEffects, TransactionEffectsResponse, GatewayTxSeqNumber, GetTxnDigestsResponse, Event, MoveCall, SuiJsonValue, EmptySignInfo, AuthorityName, AuthoritySignature, TransactionBytes, MergeCoinResponse, SplitCoinResponse, TransactionResponse } from "./index"; | ||
import { BN } from "bn.js"; | ||
import { Base64DataBuffer } from "./serialization/base64"; | ||
import { PublicKey } from "./cryptography/publickey"; | ||
@@ -60,5 +62,5 @@ export function isEd25519KeypairData(obj: any, _argumentName?: string): obj is Ed25519KeypairData { | ||
typeof obj === "function") && | ||
isTransactionDigest(obj.signer) as boolean && | ||
isTransactionDigest(obj.objectId) as boolean && | ||
isTransactionDigest(obj.gasPayment) as boolean && | ||
(typeof obj.gasPayment === "undefined" || | ||
isTransactionDigest(obj.gasPayment) as boolean) && | ||
isSequenceNumber(obj.gasBudget) as boolean && | ||
@@ -69,2 +71,53 @@ isTransactionDigest(obj.recipient) as boolean | ||
export function isMergeCoinTransaction(obj: any, _argumentName?: string): obj is MergeCoinTransaction { | ||
return ( | ||
(obj !== null && | ||
typeof obj === "object" || | ||
typeof obj === "function") && | ||
isTransactionDigest(obj.primaryCoin) as boolean && | ||
isTransactionDigest(obj.coinToMerge) as boolean && | ||
(typeof obj.gasPayment === "undefined" || | ||
isTransactionDigest(obj.gasPayment) as boolean) && | ||
isSequenceNumber(obj.gasBudget) as boolean | ||
) | ||
} | ||
export function isSplitCoinTransaction(obj: any, _argumentName?: string): obj is SplitCoinTransaction { | ||
return ( | ||
(obj !== null && | ||
typeof obj === "object" || | ||
typeof obj === "function") && | ||
isTransactionDigest(obj.coinObjectId) as boolean && | ||
Array.isArray(obj.splitAmounts) && | ||
obj.splitAmounts.every((e: any) => | ||
isSequenceNumber(e) as boolean | ||
) && | ||
(typeof obj.gasPayment === "undefined" || | ||
isTransactionDigest(obj.gasPayment) as boolean) && | ||
isSequenceNumber(obj.gasBudget) as boolean | ||
) | ||
} | ||
export function isMoveCallTransaction(obj: any, _argumentName?: string): obj is MoveCallTransaction { | ||
return ( | ||
(obj !== null && | ||
typeof obj === "object" || | ||
typeof obj === "function") && | ||
isTransactionDigest(obj.packageObjectId) as boolean && | ||
isTransactionDigest(obj.module) as boolean && | ||
isTransactionDigest(obj.function) as boolean && | ||
Array.isArray(obj.typeArguments) && | ||
obj.typeArguments.every((e: any) => | ||
isTransactionDigest(e) as boolean | ||
) && | ||
Array.isArray(obj.arguments) && | ||
obj.arguments.every((e: any) => | ||
isSuiJsonValue(e) as boolean | ||
) && | ||
(typeof obj.gasPayment === "undefined" || | ||
isTransactionDigest(obj.gasPayment) as boolean) && | ||
isSequenceNumber(obj.gasBudget) as boolean | ||
) | ||
} | ||
export function isTxnDataSerializer(obj: any, _argumentName?: string): obj is TxnDataSerializer { | ||
@@ -75,6 +128,29 @@ return ( | ||
typeof obj === "function") && | ||
typeof obj.newTransferCoin === "function" | ||
typeof obj.newTransferCoin === "function" && | ||
typeof obj.newMoveCall === "function" && | ||
typeof obj.newMergeCoin === "function" && | ||
typeof obj.newSplitCoin === "function" | ||
) | ||
} | ||
export function isSignaturePubkeyPair(obj: any, _argumentName?: string): obj is SignaturePubkeyPair { | ||
return ( | ||
(obj !== null && | ||
typeof obj === "object" || | ||
typeof obj === "function") && | ||
obj.signature instanceof Base64DataBuffer && | ||
obj.pubKey instanceof PublicKey | ||
) | ||
} | ||
export function isSigner(obj: any, _argumentName?: string): obj is Signer { | ||
return ( | ||
(obj !== null && | ||
typeof obj === "object" || | ||
typeof obj === "function") && | ||
typeof obj.getAddress === "function" && | ||
typeof obj.signData === "function" | ||
) | ||
} | ||
export function isTransactionDigest(obj: any, _argumentName?: string): obj is TransactionDigest { | ||
@@ -118,2 +194,14 @@ return ( | ||
export function isSuiObjectInfo(obj: any, _argumentName?: string): obj is SuiObjectInfo { | ||
return ( | ||
isSuiObjectRef(obj) as boolean && | ||
(obj !== null && | ||
typeof obj === "object" || | ||
typeof obj === "function") && | ||
isTransactionDigest(obj.type) as boolean && | ||
isObjectOwner(obj.owner) as boolean && | ||
isTransactionDigest(obj.previousTransaction) as boolean | ||
) | ||
} | ||
export function isObjectContentFields(obj: any, _argumentName?: string): obj is ObjectContentFields { | ||
@@ -202,10 +290,7 @@ return ( | ||
export function isGetOwnedObjectRefsResponse(obj: any, _argumentName?: string): obj is GetOwnedObjectRefsResponse { | ||
export function isGetOwnedObjectsResponse(obj: any, _argumentName?: string): obj is GetOwnedObjectsResponse { | ||
return ( | ||
(obj !== null && | ||
typeof obj === "object" || | ||
typeof obj === "function") && | ||
Array.isArray(obj.objects) && | ||
obj.objects.every((e: any) => | ||
isSuiObjectRef(e) as boolean | ||
Array.isArray(obj) && | ||
obj.every((e: any) => | ||
isSuiObjectInfo(e) as boolean | ||
) | ||
@@ -215,3 +300,3 @@ ) | ||
export function isGetObjectInfoResponse(obj: any, _argumentName?: string): obj is GetObjectInfoResponse { | ||
export function isGetObjectDataResponse(obj: any, _argumentName?: string): obj is GetObjectDataResponse { | ||
return ( | ||
@@ -527,2 +612,13 @@ (obj !== null && | ||
export function isMergeCoinResponse(obj: any, _argumentName?: string): obj is MergeCoinResponse { | ||
return ( | ||
(obj !== null && | ||
typeof obj === "object" || | ||
typeof obj === "function") && | ||
isCertifiedTransaction(obj.certificate) as boolean && | ||
isSuiObject(obj.updatedCoin) as boolean && | ||
isSuiObject(obj.updatedGas) as boolean | ||
) | ||
} | ||
export function isSplitCoinResponse(obj: any, _argumentName?: string): obj is SplitCoinResponse { | ||
@@ -552,4 +648,8 @@ return ( | ||
typeof obj === "function") && | ||
isSplitCoinResponse(obj.SplitCoinResponse) as boolean) | ||
isSplitCoinResponse(obj.SplitCoinResponse) as boolean || | ||
(obj !== null && | ||
typeof obj === "object" || | ||
typeof obj === "function") && | ||
isMergeCoinResponse(obj.MergeCoinResponse) as boolean) | ||
) | ||
} |
@@ -17,2 +17,3 @@ // Copyright (c) 2022, Mysten Labs, Inc. | ||
export * from './signers/signer'; | ||
export * from './signers/raw-signer'; | ||
@@ -19,0 +20,0 @@ export * from './signers/signer-with-provider'; |
@@ -7,4 +7,4 @@ // Copyright (c) 2022, Mysten Labs, Inc. | ||
import { | ||
isGetObjectInfoResponse, | ||
isGetOwnedObjectRefsResponse, | ||
isGetObjectDataResponse, | ||
isGetOwnedObjectsResponse, | ||
isGetTxnDigestsResponse, | ||
@@ -17,4 +17,4 @@ isTransactionEffectsResponse, | ||
GetTxnDigestsResponse, | ||
GetObjectInfoResponse, | ||
SuiObjectRef, | ||
GetObjectDataResponse, | ||
SuiObjectInfo, | ||
TransactionDigest, | ||
@@ -41,13 +41,12 @@ TransactionEffectsResponse, | ||
// Objects | ||
async getOwnedObjectRefs(address: string): Promise<SuiObjectRef[]> { | ||
async getObjectsOwnedByAddress(address: string): Promise<SuiObjectInfo[]> { | ||
try { | ||
const resp = await this.client.requestWithType( | ||
'sui_getOwnedObjects', | ||
return await this.client.requestWithType( | ||
'sui_getObjectsOwnedByAddress', | ||
[address], | ||
isGetOwnedObjectRefsResponse | ||
isGetOwnedObjectsResponse | ||
); | ||
return resp.objects; | ||
} catch (err) { | ||
throw new Error( | ||
`Error fetching owned object refs: ${err} for address ${address}` | ||
`Error fetching owned object: ${err} for address ${address}` | ||
); | ||
@@ -57,10 +56,24 @@ } | ||
async getObjectInfo(objectId: string): Promise<GetObjectInfoResponse> { | ||
async getObjectsOwnedByObject(objectId: string): Promise<SuiObjectInfo[]> { | ||
try { | ||
return await this.client.requestWithType( | ||
'sui_getObjectInfo', | ||
'sui_getObjectsOwnedByObject', | ||
[objectId], | ||
isGetObjectInfoResponse | ||
isGetOwnedObjectsResponse | ||
); | ||
} catch (err) { | ||
throw new Error( | ||
`Error fetching owned object: ${err} for objectId ${objectId}` | ||
); | ||
} | ||
} | ||
async getObject(objectId: string): Promise<GetObjectDataResponse> { | ||
try { | ||
return await this.client.requestWithType( | ||
'sui_getObject', | ||
[objectId], | ||
isGetObjectDataResponse | ||
); | ||
} catch (err) { | ||
throw new Error(`Error fetching object info: ${err} for id ${objectId}`); | ||
@@ -70,7 +83,5 @@ } | ||
async getObjectInfoBatch( | ||
objectIds: string[] | ||
): Promise<GetObjectInfoResponse[]> { | ||
async getObjectBatch(objectIds: string[]): Promise<GetObjectDataResponse[]> { | ||
const requests = objectIds.map(id => ({ | ||
method: 'sui_getObjectInfo', | ||
method: 'sui_getObject', | ||
args: [id], | ||
@@ -81,3 +92,3 @@ })); | ||
requests, | ||
isGetObjectInfoResponse | ||
isGetObjectDataResponse | ||
); | ||
@@ -84,0 +95,0 @@ } catch (err) { |
@@ -5,4 +5,4 @@ // Copyright (c) 2022, Mysten Labs, Inc. | ||
import { | ||
GetObjectInfoResponse, | ||
SuiObjectRef, | ||
GetObjectDataResponse, | ||
SuiObjectInfo, | ||
GatewayTxSeqNumber, | ||
@@ -20,8 +20,10 @@ GetTxnDigestsResponse, | ||
*/ | ||
abstract getOwnedObjectRefs(address: string): Promise<SuiObjectRef[]>; | ||
abstract getObjectsOwnedByAddress( | ||
addressOrObjectId: string | ||
): Promise<SuiObjectInfo[]>; | ||
/** | ||
* Get information about an object | ||
* Get details about an object | ||
*/ | ||
abstract getObjectInfo(objectId: string): Promise<GetObjectInfoResponse>; | ||
abstract getObject(objectId: string): Promise<GetObjectDataResponse>; | ||
@@ -28,0 +30,0 @@ // Transactions |
@@ -9,4 +9,4 @@ // Copyright (c) 2022, Mysten Labs, Inc. | ||
GatewayTxSeqNumber, | ||
SuiObjectRef, | ||
GetObjectInfoResponse, | ||
SuiObjectInfo, | ||
GetObjectDataResponse, | ||
TransactionResponse, | ||
@@ -18,8 +18,8 @@ } from '../types'; | ||
// Objects | ||
async getOwnedObjectRefs(_address: string): Promise<SuiObjectRef[]> { | ||
throw this.newError('getOwnedObjectRefs'); | ||
async getObjectsOwnedByAddress(_address: string): Promise<SuiObjectInfo[]> { | ||
throw this.newError('getOwnedObjects'); | ||
} | ||
async getObjectInfo(_objectId: string): Promise<GetObjectInfoResponse> { | ||
throw this.newError('getObjectInfo'); | ||
async getObject(_objectId: string): Promise<GetObjectDataResponse> { | ||
throw this.newError('getObject'); | ||
} | ||
@@ -26,0 +26,0 @@ |
@@ -51,3 +51,7 @@ // Copyright (c) 2022, Mysten Labs, Inc. | ||
if (key === "balance") return value.toString(); | ||
if (value.isLosslessNumber) return value.valueOf(); | ||
try { | ||
if (value.isLosslessNumber) return value.valueOf(); | ||
} catch { | ||
return value.toString(); | ||
} | ||
return value; | ||
@@ -54,0 +58,0 @@ } |
@@ -7,2 +7,3 @@ // Copyright (c) 2022, Mysten Labs, Inc. | ||
import { Base64DataBuffer } from '../serialization/base64'; | ||
import { SuiAddress } from '../types'; | ||
import { SignaturePubkeyPair } from './signer'; | ||
@@ -24,4 +25,4 @@ import { SignerWithProvider } from './signer-with-provider'; | ||
async getAddress(): Promise<string> { | ||
throw this.keypair.getPublicKey().toSuiAddress(); | ||
async getAddress(): Promise<SuiAddress> { | ||
return this.keypair.getPublicKey().toSuiAddress(); | ||
} | ||
@@ -28,0 +29,0 @@ |
@@ -8,6 +8,9 @@ // Copyright (c) 2022, Mysten Labs, Inc. | ||
import { Base64DataBuffer } from '../serialization/base64'; | ||
import { TransactionResponse } from '../types'; | ||
import { SuiAddress, TransactionResponse } from '../types'; | ||
import { SignaturePubkeyPair, Signer } from './signer'; | ||
import { RpcTxnDataSerializer } from './txn-data-serializers/rpc-txn-data-serializer'; | ||
import { | ||
MoveCallTransaction, | ||
MergeCoinTransaction, | ||
SplitCoinTransaction, | ||
TransferCoinTransaction, | ||
@@ -27,3 +30,3 @@ TxnDataSerializer, | ||
// Returns the checksum address | ||
abstract getAddress(): Promise<string>; | ||
abstract getAddress(): Promise<SuiAddress>; | ||
@@ -73,5 +76,51 @@ /** | ||
): Promise<TransactionResponse> { | ||
const txBytes = await this.serializer.newTransferCoin(transaction); | ||
const signerAddress = await this.getAddress(); | ||
const txBytes = await this.serializer.newTransferCoin( | ||
signerAddress, | ||
transaction | ||
); | ||
return await this.signAndExecuteTransaction(txBytes); | ||
} | ||
/** | ||
* Serialize and Sign a `MergeCoin` transaction and submit to the Gateway for execution | ||
*/ | ||
async mergeCoin( | ||
transaction: MergeCoinTransaction | ||
): Promise<TransactionResponse> { | ||
const signerAddress = await this.getAddress(); | ||
const txBytes = await this.serializer.newMergeCoin( | ||
signerAddress, | ||
transaction | ||
); | ||
return await this.signAndExecuteTransaction(txBytes); | ||
} | ||
/** | ||
* Serialize and Sign a `SplitCoin` transaction and submit to the Gateway for execution | ||
*/ | ||
async splitCoin( | ||
transaction: SplitCoinTransaction | ||
): Promise<TransactionResponse> { | ||
const signerAddress = await this.getAddress(); | ||
const txBytes = await this.serializer.newSplitCoin( | ||
signerAddress, | ||
transaction | ||
); | ||
return await this.signAndExecuteTransaction(txBytes); | ||
} | ||
/** | ||
* Serialize and Sign a `MoveCall` transaction and submit to the Gateway for execution | ||
*/ | ||
async executeMoveCall( | ||
transaction: MoveCallTransaction | ||
): Promise<TransactionResponse> { | ||
const signerAddress = await this.getAddress(); | ||
const txBytes = await this.serializer.newMoveCall( | ||
signerAddress, | ||
transaction | ||
); | ||
return await this.signAndExecuteTransaction(txBytes); | ||
} | ||
} |
@@ -7,3 +7,7 @@ // Copyright (c) 2022, Mysten Labs, Inc. | ||
import { Base64DataBuffer } from '../../serialization/base64'; | ||
import { SuiAddress } from '../../types'; | ||
import { | ||
MoveCallTransaction, | ||
MergeCoinTransaction, | ||
SplitCoinTransaction, | ||
TransferCoinTransaction, | ||
@@ -32,7 +36,10 @@ TxnDataSerializer, | ||
async newTransferCoin(t: TransferCoinTransaction): Promise<Base64DataBuffer> { | ||
async newTransferCoin( | ||
signerAddress: SuiAddress, | ||
t: TransferCoinTransaction | ||
): Promise<Base64DataBuffer> { | ||
try { | ||
const resp = await this.client.requestWithType( | ||
'sui_transferCoin', | ||
[t.signer, t.objectId, t.gasPayment, t.gasBudget, t.recipient], | ||
[signerAddress, t.objectId, t.gasPayment, t.gasBudget, t.recipient], | ||
isTransactionBytes | ||
@@ -42,7 +49,74 @@ ); | ||
} catch (err) { | ||
throw new Error(`Error transferring coin: ${err}`); | ||
throw new Error(`Error transferring coin: ${err} with args ${t}`); | ||
} | ||
} | ||
// TODO: add more interface methods | ||
async newMoveCall( | ||
signerAddress: SuiAddress, | ||
t: MoveCallTransaction | ||
): Promise<Base64DataBuffer> { | ||
try { | ||
const resp = await this.client.requestWithType( | ||
'sui_moveCall', | ||
[ | ||
signerAddress, | ||
t.packageObjectId, | ||
t.module, | ||
t.function, | ||
t.typeArguments, | ||
t.arguments, | ||
t.gasPayment, | ||
t.gasBudget, | ||
], | ||
isTransactionBytes | ||
); | ||
return new Base64DataBuffer(resp.txBytes); | ||
} catch (err) { | ||
throw new Error(`Error executing a move call: ${err} with args ${t}`); | ||
} | ||
} | ||
async newMergeCoin( | ||
signerAddress: SuiAddress, | ||
t: MergeCoinTransaction | ||
): Promise<Base64DataBuffer> { | ||
try { | ||
const resp = await this.client.requestWithType( | ||
'sui_mergeCoins', | ||
[ | ||
signerAddress, | ||
t.primaryCoin, | ||
t.coinToMerge, | ||
t.gasPayment, | ||
t.gasBudget, | ||
], | ||
isTransactionBytes | ||
); | ||
return new Base64DataBuffer(resp.txBytes); | ||
} catch (err) { | ||
throw new Error(`Error merging coin: ${err}`); | ||
} | ||
} | ||
async newSplitCoin( | ||
signerAddress: SuiAddress, | ||
t: SplitCoinTransaction | ||
): Promise<Base64DataBuffer> { | ||
try { | ||
const resp = await this.client.requestWithType( | ||
'sui_splitCoin', | ||
[ | ||
signerAddress, | ||
t.coinObjectId, | ||
t.splitAmounts, | ||
t.gasPayment, | ||
t.gasBudget, | ||
], | ||
isTransactionBytes | ||
); | ||
return new Base64DataBuffer(resp.txBytes); | ||
} catch (err) { | ||
throw new Error(`Error splitting coin: ${err}`); | ||
} | ||
} | ||
} |
@@ -5,3 +5,3 @@ // Copyright (c) 2022, Mysten Labs, Inc. | ||
import { Base64DataBuffer } from '../../serialization/base64'; | ||
import { ObjectId, SuiAddress } from '../../types'; | ||
import { ObjectId, SuiAddress, SuiJsonValue } from '../../types'; | ||
@@ -11,5 +11,4 @@ /////////////////////////////// | ||
export interface TransferCoinTransaction { | ||
signer: SuiAddress; | ||
objectId: ObjectId; | ||
gasPayment: ObjectId; | ||
gasPayment?: ObjectId; | ||
gasBudget: number; | ||
@@ -19,2 +18,26 @@ recipient: SuiAddress; | ||
export interface MergeCoinTransaction { | ||
primaryCoin: ObjectId; | ||
coinToMerge: ObjectId; | ||
gasPayment?: ObjectId; | ||
gasBudget: number; | ||
} | ||
export interface SplitCoinTransaction { | ||
coinObjectId: ObjectId; | ||
splitAmounts: number[]; | ||
gasPayment?: ObjectId; | ||
gasBudget: number; | ||
} | ||
export interface MoveCallTransaction { | ||
packageObjectId: ObjectId; | ||
module: string; | ||
function: string; | ||
typeArguments: string[]; | ||
arguments: SuiJsonValue[]; | ||
gasPayment?: ObjectId; | ||
gasBudget: number; | ||
} | ||
/////////////////////////////// | ||
@@ -26,5 +49,21 @@ // Exported Abstracts | ||
export interface TxnDataSerializer { | ||
newTransferCoin(txn: TransferCoinTransaction): Promise<Base64DataBuffer>; | ||
newTransferCoin( | ||
signerAddress: SuiAddress, | ||
txn: TransferCoinTransaction | ||
): Promise<Base64DataBuffer>; | ||
// TODO: add more interface methods | ||
newMoveCall( | ||
signerAddress: SuiAddress, | ||
txn: MoveCallTransaction | ||
): Promise<Base64DataBuffer>; | ||
newMergeCoin( | ||
signerAddress: SuiAddress, | ||
txn: MergeCoinTransaction | ||
): Promise<Base64DataBuffer>; | ||
newSplitCoin( | ||
signerAddress: SuiAddress, | ||
txn: SplitCoinTransaction | ||
): Promise<Base64DataBuffer>; | ||
} |
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { getObjectFields, GetObjectInfoResponse } from './objects'; | ||
import { getObjectFields, GetObjectDataResponse } from './objects'; | ||
@@ -15,7 +15,7 @@ import { getMoveObjectType } from './objects'; | ||
export class Coin { | ||
static isCoin(data: GetObjectInfoResponse): boolean { | ||
static isCoin(data: GetObjectDataResponse): boolean { | ||
return getMoveObjectType(data)?.startsWith('0x2::Coin::Coin') ?? false; | ||
} | ||
static getBalance(data: GetObjectInfoResponse): BN | undefined { | ||
static getBalance(data: GetObjectDataResponse): BN | undefined { | ||
if (!Coin.isCoin(data)) { | ||
@@ -29,4 +29,4 @@ return undefined; | ||
static getZero(): BN { | ||
return new BN.BN("0", 10); | ||
return new BN.BN('0', 10); | ||
} | ||
} |
@@ -16,2 +16,8 @@ // Copyright (c) 2022, Mysten Labs, Inc. | ||
export type SuiObjectInfo = SuiObjectRef & { | ||
type: string; | ||
owner: ObjectOwner; | ||
previousTransaction: TransactionDigest; | ||
}; | ||
export type ObjectContentFields = Record<string, any>; | ||
@@ -57,7 +63,5 @@ | ||
export type GetOwnedObjectRefsResponse = { | ||
objects: SuiObjectRef[]; | ||
}; | ||
export type GetOwnedObjectsResponse = SuiObjectInfo[]; | ||
export type GetObjectInfoResponse = { | ||
export type GetObjectDataResponse = { | ||
status: ObjectStatus; | ||
@@ -75,6 +79,6 @@ details: SuiObject | ObjectId | SuiObjectRef; | ||
/* -------------------------- GetObjectInfoResponse ------------------------- */ | ||
/* -------------------------- GetObjectDataResponse ------------------------- */ | ||
export function getObjectExistsResponse( | ||
resp: GetObjectInfoResponse | ||
resp: GetObjectDataResponse | ||
): SuiObject | undefined { | ||
@@ -85,3 +89,3 @@ return resp.status !== 'Exists' ? undefined : (resp.details as SuiObject); | ||
export function getObjectDeletedResponse( | ||
resp: GetObjectInfoResponse | ||
resp: GetObjectDataResponse | ||
): SuiObjectRef | undefined { | ||
@@ -92,3 +96,3 @@ return resp.status !== 'Deleted' ? undefined : (resp.details as SuiObjectRef); | ||
export function getObjectNotExistsResponse( | ||
resp: GetObjectInfoResponse | ||
resp: GetObjectDataResponse | ||
): ObjectId | undefined { | ||
@@ -99,3 +103,3 @@ return resp.status !== 'NotExists' ? undefined : (resp.details as ObjectId); | ||
export function getObjectReference( | ||
resp: GetObjectInfoResponse | ||
resp: GetObjectDataResponse | ||
): SuiObjectRef | undefined { | ||
@@ -110,3 +114,3 @@ return ( | ||
export function getObjectId( | ||
data: GetObjectInfoResponse | SuiObjectRef | ||
data: GetObjectDataResponse | SuiObjectRef | ||
): ObjectId { | ||
@@ -122,3 +126,3 @@ if ('objectId' in data) { | ||
export function getObjectVersion( | ||
data: GetObjectInfoResponse | SuiObjectRef | ||
data: GetObjectDataResponse | SuiObjectRef | ||
): number | undefined { | ||
@@ -134,3 +138,3 @@ if ('version' in data) { | ||
export function getObjectType( | ||
resp: GetObjectInfoResponse | ||
resp: GetObjectDataResponse | ||
): ObjectType | undefined { | ||
@@ -141,3 +145,3 @@ return getObjectExistsResponse(resp)?.data.dataType; | ||
export function getObjectPreviousTransactionDigest( | ||
resp: GetObjectInfoResponse | ||
resp: GetObjectDataResponse | ||
): TransactionDigest | undefined { | ||
@@ -148,3 +152,3 @@ return getObjectExistsResponse(resp)?.previousTransaction; | ||
export function getObjectOwner( | ||
resp: GetObjectInfoResponse | ||
resp: GetObjectDataResponse | ||
): ObjectOwner | undefined { | ||
@@ -155,3 +159,3 @@ return getObjectExistsResponse(resp)?.owner; | ||
export function getMoveObjectType( | ||
resp: GetObjectInfoResponse | ||
resp: GetObjectDataResponse | ||
): string | undefined { | ||
@@ -162,3 +166,3 @@ return getMoveObject(resp)?.type; | ||
export function getObjectFields( | ||
resp: GetObjectInfoResponse | ||
resp: GetObjectDataResponse | ||
): ObjectContentFields | undefined { | ||
@@ -169,5 +173,5 @@ return getMoveObject(resp)?.fields; | ||
export function getMoveObject( | ||
resp: GetObjectInfoResponse | ||
data: GetObjectDataResponse | SuiObject | ||
): SuiMoveObject | undefined { | ||
const suiObject = getObjectExistsResponse(resp); | ||
const suiObject = 'data' in data ? data : getObjectExistsResponse(data); | ||
if (suiObject?.data.dataType !== 'moveObject') { | ||
@@ -180,3 +184,3 @@ return undefined; | ||
export function getMovePackageContent( | ||
data: GetObjectInfoResponse | SuiMovePackage | ||
data: GetObjectDataResponse | SuiMovePackage | ||
): MovePackageContent | undefined { | ||
@@ -183,0 +187,0 @@ if ('disassembled' in data) { |
@@ -129,2 +129,8 @@ // Copyright (c) 2022, Mysten Labs, Inc. | ||
export type MergeCoinResponse = { | ||
certificate: CertifiedTransaction; | ||
updatedCoin: SuiObject; | ||
updatedGas: SuiObject; | ||
}; | ||
export type SplitCoinResponse = { | ||
@@ -140,6 +146,9 @@ certificate: CertifiedTransaction; | ||
EffectResponse: TransactionEffectsResponse; | ||
// TODO: Add Publish, MergeCoin Response | ||
// TODO: Add Publish Response | ||
} | ||
| { | ||
SplitCoinResponse: SplitCoinResponse; | ||
} | ||
| { | ||
MergeCoinResponse: MergeCoinResponse; | ||
}; | ||
@@ -252,1 +261,54 @@ | ||
} | ||
/* --------------------------- TransactionResponse -------------------------- */ | ||
export function getTransactionEffectsResponse( | ||
data: TransactionResponse | ||
): TransactionEffectsResponse | undefined { | ||
return 'EffectResponse' in data ? data.EffectResponse : undefined; | ||
} | ||
export function getSplitCoinResponse( | ||
data: TransactionResponse | ||
): SplitCoinResponse | undefined { | ||
return 'SplitCoinResponse' in data ? data.SplitCoinResponse : undefined; | ||
} | ||
export function getMergeCoinResponse( | ||
data: TransactionResponse | ||
): MergeCoinResponse | undefined { | ||
return 'MergeCoinResponse' in data ? data.MergeCoinResponse : undefined; | ||
} | ||
/** | ||
* Get the updated coin after a merge. | ||
* @param data the response for executing a merge coin transaction | ||
* @returns the updated state of the primary coin after the merge | ||
*/ | ||
export function getCoinAfterMerge( | ||
data: TransactionResponse | ||
): SuiObject | undefined { | ||
return getMergeCoinResponse(data)?.updatedCoin; | ||
} | ||
/** | ||
* Get the updated coin after a split. | ||
* @param data the response for executing a Split coin transaction | ||
* @returns the updated state of the original coin object used for the split | ||
*/ | ||
export function getCoinAfterSplit( | ||
data: TransactionResponse | ||
): SuiObject | undefined { | ||
return getSplitCoinResponse(data)?.updatedCoin; | ||
} | ||
/** | ||
* Get the newly created coin after a split. | ||
* @param data the response for executing a Split coin transaction | ||
* @returns the updated state of the original coin object used for the split | ||
*/ | ||
export function getNewlyCreatedCoinsAfterSplit( | ||
data: TransactionResponse | ||
): SuiObject[] | undefined { | ||
return getSplitCoinResponse(data)?.newCoins; | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1000193
10485
154
11