@thru/protocol 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,125 @@
1
+ import { AppMetadata, AddressType, ConnectResult } from '@thru/chain-interfaces';
2
+ export { AppMetadata, ConnectResult } from '@thru/chain-interfaces';
3
+
4
+ declare const POST_MESSAGE_REQUEST_TYPES: {
5
+ readonly CONNECT: "connect";
6
+ readonly DISCONNECT: "disconnect";
7
+ readonly SIGN_MESSAGE: "signMessage";
8
+ readonly SIGN_TRANSACTION: "signTransaction";
9
+ readonly GET_ACCOUNTS: "getAccounts";
10
+ };
11
+ type RequestType = typeof POST_MESSAGE_REQUEST_TYPES[keyof typeof POST_MESSAGE_REQUEST_TYPES];
12
+ declare const EMBEDDED_PROVIDER_EVENTS: {
13
+ readonly CONNECT_START: "connect_start";
14
+ readonly CONNECT: "connect";
15
+ readonly DISCONNECT: "disconnect";
16
+ readonly CONNECT_ERROR: "connect_error";
17
+ readonly ERROR: "error";
18
+ readonly LOCK: "lock";
19
+ };
20
+ type EmbeddedProviderEvent = typeof EMBEDDED_PROVIDER_EVENTS[keyof typeof EMBEDDED_PROVIDER_EVENTS];
21
+ declare const POST_MESSAGE_EVENT_TYPE: "event";
22
+ declare const IFRAME_READY_EVENT: "iframe:ready";
23
+ declare const DEFAULT_IFRAME_URL = "https://wallet.thru.io/embedded";
24
+ declare const createRequestId: (prefix?: string) => string;
25
+ interface BaseRequest {
26
+ id: string;
27
+ origin: string;
28
+ }
29
+ interface ConnectRequestMessage extends BaseRequest {
30
+ type: typeof POST_MESSAGE_REQUEST_TYPES.CONNECT;
31
+ payload: ConnectRequestPayload;
32
+ }
33
+ interface DisconnectRequestMessage extends BaseRequest {
34
+ type: typeof POST_MESSAGE_REQUEST_TYPES.DISCONNECT;
35
+ payload?: undefined;
36
+ }
37
+ interface SignMessageRequestMessage extends BaseRequest {
38
+ type: typeof POST_MESSAGE_REQUEST_TYPES.SIGN_MESSAGE;
39
+ payload: SignMessagePayload;
40
+ }
41
+ interface SignTransactionRequestMessage extends BaseRequest {
42
+ type: typeof POST_MESSAGE_REQUEST_TYPES.SIGN_TRANSACTION;
43
+ payload: SignTransactionPayload;
44
+ }
45
+ interface GetAccountsRequestMessage extends BaseRequest {
46
+ type: typeof POST_MESSAGE_REQUEST_TYPES.GET_ACCOUNTS;
47
+ payload?: undefined;
48
+ }
49
+ type PostMessageRequest = ConnectRequestMessage | DisconnectRequestMessage | SignMessageRequestMessage | SignTransactionRequestMessage | GetAccountsRequestMessage;
50
+ interface DisconnectResult {
51
+ }
52
+ interface GetAccountsResult {
53
+ addresses: Array<{
54
+ addressType: AddressType;
55
+ address: string;
56
+ }>;
57
+ }
58
+ type RequestResultMap = {
59
+ [POST_MESSAGE_REQUEST_TYPES.CONNECT]: ConnectResult;
60
+ [POST_MESSAGE_REQUEST_TYPES.DISCONNECT]: DisconnectResult;
61
+ [POST_MESSAGE_REQUEST_TYPES.SIGN_MESSAGE]: SignMessageResult;
62
+ [POST_MESSAGE_REQUEST_TYPES.SIGN_TRANSACTION]: SignTransactionResult;
63
+ [POST_MESSAGE_REQUEST_TYPES.GET_ACCOUNTS]: GetAccountsResult;
64
+ };
65
+ interface ResponseErrorPayload {
66
+ code: ErrorCode;
67
+ message: string;
68
+ }
69
+ type SuccessResponse<TType extends RequestType> = {
70
+ id: string;
71
+ success: true;
72
+ result: RequestResultMap[TType];
73
+ };
74
+ type ErrorResponse = {
75
+ id: string;
76
+ success: false;
77
+ error: ResponseErrorPayload;
78
+ };
79
+ type PostMessageResponse<TType extends RequestType = RequestType> = SuccessResponse<TType> | ErrorResponse;
80
+ type SuccessfulPostMessageResponse<TType extends RequestType = RequestType> = Extract<PostMessageResponse<TType>, {
81
+ success: true;
82
+ }>;
83
+ type InferPostMessageResponse<TRequest extends PostMessageRequest> = PostMessageResponse<TRequest['type']>;
84
+ type InferSuccessfulPostMessageResponse<TRequest extends PostMessageRequest> = SuccessfulPostMessageResponse<TRequest['type']>;
85
+ interface PostMessageEvent<TEvent extends EmbeddedProviderEvent = EmbeddedProviderEvent, TData = any> {
86
+ type: typeof POST_MESSAGE_EVENT_TYPE;
87
+ event: TEvent;
88
+ data?: TData;
89
+ }
90
+ declare const ErrorCode: {
91
+ readonly USER_REJECTED: "USER_REJECTED";
92
+ readonly WALLET_LOCKED: "WALLET_LOCKED";
93
+ readonly INVALID_PASSWORD: "INVALID_PASSWORD";
94
+ readonly ALREADY_CONNECTED: "ALREADY_CONNECTED";
95
+ readonly ACCOUNT_NOT_FOUND: "ACCOUNT_NOT_FOUND";
96
+ readonly INVALID_TRANSACTION: "INVALID_TRANSACTION";
97
+ readonly TRANSACTION_FAILED: "TRANSACTION_FAILED";
98
+ readonly INSUFFICIENT_FUNDS: "INSUFFICIENT_FUNDS";
99
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
100
+ readonly TIMEOUT: "TIMEOUT";
101
+ readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
102
+ };
103
+ type ErrorCode = typeof ErrorCode[keyof typeof ErrorCode];
104
+ type ConnectMetadataInput = Partial<AppMetadata>;
105
+ interface ConnectRequestPayload {
106
+ metadata?: ConnectMetadataInput;
107
+ }
108
+
109
+ interface SignMessagePayload {
110
+ message: string | number[];
111
+ accountIndex?: number;
112
+ }
113
+ interface SignMessageResult {
114
+ signature: number[];
115
+ publicKey: string;
116
+ }
117
+ interface SignTransactionPayload {
118
+ transaction: string;
119
+ accountIndex?: number;
120
+ }
121
+ interface SignTransactionResult {
122
+ signedTransaction: string;
123
+ }
124
+
125
+ export { type ConnectMetadataInput, type ConnectRequestMessage, type ConnectRequestPayload, DEFAULT_IFRAME_URL, type DisconnectRequestMessage, type DisconnectResult, EMBEDDED_PROVIDER_EVENTS, type EmbeddedProviderEvent, ErrorCode, type GetAccountsRequestMessage, type GetAccountsResult, IFRAME_READY_EVENT, type InferPostMessageResponse, type InferSuccessfulPostMessageResponse, POST_MESSAGE_EVENT_TYPE, POST_MESSAGE_REQUEST_TYPES, type PostMessageEvent, type PostMessageRequest, type PostMessageResponse, type RequestType, type SignMessagePayload, type SignMessageRequestMessage, type SignMessageResult, type SignTransactionPayload, type SignTransactionRequestMessage, type SignTransactionResult, type SuccessfulPostMessageResponse, createRequestId };
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ // src/postMessage.ts
2
+ var POST_MESSAGE_REQUEST_TYPES = {
3
+ CONNECT: "connect",
4
+ DISCONNECT: "disconnect",
5
+ SIGN_MESSAGE: "signMessage",
6
+ SIGN_TRANSACTION: "signTransaction",
7
+ GET_ACCOUNTS: "getAccounts"
8
+ };
9
+ var EMBEDDED_PROVIDER_EVENTS = {
10
+ CONNECT_START: "connect_start",
11
+ CONNECT: "connect",
12
+ DISCONNECT: "disconnect",
13
+ CONNECT_ERROR: "connect_error",
14
+ ERROR: "error",
15
+ LOCK: "lock"
16
+ };
17
+ var POST_MESSAGE_EVENT_TYPE = "event";
18
+ var IFRAME_READY_EVENT = "iframe:ready";
19
+ var DEFAULT_IFRAME_URL = "https://wallet.thru.io/embedded";
20
+ var REQUEST_ID_PREFIX = "req";
21
+ var createRequestId = (prefix = REQUEST_ID_PREFIX) => {
22
+ const random = Math.random().toString(36).slice(2, 11);
23
+ return `${prefix}_${Date.now()}_${random}`;
24
+ };
25
+ var ErrorCode = {
26
+ USER_REJECTED: "USER_REJECTED",
27
+ WALLET_LOCKED: "WALLET_LOCKED",
28
+ INVALID_PASSWORD: "INVALID_PASSWORD",
29
+ ALREADY_CONNECTED: "ALREADY_CONNECTED",
30
+ ACCOUNT_NOT_FOUND: "ACCOUNT_NOT_FOUND",
31
+ INVALID_TRANSACTION: "INVALID_TRANSACTION",
32
+ TRANSACTION_FAILED: "TRANSACTION_FAILED",
33
+ INSUFFICIENT_FUNDS: "INSUFFICIENT_FUNDS",
34
+ NETWORK_ERROR: "NETWORK_ERROR",
35
+ TIMEOUT: "TIMEOUT",
36
+ UNKNOWN_ERROR: "UNKNOWN_ERROR"
37
+ };
38
+
39
+ export { DEFAULT_IFRAME_URL, EMBEDDED_PROVIDER_EVENTS, ErrorCode, IFRAME_READY_EVENT, POST_MESSAGE_EVENT_TYPE, POST_MESSAGE_REQUEST_TYPES, createRequestId };
40
+ //# sourceMappingURL=index.js.map
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/postMessage.ts"],"names":[],"mappings":";AAEO,IAAM,0BAAA,GAA6B;AAAA,EACxC,OAAA,EAAS,SAAA;AAAA,EACT,UAAA,EAAY,YAAA;AAAA,EACZ,YAAA,EAAc,aAAA;AAAA,EACd,gBAAA,EAAkB,iBAAA;AAAA,EAClB,YAAA,EAAc;AAChB;AAIO,IAAM,wBAAA,GAA2B;AAAA,EACtC,aAAA,EAAe,eAAA;AAAA,EACf,OAAA,EAAS,SAAA;AAAA,EACT,UAAA,EAAY,YAAA;AAAA,EACZ,aAAA,EAAe,eAAA;AAAA,EACf,KAAA,EAAO,OAAA;AAAA,EACP,IAAA,EAAM;AACR;AAKO,IAAM,uBAAA,GAA0B;AAEhC,IAAM,kBAAA,GAAqB;AAE3B,IAAM,kBAAA,GAAqB;AAElC,IAAM,iBAAA,GAAoB,KAAA;AAEnB,IAAM,eAAA,GAAkB,CAAC,MAAA,GAAiB,iBAAA,KAA8B;AAC7E,EAAA,MAAM,MAAA,GAAS,KAAK,MAAA,EAAO,CAAE,SAAS,EAAE,CAAA,CAAE,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AACrD,EAAA,OAAO,GAAG,MAAM,CAAA,CAAA,EAAI,KAAK,GAAA,EAAK,IAAI,MAAM,CAAA,CAAA;AAC1C;AA8FO,IAAM,SAAA,GAAY;AAAA,EACvB,aAAA,EAAe,eAAA;AAAA,EACf,aAAA,EAAe,eAAA;AAAA,EACf,gBAAA,EAAkB,kBAAA;AAAA,EAClB,iBAAA,EAAmB,mBAAA;AAAA,EACnB,iBAAA,EAAmB,mBAAA;AAAA,EACnB,mBAAA,EAAqB,qBAAA;AAAA,EACrB,kBAAA,EAAoB,oBAAA;AAAA,EACpB,kBAAA,EAAoB,oBAAA;AAAA,EACpB,aAAA,EAAe,eAAA;AAAA,EACf,OAAA,EAAS,SAAA;AAAA,EACT,aAAA,EAAe;AACjB","file":"index.js","sourcesContent":["import type { AddressType, AppMetadata, ConnectResult } from '@thru/chain-interfaces';\n\nexport const POST_MESSAGE_REQUEST_TYPES = {\n CONNECT: 'connect',\n DISCONNECT: 'disconnect',\n SIGN_MESSAGE: 'signMessage',\n SIGN_TRANSACTION: 'signTransaction',\n GET_ACCOUNTS: 'getAccounts',\n} as const;\n\nexport type RequestType = typeof POST_MESSAGE_REQUEST_TYPES[keyof typeof POST_MESSAGE_REQUEST_TYPES];\n\nexport const EMBEDDED_PROVIDER_EVENTS = {\n CONNECT_START: 'connect_start',\n CONNECT: 'connect',\n DISCONNECT: 'disconnect',\n CONNECT_ERROR: 'connect_error',\n ERROR: 'error',\n LOCK: 'lock',\n} as const;\n\nexport type EmbeddedProviderEvent =\n typeof EMBEDDED_PROVIDER_EVENTS[keyof typeof EMBEDDED_PROVIDER_EVENTS];\n\nexport const POST_MESSAGE_EVENT_TYPE = 'event' as const;\n\nexport const IFRAME_READY_EVENT = 'iframe:ready' as const;\n\nexport const DEFAULT_IFRAME_URL = 'https://wallet.thru.io/embedded';\n\nconst REQUEST_ID_PREFIX = 'req';\n\nexport const createRequestId = (prefix: string = REQUEST_ID_PREFIX): string => {\n const random = Math.random().toString(36).slice(2, 11);\n return `${prefix}_${Date.now()}_${random}`;\n};\n\ninterface BaseRequest {\n id: string;\n origin: string;\n}\n\nexport interface ConnectRequestMessage extends BaseRequest {\n type: typeof POST_MESSAGE_REQUEST_TYPES.CONNECT;\n payload: ConnectRequestPayload;\n}\n\nexport interface DisconnectRequestMessage extends BaseRequest {\n type: typeof POST_MESSAGE_REQUEST_TYPES.DISCONNECT;\n payload?: undefined;\n}\n\nexport interface SignMessageRequestMessage extends BaseRequest {\n type: typeof POST_MESSAGE_REQUEST_TYPES.SIGN_MESSAGE;\n payload: SignMessagePayload;\n}\n\nexport interface SignTransactionRequestMessage extends BaseRequest {\n type: typeof POST_MESSAGE_REQUEST_TYPES.SIGN_TRANSACTION;\n payload: SignTransactionPayload;\n}\n\nexport interface GetAccountsRequestMessage extends BaseRequest {\n type: typeof POST_MESSAGE_REQUEST_TYPES.GET_ACCOUNTS;\n payload?: undefined;\n}\n\nexport type PostMessageRequest =\n | ConnectRequestMessage\n | DisconnectRequestMessage\n | SignMessageRequestMessage\n | SignTransactionRequestMessage\n | GetAccountsRequestMessage;\n\nexport interface DisconnectResult {\n // Empty object keeps compatibility with existing consumers expecting a success payload\n}\n\nexport interface GetAccountsResult {\n addresses: Array<{\n addressType: AddressType;\n address: string;\n }>;\n}\n\ntype RequestResultMap = {\n [POST_MESSAGE_REQUEST_TYPES.CONNECT]: ConnectResult;\n [POST_MESSAGE_REQUEST_TYPES.DISCONNECT]: DisconnectResult;\n [POST_MESSAGE_REQUEST_TYPES.SIGN_MESSAGE]: SignMessageResult;\n [POST_MESSAGE_REQUEST_TYPES.SIGN_TRANSACTION]: SignTransactionResult;\n [POST_MESSAGE_REQUEST_TYPES.GET_ACCOUNTS]: GetAccountsResult;\n};\n\ninterface ResponseErrorPayload {\n code: ErrorCode;\n message: string;\n}\n\ntype SuccessResponse<TType extends RequestType> = {\n id: string;\n success: true;\n result: RequestResultMap[TType];\n};\n\ntype ErrorResponse = {\n id: string;\n success: false;\n error: ResponseErrorPayload;\n};\n\nexport type PostMessageResponse<TType extends RequestType = RequestType> =\n | SuccessResponse<TType>\n | ErrorResponse;\n\nexport type SuccessfulPostMessageResponse<TType extends RequestType = RequestType> =\n Extract<PostMessageResponse<TType>, { success: true }>;\n\nexport type InferPostMessageResponse<TRequest extends PostMessageRequest> =\n PostMessageResponse<TRequest['type']>;\n\nexport type InferSuccessfulPostMessageResponse<TRequest extends PostMessageRequest> =\n SuccessfulPostMessageResponse<TRequest['type']>;\n\nexport interface PostMessageEvent<TEvent extends EmbeddedProviderEvent = EmbeddedProviderEvent, TData = any> {\n type: typeof POST_MESSAGE_EVENT_TYPE;\n event: TEvent;\n data?: TData;\n}\n\nexport const ErrorCode = {\n USER_REJECTED: 'USER_REJECTED',\n WALLET_LOCKED: 'WALLET_LOCKED',\n INVALID_PASSWORD: 'INVALID_PASSWORD',\n ALREADY_CONNECTED: 'ALREADY_CONNECTED',\n ACCOUNT_NOT_FOUND: 'ACCOUNT_NOT_FOUND',\n INVALID_TRANSACTION: 'INVALID_TRANSACTION',\n TRANSACTION_FAILED: 'TRANSACTION_FAILED',\n INSUFFICIENT_FUNDS: 'INSUFFICIENT_FUNDS',\n NETWORK_ERROR: 'NETWORK_ERROR',\n TIMEOUT: 'TIMEOUT',\n UNKNOWN_ERROR: 'UNKNOWN_ERROR',\n} as const;\n\nexport type ErrorCode = typeof ErrorCode[keyof typeof ErrorCode];\n\nexport type ConnectMetadataInput = Partial<AppMetadata>;\n\nexport interface ConnectRequestPayload {\n metadata?: ConnectMetadataInput;\n}\n\nexport type { AppMetadata, ConnectResult };\n\nexport interface SignMessagePayload {\n message: string | number[];\n accountIndex?: number;\n}\n\nexport interface SignMessageResult {\n signature: number[];\n publicKey: string;\n}\n\nexport interface SignTransactionPayload {\n transaction: string;\n accountIndex?: number;\n}\n\nexport interface SignTransactionResult {\n signedTransaction: string;\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@thru/protocol",
3
+ "version": "0.0.4",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
13
+ "dependencies": {
14
+ "@thru/chain-interfaces": "0.0.4"
15
+ },
16
+ "scripts": {
17
+ "build": "tsup",
18
+ "dev": "tsup --watch",
19
+ "lint": "eslint src/",
20
+ "clean": "rm -rf dist"
21
+ }
22
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './postMessage';
@@ -0,0 +1,171 @@
1
+ import type { AddressType, AppMetadata, ConnectResult } from '@thru/chain-interfaces';
2
+
3
+ export const POST_MESSAGE_REQUEST_TYPES = {
4
+ CONNECT: 'connect',
5
+ DISCONNECT: 'disconnect',
6
+ SIGN_MESSAGE: 'signMessage',
7
+ SIGN_TRANSACTION: 'signTransaction',
8
+ GET_ACCOUNTS: 'getAccounts',
9
+ } as const;
10
+
11
+ export type RequestType = typeof POST_MESSAGE_REQUEST_TYPES[keyof typeof POST_MESSAGE_REQUEST_TYPES];
12
+
13
+ export const EMBEDDED_PROVIDER_EVENTS = {
14
+ CONNECT_START: 'connect_start',
15
+ CONNECT: 'connect',
16
+ DISCONNECT: 'disconnect',
17
+ CONNECT_ERROR: 'connect_error',
18
+ ERROR: 'error',
19
+ LOCK: 'lock',
20
+ } as const;
21
+
22
+ export type EmbeddedProviderEvent =
23
+ typeof EMBEDDED_PROVIDER_EVENTS[keyof typeof EMBEDDED_PROVIDER_EVENTS];
24
+
25
+ export const POST_MESSAGE_EVENT_TYPE = 'event' as const;
26
+
27
+ export const IFRAME_READY_EVENT = 'iframe:ready' as const;
28
+
29
+ export const DEFAULT_IFRAME_URL = 'https://wallet.thru.io/embedded';
30
+
31
+ const REQUEST_ID_PREFIX = 'req';
32
+
33
+ export const createRequestId = (prefix: string = REQUEST_ID_PREFIX): string => {
34
+ const random = Math.random().toString(36).slice(2, 11);
35
+ return `${prefix}_${Date.now()}_${random}`;
36
+ };
37
+
38
+ interface BaseRequest {
39
+ id: string;
40
+ origin: string;
41
+ }
42
+
43
+ export interface ConnectRequestMessage extends BaseRequest {
44
+ type: typeof POST_MESSAGE_REQUEST_TYPES.CONNECT;
45
+ payload: ConnectRequestPayload;
46
+ }
47
+
48
+ export interface DisconnectRequestMessage extends BaseRequest {
49
+ type: typeof POST_MESSAGE_REQUEST_TYPES.DISCONNECT;
50
+ payload?: undefined;
51
+ }
52
+
53
+ export interface SignMessageRequestMessage extends BaseRequest {
54
+ type: typeof POST_MESSAGE_REQUEST_TYPES.SIGN_MESSAGE;
55
+ payload: SignMessagePayload;
56
+ }
57
+
58
+ export interface SignTransactionRequestMessage extends BaseRequest {
59
+ type: typeof POST_MESSAGE_REQUEST_TYPES.SIGN_TRANSACTION;
60
+ payload: SignTransactionPayload;
61
+ }
62
+
63
+ export interface GetAccountsRequestMessage extends BaseRequest {
64
+ type: typeof POST_MESSAGE_REQUEST_TYPES.GET_ACCOUNTS;
65
+ payload?: undefined;
66
+ }
67
+
68
+ export type PostMessageRequest =
69
+ | ConnectRequestMessage
70
+ | DisconnectRequestMessage
71
+ | SignMessageRequestMessage
72
+ | SignTransactionRequestMessage
73
+ | GetAccountsRequestMessage;
74
+
75
+ export interface DisconnectResult {
76
+ // Empty object keeps compatibility with existing consumers expecting a success payload
77
+ }
78
+
79
+ export interface GetAccountsResult {
80
+ addresses: Array<{
81
+ addressType: AddressType;
82
+ address: string;
83
+ }>;
84
+ }
85
+
86
+ type RequestResultMap = {
87
+ [POST_MESSAGE_REQUEST_TYPES.CONNECT]: ConnectResult;
88
+ [POST_MESSAGE_REQUEST_TYPES.DISCONNECT]: DisconnectResult;
89
+ [POST_MESSAGE_REQUEST_TYPES.SIGN_MESSAGE]: SignMessageResult;
90
+ [POST_MESSAGE_REQUEST_TYPES.SIGN_TRANSACTION]: SignTransactionResult;
91
+ [POST_MESSAGE_REQUEST_TYPES.GET_ACCOUNTS]: GetAccountsResult;
92
+ };
93
+
94
+ interface ResponseErrorPayload {
95
+ code: ErrorCode;
96
+ message: string;
97
+ }
98
+
99
+ type SuccessResponse<TType extends RequestType> = {
100
+ id: string;
101
+ success: true;
102
+ result: RequestResultMap[TType];
103
+ };
104
+
105
+ type ErrorResponse = {
106
+ id: string;
107
+ success: false;
108
+ error: ResponseErrorPayload;
109
+ };
110
+
111
+ export type PostMessageResponse<TType extends RequestType = RequestType> =
112
+ | SuccessResponse<TType>
113
+ | ErrorResponse;
114
+
115
+ export type SuccessfulPostMessageResponse<TType extends RequestType = RequestType> =
116
+ Extract<PostMessageResponse<TType>, { success: true }>;
117
+
118
+ export type InferPostMessageResponse<TRequest extends PostMessageRequest> =
119
+ PostMessageResponse<TRequest['type']>;
120
+
121
+ export type InferSuccessfulPostMessageResponse<TRequest extends PostMessageRequest> =
122
+ SuccessfulPostMessageResponse<TRequest['type']>;
123
+
124
+ export interface PostMessageEvent<TEvent extends EmbeddedProviderEvent = EmbeddedProviderEvent, TData = any> {
125
+ type: typeof POST_MESSAGE_EVENT_TYPE;
126
+ event: TEvent;
127
+ data?: TData;
128
+ }
129
+
130
+ export const ErrorCode = {
131
+ USER_REJECTED: 'USER_REJECTED',
132
+ WALLET_LOCKED: 'WALLET_LOCKED',
133
+ INVALID_PASSWORD: 'INVALID_PASSWORD',
134
+ ALREADY_CONNECTED: 'ALREADY_CONNECTED',
135
+ ACCOUNT_NOT_FOUND: 'ACCOUNT_NOT_FOUND',
136
+ INVALID_TRANSACTION: 'INVALID_TRANSACTION',
137
+ TRANSACTION_FAILED: 'TRANSACTION_FAILED',
138
+ INSUFFICIENT_FUNDS: 'INSUFFICIENT_FUNDS',
139
+ NETWORK_ERROR: 'NETWORK_ERROR',
140
+ TIMEOUT: 'TIMEOUT',
141
+ UNKNOWN_ERROR: 'UNKNOWN_ERROR',
142
+ } as const;
143
+
144
+ export type ErrorCode = typeof ErrorCode[keyof typeof ErrorCode];
145
+
146
+ export type ConnectMetadataInput = Partial<AppMetadata>;
147
+
148
+ export interface ConnectRequestPayload {
149
+ metadata?: ConnectMetadataInput;
150
+ }
151
+
152
+ export type { AppMetadata, ConnectResult };
153
+
154
+ export interface SignMessagePayload {
155
+ message: string | number[];
156
+ accountIndex?: number;
157
+ }
158
+
159
+ export interface SignMessageResult {
160
+ signature: number[];
161
+ publicKey: string;
162
+ }
163
+
164
+ export interface SignTransactionPayload {
165
+ transaction: string;
166
+ accountIndex?: number;
167
+ }
168
+
169
+ export interface SignTransactionResult {
170
+ signedTransaction: string;
171
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src"],
8
+ "exclude": ["node_modules", "dist"]
9
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig({
4
+ entry: ['src/index.ts'],
5
+ format: ['esm'],
6
+ dts: true,
7
+ sourcemap: true,
8
+ clean: true,
9
+ treeshake: true,
10
+ platform: 'browser'
11
+ });