@snowflake-so/safe-apps-sdk
Advanced tools
Comparing version 1.0.12 to 1.1.0
@@ -1,6 +0,6 @@ | ||
import { ErrorResponse, MessageMethod, MessagePayload, MessageReturnData, RequestMessage, SuccessResponse } from '../types'; | ||
import { ErrorResponse, MessageMethod, MessageReturnData, MessageSerializedPayload, RequestMessage, SuccessResponse } from '../types'; | ||
export default class MessageFormatter { | ||
static makeRequest<T extends MessageMethod>(method: T, payload: MessagePayload[T]): RequestMessage<T>; | ||
static makeRequest<T extends MessageMethod>(method: T, payload: MessageSerializedPayload[T]): RequestMessage<T>; | ||
static makeResponse<T extends MessageMethod>(id: string, data: MessageReturnData[T]): SuccessResponse<T>; | ||
static makeError<T extends MessageMethod>(id: string, method: T, error: string): ErrorResponse; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { Communicator, MessageMethod, MessagePayload, MessageReturnData, ResponseMessage } from '../types'; | ||
import { Communicator, MessageMethod, MessageReturnData, MessageSerializedPayload, ResponseMessage } from '../types'; | ||
export declare class PostMessageCommunicator implements Communicator { | ||
@@ -11,3 +11,3 @@ private readonly _allowedOrigins; | ||
private onParentMessage; | ||
send<T extends MessageMethod>(method: T, payload: MessagePayload[T]): Promise<ResponseMessage<MessageReturnData[T]>>; | ||
send<T extends MessageMethod>(method: T, payload: MessageSerializedPayload[T]): Promise<ResponseMessage<MessageReturnData[T]>>; | ||
} |
import { CommunicatorService, MessageMethod, MessagePayload, MessageReturnData, ResponseMessage } from '../types'; | ||
export declare class TransactionCommunicatorService extends CommunicatorService { | ||
private _prepareCreateProposalPayload; | ||
private _prepareSignTransactionPayload; | ||
private _prepareSignMessagePayload; | ||
createProposal(payload: MessagePayload[MessageMethod.createProposal]): Promise<ResponseMessage<MessageReturnData[MessageMethod.createProposal]>>; | ||
signMessage(payload: MessagePayload[MessageMethod.signMessage]): Promise<ResponseMessage<MessageReturnData[MessageMethod.signMessage]>>; | ||
sendTransaction(payload: MessagePayload[MessageMethod.sendTransaction]): Promise<ResponseMessage<MessageReturnData[MessageMethod.sendTransaction]>>; | ||
signTransaction(payload: MessagePayload[MessageMethod.signTransaction]): Promise<ResponseMessage<{ | ||
transaction: import("../types").SerializedTransaction; | ||
}>>; | ||
signAllTransactions(payload: MessagePayload[MessageMethod.signAllTransactions]): Promise<ResponseMessage<{ | ||
transaction: import("../types").SerializedTransaction[]; | ||
}>>; | ||
} |
@@ -8,13 +8,21 @@ "use strict"; | ||
_prepareCreateProposalPayload(payload) { | ||
const preparedPayload = payload; | ||
preparedPayload.executeInstructions = utils_1.MessageUtils.serializeTransactionInstructions(payload.executeInstructions); | ||
if (payload.setupInstructions) { | ||
preparedPayload.setupInstructions = utils_1.MessageUtils.serializeTransactionInstructions(payload.setupInstructions); | ||
} | ||
preparedPayload.signers = preparedPayload.signers.map(signer => ({ | ||
publicKey: signer.publicKey.toString(), | ||
secretKey: Buffer.from(signer.secretKey).toJSON(), | ||
})); | ||
return preparedPayload; | ||
return { | ||
executeInstructions: utils_1.MessageUtils.serializeTransactionInstructions(payload.executeInstructions), | ||
display: payload.display, | ||
signers: payload.signers.map(utils_1.MessageUtils.serializeSigner), | ||
setupInstructions: payload.setupInstructions | ||
? utils_1.MessageUtils.serializeTransactionInstructions(payload.setupInstructions) | ||
: [], | ||
}; | ||
} | ||
_prepareSignTransactionPayload(payload) { | ||
return { | ||
transaction: utils_1.MessageUtils.serializeTransaction(payload.transaction), | ||
}; | ||
} | ||
_prepareSignMessagePayload(payload) { | ||
return { | ||
message: utils_1.MessageUtils.serializeBuffer(payload.message), | ||
}; | ||
} | ||
createProposal(payload) { | ||
@@ -24,9 +32,14 @@ return this._communicator.send(types_1.MessageMethod.createProposal, this._prepareCreateProposalPayload(payload)); | ||
signMessage(payload) { | ||
return this._communicator.send(types_1.MessageMethod.signMessage, payload); | ||
return this._communicator.send(types_1.MessageMethod.signMessage, this._prepareSignMessagePayload(payload)); | ||
} | ||
sendTransaction(payload) { | ||
return this._communicator.send(types_1.MessageMethod.sendTransaction, payload); | ||
signTransaction(payload) { | ||
return this._communicator.send(types_1.MessageMethod.signTransaction, this._prepareSignTransactionPayload(payload)); | ||
} | ||
signAllTransactions(payload) { | ||
return this._communicator.send(types_1.MessageMethod.signAllTransactions, { | ||
transactions: payload.transactions.map(transaction => utils_1.MessageUtils.serializeTransaction(transaction)), | ||
}); | ||
} | ||
} | ||
exports.TransactionCommunicatorService = TransactionCommunicatorService; | ||
//# sourceMappingURL=TransactionService.js.map |
@@ -1,4 +0,4 @@ | ||
import { MessageMethod, MessagePayload, MessageReturnData, Optional, ResponseMessage } from './message'; | ||
import { MessageMethod, MessageReturnData, MessageSerializedPayload, Optional, ResponseMessage } from './message'; | ||
export interface Communicator { | ||
send<M extends MessageMethod>(method: M, payload: Optional<MessagePayload[M]>): Promise<ResponseMessage<MessageReturnData[M]>>; | ||
send<M extends MessageMethod>(method: M, payload: Optional<MessageSerializedPayload[M]>): Promise<ResponseMessage<MessageReturnData[M]>>; | ||
} | ||
@@ -5,0 +5,0 @@ export declare class CommunicatorService { |
@@ -1,4 +0,3 @@ | ||
import { SendTransactionOptions } from '@solana/wallet-adapter-base'; | ||
import { Signer, Transaction, TransactionInstruction } from '@solana/web3.js'; | ||
import { NotNestedObject, StrPubkey } from './utils'; | ||
import { BufferJSON, NotNestedObject, SerializedSigner, SerializedTransaction, SerializedTransactionInstruction, StrPubkey } from './utils'; | ||
export declare type Optional<T> = T | undefined | null; | ||
@@ -10,4 +9,4 @@ export declare enum MessageMethod { | ||
signMessage = "signMessage", | ||
sendTransaction = "sendTransaction", | ||
signTransaction = "signTransaction" | ||
signTransaction = "signTransaction", | ||
signAllTransactions = "signAllTransactions" | ||
} | ||
@@ -28,8 +27,30 @@ export declare type MessagePayload = { | ||
}; | ||
[MessageMethod.sendTransaction]: { | ||
[MessageMethod.signTransaction]: { | ||
transaction: Transaction; | ||
opts?: SendTransactionOptions; | ||
}; | ||
[MessageMethod.signTransaction]: unknown; | ||
[MessageMethod.signAllTransactions]: { | ||
transactions: Transaction[]; | ||
}; | ||
}; | ||
export declare type MessageSerializedPayload = { | ||
[MessageMethod.createProposal]: { | ||
display: { | ||
proposalName: string; | ||
} & NotNestedObject; | ||
executeInstructions: SerializedTransactionInstruction[]; | ||
setupInstructions?: Optional<SerializedTransactionInstruction[]>; | ||
signers: SerializedSigner[]; | ||
}; | ||
[MessageMethod.getSafeInfo]: unknown; | ||
[MessageMethod.getSafeBalance]: unknown; | ||
[MessageMethod.signMessage]: { | ||
message: BufferJSON; | ||
}; | ||
[MessageMethod.signTransaction]: { | ||
transaction: SerializedTransaction; | ||
}; | ||
[MessageMethod.signAllTransactions]: { | ||
transactions: SerializedTransaction[]; | ||
}; | ||
}; | ||
export declare type MessageReturnData = { | ||
@@ -56,8 +77,10 @@ [MessageMethod.getSafeInfo]: { | ||
[MessageMethod.signMessage]: { | ||
message: Uint8Array; | ||
message: number[]; | ||
}; | ||
[MessageMethod.sendTransaction]: { | ||
txId: string; | ||
[MessageMethod.signTransaction]: { | ||
transaction: SerializedTransaction; | ||
}; | ||
[MessageMethod.signTransaction]: unknown; | ||
[MessageMethod.signAllTransactions]: { | ||
transaction: SerializedTransaction[]; | ||
}; | ||
}; | ||
@@ -82,3 +105,3 @@ export declare type MessageMethodFn = { | ||
id: string; | ||
payload: MessagePayload[T]; | ||
payload: MessageSerializedPayload[T]; | ||
method: MessageMethod; | ||
@@ -85,0 +108,0 @@ timestamp: number; |
@@ -10,5 +10,5 @@ "use strict"; | ||
MessageMethod["signMessage"] = "signMessage"; | ||
MessageMethod["sendTransaction"] = "sendTransaction"; | ||
MessageMethod["signTransaction"] = "signTransaction"; | ||
MessageMethod["signAllTransactions"] = "signAllTransactions"; | ||
})(MessageMethod = exports.MessageMethod || (exports.MessageMethod = {})); | ||
//# sourceMappingURL=message.js.map |
@@ -0,1 +1,2 @@ | ||
import { Blockhash } from '@solana/web3.js'; | ||
export interface NotNestedObject { | ||
@@ -18,1 +19,25 @@ [x: string]: number | boolean | string | Date | null | undefined; | ||
}; | ||
export declare type PublicKeyStr = string; | ||
export interface SerializedAccountMeta { | ||
pubkey: PublicKeyStr; | ||
isSigner: boolean; | ||
isWritable: boolean; | ||
} | ||
export interface SerializedTransaction { | ||
signatures: Array<{ | ||
signature: BufferJSON | null; | ||
publicKey: PublicKeyStr; | ||
}>; | ||
feePayer?: PublicKeyStr; | ||
instructions: Array<SerializedTransactionInstruction>; | ||
recentBlockhash?: Blockhash; | ||
lastValidBlockHeight?: number; | ||
nonceInfo?: { | ||
nonce: Blockhash; | ||
nonceInstruction: SerializedTransactionInstruction; | ||
}; | ||
} | ||
export interface SerializedSigner { | ||
publicKey: PublicKeyStr; | ||
secretKey: BufferJSON; | ||
} |
@@ -1,4 +0,4 @@ | ||
import { TransactionInstruction } from '@solana/web3.js'; | ||
import { Signer, Transaction, TransactionInstruction } from '@solana/web3.js'; | ||
import { MessageMethod } from '../types'; | ||
import { SerializedTransactionInstruction } from '../types/utils'; | ||
import { BufferJSON, SerializedTransaction, SerializedTransactionInstruction } from '../types/utils'; | ||
export declare class MessageUtils { | ||
@@ -9,2 +9,8 @@ get getSDKVersion(): number; | ||
static serializeTransactionInstructions(ixs: TransactionInstruction[]): SerializedTransactionInstruction[]; | ||
static serializeBuffer(bufferValue: Uint8Array): BufferJSON; | ||
static serializeSigner(signer: Signer): { | ||
publicKey: string; | ||
secretKey: BufferJSON; | ||
}; | ||
static serializeTransaction(transaction: Transaction): SerializedTransaction; | ||
} |
@@ -18,4 +18,32 @@ "use strict"; | ||
} | ||
static serializeBuffer(bufferValue) { | ||
return Buffer.from(bufferValue).toJSON(); | ||
} | ||
static serializeSigner(signer) { | ||
return { | ||
publicKey: signer.publicKey.toString(), | ||
secretKey: this.serializeBuffer(signer.secretKey), | ||
}; | ||
} | ||
static serializeTransaction(transaction) { | ||
var _a, _b; | ||
return { | ||
instructions: MessageUtils.serializeTransactionInstructions(transaction.instructions), | ||
signatures: transaction.signatures.map(signature => ({ | ||
publicKey: signature.publicKey.toString(), | ||
signature: signature.signature ? MessageUtils.serializeBuffer(signature.signature) : null, | ||
})), | ||
feePayer: (_a = transaction.feePayer) === null || _a === void 0 ? void 0 : _a.toString(), | ||
nonceInfo: { | ||
nonce: (_b = transaction.nonceInfo) === null || _b === void 0 ? void 0 : _b.nonce, | ||
nonceInstruction: (transaction.nonceInfo | ||
? this.serializeTransactionInstruction(transaction.nonceInfo.nonceInstruction) | ||
: null), | ||
}, | ||
lastValidBlockHeight: transaction.lastValidBlockHeight, | ||
recentBlockhash: transaction.recentBlockhash, | ||
}; | ||
} | ||
} | ||
exports.MessageUtils = MessageUtils; | ||
//# sourceMappingURL=message-utils.js.map |
{ | ||
"name": "@snowflake-so/safe-apps-sdk", | ||
"version": "1.0.12", | ||
"version": "1.1.0", | ||
"description": "Snowflake Safe Apps SDK - Integrate with Snowflake Safe operating system", | ||
@@ -8,3 +8,4 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "yarn rimraf dist && tsc -p src && yarn uglify", | ||
"build:prod": "yarn rimraf dist && tsc -p src && yarn uglify", | ||
"build": "yarn rimraf dist && tsc -p src", | ||
"watch": "tsc -w -p src", | ||
@@ -11,0 +12,0 @@ "prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write", |
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 not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
44808
570