@alien_org/contract 0.2.4 → 1.0.0-alpha.2
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.
- package/README.md +29 -11
- package/dist/index.cjs +33 -1
- package/dist/index.d.cts +194 -12
- package/dist/index.d.mts +194 -12
- package/dist/index.mjs +33 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ isMethodSupported('payment:request', '0.0.9'); // false
|
|
|
63
63
|
|
|
64
64
|
// Get minimum version that supports a method
|
|
65
65
|
getMethodMinVersion('app:ready'); // '0.0.9'
|
|
66
|
-
getMethodMinVersion('payment:request'); // '0.
|
|
66
|
+
getMethodMinVersion('payment:request'); // '0.1.1'
|
|
67
67
|
|
|
68
68
|
// Get version where a method was introduced
|
|
69
69
|
getReleaseVersion('app:ready'); // '0.0.9'
|
|
@@ -74,17 +74,33 @@ getReleaseVersion('app:ready'); // '0.0.9'
|
|
|
74
74
|
| Method | Since | Description |
|
|
75
75
|
|--------|-------|-------------|
|
|
76
76
|
| `app:ready` | 0.0.9 | Notify host that miniapp is ready |
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
| `
|
|
77
|
+
| `payment:request` | 0.1.1 | Request payment |
|
|
78
|
+
| `clipboard:write` | 0.1.1 | Write text to clipboard |
|
|
79
|
+
| `clipboard:read` | 0.1.1 | Read text from clipboard |
|
|
80
|
+
| `link:open` | 0.1.3 | Open a URL |
|
|
81
|
+
| `haptic:impact` | 0.2.4 | Trigger haptic impact feedback |
|
|
82
|
+
| `haptic:notification` | 0.2.4 | Trigger haptic notification feedback |
|
|
83
|
+
| `haptic:selection` | 0.2.4 | Trigger haptic selection feedback |
|
|
84
|
+
| `wallet.solana:connect` | 1.0.0 | Request Solana wallet connection |
|
|
85
|
+
| `wallet.solana:disconnect` | 1.0.0 | Disconnect from Solana wallet |
|
|
86
|
+
| `wallet.solana:sign.transaction` | 1.0.0 | Sign a Solana transaction |
|
|
87
|
+
| `wallet.solana:sign.message` | 1.0.0 | Sign a Solana message |
|
|
88
|
+
| `wallet.solana:sign.send` | 1.0.0 | Sign and send a Solana transaction |
|
|
89
|
+
| `app:close` | 1.0.0 | Request host to close the miniapp |
|
|
90
|
+
| `host.back.button:toggle` | 1.0.0 | Show/hide back button |
|
|
80
91
|
|
|
81
92
|
## Available Events
|
|
82
93
|
|
|
83
94
|
| Event | Since | Description |
|
|
84
95
|
|-------|-------|-------------|
|
|
85
96
|
| `miniapp:close` | 0.0.14 | Host is closing miniapp |
|
|
86
|
-
| `host.back.button:clicked` | 0.0
|
|
87
|
-
| `payment:response` | 0.
|
|
97
|
+
| `host.back.button:clicked` | 1.0.0 | Back button was clicked |
|
|
98
|
+
| `payment:response` | 0.1.1 | Payment result |
|
|
99
|
+
| `clipboard:response` | 0.1.1 | Clipboard read result |
|
|
100
|
+
| `wallet.solana:connect.response` | 1.0.0 | Wallet connection result |
|
|
101
|
+
| `wallet.solana:sign.transaction.response` | 1.0.0 | Transaction signing result |
|
|
102
|
+
| `wallet.solana:sign.message.response` | 1.0.0 | Message signing result |
|
|
103
|
+
| `wallet.solana:sign.send.response` | 1.0.0 | Sign and send result |
|
|
88
104
|
|
|
89
105
|
## LaunchParams
|
|
90
106
|
|
|
@@ -92,11 +108,13 @@ Parameters injected by the host app:
|
|
|
92
108
|
|
|
93
109
|
```typescript
|
|
94
110
|
interface LaunchParams {
|
|
95
|
-
authToken: string | undefined;
|
|
96
|
-
contractVersion: Version | undefined;
|
|
97
|
-
hostAppVersion: string | undefined;
|
|
98
|
-
platform: Platform | undefined;
|
|
99
|
-
|
|
111
|
+
authToken: string | undefined; // JWT auth token
|
|
112
|
+
contractVersion: Version | undefined; // Host's contract version
|
|
113
|
+
hostAppVersion: string | undefined; // Host app version
|
|
114
|
+
platform: Platform | undefined; // 'ios' | 'android'
|
|
115
|
+
safeAreaInsets: SafeAreaInsets | undefined; // System UI insets (CSS px)
|
|
116
|
+
startParam: string | undefined; // Custom param (referrals, etc.)
|
|
117
|
+
isFullscreen: boolean | undefined; // Launched in fullscreen mode
|
|
100
118
|
}
|
|
101
119
|
```
|
|
102
120
|
|
package/dist/index.cjs
CHANGED
|
@@ -9,7 +9,6 @@ const PLATFORMS = ["ios", "android"];
|
|
|
9
9
|
//#region src/methods/versions/releases.ts
|
|
10
10
|
const releases = {
|
|
11
11
|
"0.0.9": ["app:ready"],
|
|
12
|
-
"0.0.14": ["miniapp:close.ack", "host.back.button:toggle"],
|
|
13
12
|
"0.1.1": [
|
|
14
13
|
"payment:request",
|
|
15
14
|
"clipboard:write",
|
|
@@ -20,6 +19,15 @@ const releases = {
|
|
|
20
19
|
"haptic:impact",
|
|
21
20
|
"haptic:notification",
|
|
22
21
|
"haptic:selection"
|
|
22
|
+
],
|
|
23
|
+
"1.0.0": [
|
|
24
|
+
"wallet.solana:connect",
|
|
25
|
+
"wallet.solana:disconnect",
|
|
26
|
+
"wallet.solana:sign.transaction",
|
|
27
|
+
"wallet.solana:sign.message",
|
|
28
|
+
"wallet.solana:sign.send",
|
|
29
|
+
"app:close",
|
|
30
|
+
"host.back.button:toggle"
|
|
23
31
|
]
|
|
24
32
|
};
|
|
25
33
|
|
|
@@ -83,8 +91,32 @@ function getMethodMinVersion(method) {
|
|
|
83
91
|
}
|
|
84
92
|
}
|
|
85
93
|
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/utils.ts
|
|
96
|
+
/**
|
|
97
|
+
* Named constants for {@link WalletSolanaErrorCode}.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { WALLET_ERROR } from '@alien_org/contract';
|
|
102
|
+
*
|
|
103
|
+
* if (response.errorCode === WALLET_ERROR.USER_REJECTED) {
|
|
104
|
+
* // user cancelled
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @since 1.0.0
|
|
109
|
+
*/
|
|
110
|
+
const WALLET_ERROR = {
|
|
111
|
+
USER_REJECTED: 5e3,
|
|
112
|
+
INVALID_PARAMS: -32602,
|
|
113
|
+
INTERNAL_ERROR: -32603,
|
|
114
|
+
REQUEST_EXPIRED: 8e3
|
|
115
|
+
};
|
|
116
|
+
|
|
86
117
|
//#endregion
|
|
87
118
|
exports.PLATFORMS = PLATFORMS;
|
|
119
|
+
exports.WALLET_ERROR = WALLET_ERROR;
|
|
88
120
|
exports.getMethodMinVersion = getMethodMinVersion;
|
|
89
121
|
exports.getReleaseVersion = getReleaseVersion;
|
|
90
122
|
exports.isMethodSupported = isMethodSupported;
|
package/dist/index.d.cts
CHANGED
|
@@ -102,6 +102,62 @@ type HapticImpactStyle = 'light' | 'medium' | 'heavy' | 'soft' | 'rigid';
|
|
|
102
102
|
* @schema
|
|
103
103
|
*/
|
|
104
104
|
type HapticNotificationType = 'success' | 'warning' | 'error';
|
|
105
|
+
/**
|
|
106
|
+
* Solana wallet error codes (WalletConnect-compatible numeric codes).
|
|
107
|
+
*
|
|
108
|
+
* These codes are identical to WalletConnect JSON-RPC error codes,
|
|
109
|
+
* so the mobile app produces the same `(code, message)` pair for
|
|
110
|
+
* both bridge and relay transports — no mapping needed.
|
|
111
|
+
*
|
|
112
|
+
* | Code | Meaning | WC Name |
|
|
113
|
+
* |------|---------|---------|
|
|
114
|
+
* | `5000` | User rejected the request | `userRejected` |
|
|
115
|
+
* | `-32602` | Invalid params (malformed transaction, bad input) | JSON-RPC standard |
|
|
116
|
+
* | `-32603` | Internal error (send failed, unexpected error) | JSON-RPC standard |
|
|
117
|
+
* | `8000` | Request expired / timed out | `sessionRequestExpired` |
|
|
118
|
+
*
|
|
119
|
+
* @since 1.0.0
|
|
120
|
+
* @schema
|
|
121
|
+
*/
|
|
122
|
+
type WalletSolanaErrorCode = 5000 | -32602 | -32603 | 8000;
|
|
123
|
+
/**
|
|
124
|
+
* Named constants for {@link WalletSolanaErrorCode}.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { WALLET_ERROR } from '@alien_org/contract';
|
|
129
|
+
*
|
|
130
|
+
* if (response.errorCode === WALLET_ERROR.USER_REJECTED) {
|
|
131
|
+
* // user cancelled
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* @since 1.0.0
|
|
136
|
+
*/
|
|
137
|
+
declare const WALLET_ERROR: {
|
|
138
|
+
/** User rejected the request (cancelled approval screen). */
|
|
139
|
+
readonly USER_REJECTED: 5000;
|
|
140
|
+
/** Invalid params — transaction deserialization failed, malformed input. */
|
|
141
|
+
readonly INVALID_PARAMS: -32602;
|
|
142
|
+
/** Internal error — transaction broadcast failed, unexpected error. */
|
|
143
|
+
readonly INTERNAL_ERROR: -32603;
|
|
144
|
+
/** Request expired before the user responded. */
|
|
145
|
+
readonly REQUEST_EXPIRED: 8000;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Solana commitment levels for send options.
|
|
149
|
+
* @since 1.0.0
|
|
150
|
+
* @schema
|
|
151
|
+
*/
|
|
152
|
+
type SolanaCommitment = 'processed' | 'confirmed' | 'finalized';
|
|
153
|
+
/**
|
|
154
|
+
* Solana chain identifiers (wallet-standard format).
|
|
155
|
+
* Used by `wallet.solana:sign.send` to tell the host app
|
|
156
|
+
* which cluster to broadcast to.
|
|
157
|
+
* @since 1.0.0
|
|
158
|
+
* @schema
|
|
159
|
+
*/
|
|
160
|
+
type SolanaChain = 'solana:mainnet' | 'solana:devnet' | 'solana:testnet';
|
|
105
161
|
//#endregion
|
|
106
162
|
//#region src/events/types/payload.d.ts
|
|
107
163
|
/**
|
|
@@ -126,7 +182,7 @@ interface Events {
|
|
|
126
182
|
'miniapp:close': CreateEventPayload<Empty>;
|
|
127
183
|
/**
|
|
128
184
|
* Host app's back button clicked event.
|
|
129
|
-
* @since 0.0
|
|
185
|
+
* @since 1.0.0
|
|
130
186
|
* @schema
|
|
131
187
|
*/
|
|
132
188
|
'host.back.button:clicked': CreateEventPayload<Empty>;
|
|
@@ -195,6 +251,60 @@ interface Events {
|
|
|
195
251
|
*/
|
|
196
252
|
errorCode?: 'permission_denied' | 'unavailable';
|
|
197
253
|
}>>;
|
|
254
|
+
/**
|
|
255
|
+
* Solana wallet connection response.
|
|
256
|
+
* @since 1.0.0
|
|
257
|
+
* @schema
|
|
258
|
+
*/
|
|
259
|
+
'wallet.solana:connect.response': CreateEventPayload<WithReqId<{
|
|
260
|
+
/** Base58-encoded public key of the connected wallet */
|
|
261
|
+
publicKey?: string;
|
|
262
|
+
/** Numeric error code (WalletConnect-compatible). See {@link WalletSolanaErrorCode}. */
|
|
263
|
+
errorCode?: WalletSolanaErrorCode;
|
|
264
|
+
/** Human-readable error description */
|
|
265
|
+
errorMessage?: string;
|
|
266
|
+
}>>;
|
|
267
|
+
/**
|
|
268
|
+
* Solana transaction signing response.
|
|
269
|
+
* @since 1.0.0
|
|
270
|
+
* @schema
|
|
271
|
+
*/
|
|
272
|
+
'wallet.solana:sign.transaction.response': CreateEventPayload<WithReqId<{
|
|
273
|
+
/** Base64-encoded signed transaction */
|
|
274
|
+
signedTransaction?: string;
|
|
275
|
+
/** Numeric error code (WalletConnect-compatible). See {@link WalletSolanaErrorCode}. */
|
|
276
|
+
errorCode?: WalletSolanaErrorCode;
|
|
277
|
+
/** Human-readable error description */
|
|
278
|
+
errorMessage?: string;
|
|
279
|
+
}>>;
|
|
280
|
+
/**
|
|
281
|
+
* Solana message signing response.
|
|
282
|
+
* @since 1.0.0
|
|
283
|
+
* @schema
|
|
284
|
+
*/
|
|
285
|
+
'wallet.solana:sign.message.response': CreateEventPayload<WithReqId<{
|
|
286
|
+
/** Base58-encoded Ed25519 signature (64 bytes) */
|
|
287
|
+
signature?: string;
|
|
288
|
+
/** Base58-encoded public key that signed the message */
|
|
289
|
+
publicKey?: string;
|
|
290
|
+
/** Numeric error code (WalletConnect-compatible). See {@link WalletSolanaErrorCode}. */
|
|
291
|
+
errorCode?: WalletSolanaErrorCode;
|
|
292
|
+
/** Human-readable error description */
|
|
293
|
+
errorMessage?: string;
|
|
294
|
+
}>>;
|
|
295
|
+
/**
|
|
296
|
+
* Solana sign-and-send transaction response.
|
|
297
|
+
* @since 1.0.0
|
|
298
|
+
* @schema
|
|
299
|
+
*/
|
|
300
|
+
'wallet.solana:sign.send.response': CreateEventPayload<WithReqId<{
|
|
301
|
+
/** Base58-encoded transaction signature */
|
|
302
|
+
signature?: string;
|
|
303
|
+
/** Numeric error code (WalletConnect-compatible). See {@link WalletSolanaErrorCode}. */
|
|
304
|
+
errorCode?: WalletSolanaErrorCode;
|
|
305
|
+
/** Human-readable error description */
|
|
306
|
+
errorMessage?: string;
|
|
307
|
+
}>>;
|
|
198
308
|
}
|
|
199
309
|
//#endregion
|
|
200
310
|
//#region src/events/types/event-types.d.ts
|
|
@@ -239,6 +349,11 @@ interface LaunchParams {
|
|
|
239
349
|
* Used for referral codes, campaign tracking, or custom routing.
|
|
240
350
|
*/
|
|
241
351
|
startParam: string | undefined;
|
|
352
|
+
/**
|
|
353
|
+
* Whether the miniapp was launched in fullscreen mode.
|
|
354
|
+
* @since 1.0.0
|
|
355
|
+
*/
|
|
356
|
+
isFullscreen: boolean | undefined;
|
|
242
357
|
}
|
|
243
358
|
//#endregion
|
|
244
359
|
//#region src/methods/types/payload.d.ts
|
|
@@ -259,27 +374,27 @@ interface Methods {
|
|
|
259
374
|
/**
|
|
260
375
|
* Miniapp ready method.
|
|
261
376
|
* Sent by the miniapp to notify the host app that it has loaded and is ready to be displayed.
|
|
262
|
-
* @since 0.0.
|
|
377
|
+
* @since 0.0.9
|
|
263
378
|
* @schema
|
|
264
379
|
*/
|
|
265
380
|
'app:ready': CreateMethodPayload<Empty>;
|
|
266
381
|
/**
|
|
267
|
-
*
|
|
268
|
-
* Sent by the miniapp to
|
|
269
|
-
*
|
|
270
|
-
* @since 0.0
|
|
382
|
+
* Close the miniapp.
|
|
383
|
+
* Sent by the miniapp to request the host app to close it.
|
|
384
|
+
* Fire-and-forget — no response expected.
|
|
385
|
+
* @since 1.0.0
|
|
271
386
|
* @schema
|
|
272
387
|
*/
|
|
273
|
-
'
|
|
388
|
+
'app:close': CreateMethodPayload<Empty>;
|
|
274
389
|
/**
|
|
275
390
|
* Toggle host app's back button visibility.
|
|
276
|
-
* @since 0.0
|
|
391
|
+
* @since 1.0.0
|
|
277
392
|
* @schema
|
|
278
393
|
*/
|
|
279
394
|
'host.back.button:toggle': CreateMethodPayload<{
|
|
280
395
|
/**
|
|
281
396
|
* Whether to show or hide the back button.
|
|
282
|
-
* @since 0.0
|
|
397
|
+
* @since 1.0.0
|
|
283
398
|
* @schema
|
|
284
399
|
*/
|
|
285
400
|
visible: boolean;
|
|
@@ -291,8 +406,8 @@ interface Methods {
|
|
|
291
406
|
* Your backend receives a webhook when user pays - fulfill the order
|
|
292
407
|
* immediately without waiting for chain confirmation.
|
|
293
408
|
*
|
|
294
|
-
* Optional
|
|
295
|
-
*
|
|
409
|
+
* Optional `item` object (`title`, `iconUrl`, `quantity`)
|
|
410
|
+
* is shown on the payment approval screen.
|
|
296
411
|
*
|
|
297
412
|
* Set `test` to a scenario string (e.g. `'paid'`, `'error:insufficient_balance'`)
|
|
298
413
|
* for test mode - no real payment is made, but the specified scenario is
|
|
@@ -481,6 +596,73 @@ interface Methods {
|
|
|
481
596
|
* @schema
|
|
482
597
|
*/
|
|
483
598
|
'haptic:selection': CreateMethodPayload<Empty>;
|
|
599
|
+
/**
|
|
600
|
+
* Request Solana wallet connection.
|
|
601
|
+
* Returns the wallet's public key on success.
|
|
602
|
+
* @since 1.0.0
|
|
603
|
+
* @schema
|
|
604
|
+
*/
|
|
605
|
+
'wallet.solana:connect': CreateMethodPayload<WithReqId<Empty>>;
|
|
606
|
+
/**
|
|
607
|
+
* Disconnect from Solana wallet.
|
|
608
|
+
* Fire-and-forget — no response expected.
|
|
609
|
+
* @since 1.0.0
|
|
610
|
+
* @schema
|
|
611
|
+
*/
|
|
612
|
+
'wallet.solana:disconnect': CreateMethodPayload<Empty>;
|
|
613
|
+
/**
|
|
614
|
+
* Request Solana transaction signing.
|
|
615
|
+
* Returns the signed transaction bytes.
|
|
616
|
+
* @since 1.0.0
|
|
617
|
+
* @schema
|
|
618
|
+
*/
|
|
619
|
+
'wallet.solana:sign.transaction': CreateMethodPayload<WithReqId<{
|
|
620
|
+
/** Base64-encoded serialized transaction (legacy or versioned) */
|
|
621
|
+
transaction: string;
|
|
622
|
+
}>>;
|
|
623
|
+
/**
|
|
624
|
+
* Request Solana message signing.
|
|
625
|
+
* Returns the Ed25519 signature.
|
|
626
|
+
* @since 1.0.0
|
|
627
|
+
* @schema
|
|
628
|
+
*/
|
|
629
|
+
'wallet.solana:sign.message': CreateMethodPayload<WithReqId<{
|
|
630
|
+
/** Base58-encoded message bytes */
|
|
631
|
+
message: string;
|
|
632
|
+
}>>;
|
|
633
|
+
/**
|
|
634
|
+
* Request Solana transaction signing and sending.
|
|
635
|
+
* The host app signs and broadcasts the transaction.
|
|
636
|
+
* Returns the transaction signature.
|
|
637
|
+
* @since 1.0.0
|
|
638
|
+
* @schema
|
|
639
|
+
*/
|
|
640
|
+
'wallet.solana:sign.send': CreateMethodPayload<WithReqId<{
|
|
641
|
+
/** Base64-encoded serialized transaction (legacy or versioned) */
|
|
642
|
+
transaction: string;
|
|
643
|
+
/**
|
|
644
|
+
* Target Solana cluster for broadcasting.
|
|
645
|
+
* In bridge mode the host app can infer this from miniapp config,
|
|
646
|
+
* but in relay mode (QR/WebSocket) this is required so the host
|
|
647
|
+
* app knows which RPC to broadcast to.
|
|
648
|
+
* @since 1.0.0
|
|
649
|
+
* @schema
|
|
650
|
+
*/
|
|
651
|
+
chain?: SolanaChain;
|
|
652
|
+
/** Optional send options */
|
|
653
|
+
options?: {
|
|
654
|
+
skipPreflight?: boolean;
|
|
655
|
+
preflightCommitment?: SolanaCommitment;
|
|
656
|
+
/** Desired commitment level for transaction confirmation. */
|
|
657
|
+
commitment?: SolanaCommitment;
|
|
658
|
+
/**
|
|
659
|
+
* The minimum slot that the request can be evaluated at.
|
|
660
|
+
* Ensures the read is not served by a node lagging behind.
|
|
661
|
+
*/
|
|
662
|
+
minContextSlot?: number;
|
|
663
|
+
maxRetries?: number;
|
|
664
|
+
};
|
|
665
|
+
}>>;
|
|
484
666
|
}
|
|
485
667
|
//#endregion
|
|
486
668
|
//#region src/methods/types/method-types.d.ts
|
|
@@ -535,4 +717,4 @@ declare function isMethodSupported(method: MethodName, version: Version): boolea
|
|
|
535
717
|
*/
|
|
536
718
|
declare function getMethodMinVersion(method: MethodName): Version | undefined;
|
|
537
719
|
//#endregion
|
|
538
|
-
export { type CreateEventPayload, type CreateMethodPayload, type EventName, type EventPayload, type Events, type HapticImpactStyle, type HapticNotificationType, type LaunchParams, type MethodName, type MethodNameWithVersionedPayload, type MethodPayload, type MethodVersionedPayload, type Methods, PLATFORMS, type PaymentErrorCode, type PaymentTestScenario, type PaymentWebhookStatus, type Platform, type SafeAreaInsets, type Version, getMethodMinVersion, getReleaseVersion, isMethodSupported, releases };
|
|
720
|
+
export { type CreateEventPayload, type CreateMethodPayload, type EventName, type EventPayload, type Events, type HapticImpactStyle, type HapticNotificationType, type LaunchParams, type MethodName, type MethodNameWithVersionedPayload, type MethodPayload, type MethodVersionedPayload, type Methods, PLATFORMS, type PaymentErrorCode, type PaymentTestScenario, type PaymentWebhookStatus, type Platform, type SafeAreaInsets, type SolanaChain, type SolanaCommitment, type Version, WALLET_ERROR, type WalletSolanaErrorCode, getMethodMinVersion, getReleaseVersion, isMethodSupported, releases };
|
package/dist/index.d.mts
CHANGED
|
@@ -102,6 +102,62 @@ type HapticImpactStyle = 'light' | 'medium' | 'heavy' | 'soft' | 'rigid';
|
|
|
102
102
|
* @schema
|
|
103
103
|
*/
|
|
104
104
|
type HapticNotificationType = 'success' | 'warning' | 'error';
|
|
105
|
+
/**
|
|
106
|
+
* Solana wallet error codes (WalletConnect-compatible numeric codes).
|
|
107
|
+
*
|
|
108
|
+
* These codes are identical to WalletConnect JSON-RPC error codes,
|
|
109
|
+
* so the mobile app produces the same `(code, message)` pair for
|
|
110
|
+
* both bridge and relay transports — no mapping needed.
|
|
111
|
+
*
|
|
112
|
+
* | Code | Meaning | WC Name |
|
|
113
|
+
* |------|---------|---------|
|
|
114
|
+
* | `5000` | User rejected the request | `userRejected` |
|
|
115
|
+
* | `-32602` | Invalid params (malformed transaction, bad input) | JSON-RPC standard |
|
|
116
|
+
* | `-32603` | Internal error (send failed, unexpected error) | JSON-RPC standard |
|
|
117
|
+
* | `8000` | Request expired / timed out | `sessionRequestExpired` |
|
|
118
|
+
*
|
|
119
|
+
* @since 1.0.0
|
|
120
|
+
* @schema
|
|
121
|
+
*/
|
|
122
|
+
type WalletSolanaErrorCode = 5000 | -32602 | -32603 | 8000;
|
|
123
|
+
/**
|
|
124
|
+
* Named constants for {@link WalletSolanaErrorCode}.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { WALLET_ERROR } from '@alien_org/contract';
|
|
129
|
+
*
|
|
130
|
+
* if (response.errorCode === WALLET_ERROR.USER_REJECTED) {
|
|
131
|
+
* // user cancelled
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* @since 1.0.0
|
|
136
|
+
*/
|
|
137
|
+
declare const WALLET_ERROR: {
|
|
138
|
+
/** User rejected the request (cancelled approval screen). */
|
|
139
|
+
readonly USER_REJECTED: 5000;
|
|
140
|
+
/** Invalid params — transaction deserialization failed, malformed input. */
|
|
141
|
+
readonly INVALID_PARAMS: -32602;
|
|
142
|
+
/** Internal error — transaction broadcast failed, unexpected error. */
|
|
143
|
+
readonly INTERNAL_ERROR: -32603;
|
|
144
|
+
/** Request expired before the user responded. */
|
|
145
|
+
readonly REQUEST_EXPIRED: 8000;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Solana commitment levels for send options.
|
|
149
|
+
* @since 1.0.0
|
|
150
|
+
* @schema
|
|
151
|
+
*/
|
|
152
|
+
type SolanaCommitment = 'processed' | 'confirmed' | 'finalized';
|
|
153
|
+
/**
|
|
154
|
+
* Solana chain identifiers (wallet-standard format).
|
|
155
|
+
* Used by `wallet.solana:sign.send` to tell the host app
|
|
156
|
+
* which cluster to broadcast to.
|
|
157
|
+
* @since 1.0.0
|
|
158
|
+
* @schema
|
|
159
|
+
*/
|
|
160
|
+
type SolanaChain = 'solana:mainnet' | 'solana:devnet' | 'solana:testnet';
|
|
105
161
|
//#endregion
|
|
106
162
|
//#region src/events/types/payload.d.ts
|
|
107
163
|
/**
|
|
@@ -126,7 +182,7 @@ interface Events {
|
|
|
126
182
|
'miniapp:close': CreateEventPayload<Empty>;
|
|
127
183
|
/**
|
|
128
184
|
* Host app's back button clicked event.
|
|
129
|
-
* @since 0.0
|
|
185
|
+
* @since 1.0.0
|
|
130
186
|
* @schema
|
|
131
187
|
*/
|
|
132
188
|
'host.back.button:clicked': CreateEventPayload<Empty>;
|
|
@@ -195,6 +251,60 @@ interface Events {
|
|
|
195
251
|
*/
|
|
196
252
|
errorCode?: 'permission_denied' | 'unavailable';
|
|
197
253
|
}>>;
|
|
254
|
+
/**
|
|
255
|
+
* Solana wallet connection response.
|
|
256
|
+
* @since 1.0.0
|
|
257
|
+
* @schema
|
|
258
|
+
*/
|
|
259
|
+
'wallet.solana:connect.response': CreateEventPayload<WithReqId<{
|
|
260
|
+
/** Base58-encoded public key of the connected wallet */
|
|
261
|
+
publicKey?: string;
|
|
262
|
+
/** Numeric error code (WalletConnect-compatible). See {@link WalletSolanaErrorCode}. */
|
|
263
|
+
errorCode?: WalletSolanaErrorCode;
|
|
264
|
+
/** Human-readable error description */
|
|
265
|
+
errorMessage?: string;
|
|
266
|
+
}>>;
|
|
267
|
+
/**
|
|
268
|
+
* Solana transaction signing response.
|
|
269
|
+
* @since 1.0.0
|
|
270
|
+
* @schema
|
|
271
|
+
*/
|
|
272
|
+
'wallet.solana:sign.transaction.response': CreateEventPayload<WithReqId<{
|
|
273
|
+
/** Base64-encoded signed transaction */
|
|
274
|
+
signedTransaction?: string;
|
|
275
|
+
/** Numeric error code (WalletConnect-compatible). See {@link WalletSolanaErrorCode}. */
|
|
276
|
+
errorCode?: WalletSolanaErrorCode;
|
|
277
|
+
/** Human-readable error description */
|
|
278
|
+
errorMessage?: string;
|
|
279
|
+
}>>;
|
|
280
|
+
/**
|
|
281
|
+
* Solana message signing response.
|
|
282
|
+
* @since 1.0.0
|
|
283
|
+
* @schema
|
|
284
|
+
*/
|
|
285
|
+
'wallet.solana:sign.message.response': CreateEventPayload<WithReqId<{
|
|
286
|
+
/** Base58-encoded Ed25519 signature (64 bytes) */
|
|
287
|
+
signature?: string;
|
|
288
|
+
/** Base58-encoded public key that signed the message */
|
|
289
|
+
publicKey?: string;
|
|
290
|
+
/** Numeric error code (WalletConnect-compatible). See {@link WalletSolanaErrorCode}. */
|
|
291
|
+
errorCode?: WalletSolanaErrorCode;
|
|
292
|
+
/** Human-readable error description */
|
|
293
|
+
errorMessage?: string;
|
|
294
|
+
}>>;
|
|
295
|
+
/**
|
|
296
|
+
* Solana sign-and-send transaction response.
|
|
297
|
+
* @since 1.0.0
|
|
298
|
+
* @schema
|
|
299
|
+
*/
|
|
300
|
+
'wallet.solana:sign.send.response': CreateEventPayload<WithReqId<{
|
|
301
|
+
/** Base58-encoded transaction signature */
|
|
302
|
+
signature?: string;
|
|
303
|
+
/** Numeric error code (WalletConnect-compatible). See {@link WalletSolanaErrorCode}. */
|
|
304
|
+
errorCode?: WalletSolanaErrorCode;
|
|
305
|
+
/** Human-readable error description */
|
|
306
|
+
errorMessage?: string;
|
|
307
|
+
}>>;
|
|
198
308
|
}
|
|
199
309
|
//#endregion
|
|
200
310
|
//#region src/events/types/event-types.d.ts
|
|
@@ -239,6 +349,11 @@ interface LaunchParams {
|
|
|
239
349
|
* Used for referral codes, campaign tracking, or custom routing.
|
|
240
350
|
*/
|
|
241
351
|
startParam: string | undefined;
|
|
352
|
+
/**
|
|
353
|
+
* Whether the miniapp was launched in fullscreen mode.
|
|
354
|
+
* @since 1.0.0
|
|
355
|
+
*/
|
|
356
|
+
isFullscreen: boolean | undefined;
|
|
242
357
|
}
|
|
243
358
|
//#endregion
|
|
244
359
|
//#region src/methods/types/payload.d.ts
|
|
@@ -259,27 +374,27 @@ interface Methods {
|
|
|
259
374
|
/**
|
|
260
375
|
* Miniapp ready method.
|
|
261
376
|
* Sent by the miniapp to notify the host app that it has loaded and is ready to be displayed.
|
|
262
|
-
* @since 0.0.
|
|
377
|
+
* @since 0.0.9
|
|
263
378
|
* @schema
|
|
264
379
|
*/
|
|
265
380
|
'app:ready': CreateMethodPayload<Empty>;
|
|
266
381
|
/**
|
|
267
|
-
*
|
|
268
|
-
* Sent by the miniapp to
|
|
269
|
-
*
|
|
270
|
-
* @since 0.0
|
|
382
|
+
* Close the miniapp.
|
|
383
|
+
* Sent by the miniapp to request the host app to close it.
|
|
384
|
+
* Fire-and-forget — no response expected.
|
|
385
|
+
* @since 1.0.0
|
|
271
386
|
* @schema
|
|
272
387
|
*/
|
|
273
|
-
'
|
|
388
|
+
'app:close': CreateMethodPayload<Empty>;
|
|
274
389
|
/**
|
|
275
390
|
* Toggle host app's back button visibility.
|
|
276
|
-
* @since 0.0
|
|
391
|
+
* @since 1.0.0
|
|
277
392
|
* @schema
|
|
278
393
|
*/
|
|
279
394
|
'host.back.button:toggle': CreateMethodPayload<{
|
|
280
395
|
/**
|
|
281
396
|
* Whether to show or hide the back button.
|
|
282
|
-
* @since 0.0
|
|
397
|
+
* @since 1.0.0
|
|
283
398
|
* @schema
|
|
284
399
|
*/
|
|
285
400
|
visible: boolean;
|
|
@@ -291,8 +406,8 @@ interface Methods {
|
|
|
291
406
|
* Your backend receives a webhook when user pays - fulfill the order
|
|
292
407
|
* immediately without waiting for chain confirmation.
|
|
293
408
|
*
|
|
294
|
-
* Optional
|
|
295
|
-
*
|
|
409
|
+
* Optional `item` object (`title`, `iconUrl`, `quantity`)
|
|
410
|
+
* is shown on the payment approval screen.
|
|
296
411
|
*
|
|
297
412
|
* Set `test` to a scenario string (e.g. `'paid'`, `'error:insufficient_balance'`)
|
|
298
413
|
* for test mode - no real payment is made, but the specified scenario is
|
|
@@ -481,6 +596,73 @@ interface Methods {
|
|
|
481
596
|
* @schema
|
|
482
597
|
*/
|
|
483
598
|
'haptic:selection': CreateMethodPayload<Empty>;
|
|
599
|
+
/**
|
|
600
|
+
* Request Solana wallet connection.
|
|
601
|
+
* Returns the wallet's public key on success.
|
|
602
|
+
* @since 1.0.0
|
|
603
|
+
* @schema
|
|
604
|
+
*/
|
|
605
|
+
'wallet.solana:connect': CreateMethodPayload<WithReqId<Empty>>;
|
|
606
|
+
/**
|
|
607
|
+
* Disconnect from Solana wallet.
|
|
608
|
+
* Fire-and-forget — no response expected.
|
|
609
|
+
* @since 1.0.0
|
|
610
|
+
* @schema
|
|
611
|
+
*/
|
|
612
|
+
'wallet.solana:disconnect': CreateMethodPayload<Empty>;
|
|
613
|
+
/**
|
|
614
|
+
* Request Solana transaction signing.
|
|
615
|
+
* Returns the signed transaction bytes.
|
|
616
|
+
* @since 1.0.0
|
|
617
|
+
* @schema
|
|
618
|
+
*/
|
|
619
|
+
'wallet.solana:sign.transaction': CreateMethodPayload<WithReqId<{
|
|
620
|
+
/** Base64-encoded serialized transaction (legacy or versioned) */
|
|
621
|
+
transaction: string;
|
|
622
|
+
}>>;
|
|
623
|
+
/**
|
|
624
|
+
* Request Solana message signing.
|
|
625
|
+
* Returns the Ed25519 signature.
|
|
626
|
+
* @since 1.0.0
|
|
627
|
+
* @schema
|
|
628
|
+
*/
|
|
629
|
+
'wallet.solana:sign.message': CreateMethodPayload<WithReqId<{
|
|
630
|
+
/** Base58-encoded message bytes */
|
|
631
|
+
message: string;
|
|
632
|
+
}>>;
|
|
633
|
+
/**
|
|
634
|
+
* Request Solana transaction signing and sending.
|
|
635
|
+
* The host app signs and broadcasts the transaction.
|
|
636
|
+
* Returns the transaction signature.
|
|
637
|
+
* @since 1.0.0
|
|
638
|
+
* @schema
|
|
639
|
+
*/
|
|
640
|
+
'wallet.solana:sign.send': CreateMethodPayload<WithReqId<{
|
|
641
|
+
/** Base64-encoded serialized transaction (legacy or versioned) */
|
|
642
|
+
transaction: string;
|
|
643
|
+
/**
|
|
644
|
+
* Target Solana cluster for broadcasting.
|
|
645
|
+
* In bridge mode the host app can infer this from miniapp config,
|
|
646
|
+
* but in relay mode (QR/WebSocket) this is required so the host
|
|
647
|
+
* app knows which RPC to broadcast to.
|
|
648
|
+
* @since 1.0.0
|
|
649
|
+
* @schema
|
|
650
|
+
*/
|
|
651
|
+
chain?: SolanaChain;
|
|
652
|
+
/** Optional send options */
|
|
653
|
+
options?: {
|
|
654
|
+
skipPreflight?: boolean;
|
|
655
|
+
preflightCommitment?: SolanaCommitment;
|
|
656
|
+
/** Desired commitment level for transaction confirmation. */
|
|
657
|
+
commitment?: SolanaCommitment;
|
|
658
|
+
/**
|
|
659
|
+
* The minimum slot that the request can be evaluated at.
|
|
660
|
+
* Ensures the read is not served by a node lagging behind.
|
|
661
|
+
*/
|
|
662
|
+
minContextSlot?: number;
|
|
663
|
+
maxRetries?: number;
|
|
664
|
+
};
|
|
665
|
+
}>>;
|
|
484
666
|
}
|
|
485
667
|
//#endregion
|
|
486
668
|
//#region src/methods/types/method-types.d.ts
|
|
@@ -535,4 +717,4 @@ declare function isMethodSupported(method: MethodName, version: Version): boolea
|
|
|
535
717
|
*/
|
|
536
718
|
declare function getMethodMinVersion(method: MethodName): Version | undefined;
|
|
537
719
|
//#endregion
|
|
538
|
-
export { type CreateEventPayload, type CreateMethodPayload, type EventName, type EventPayload, type Events, type HapticImpactStyle, type HapticNotificationType, type LaunchParams, type MethodName, type MethodNameWithVersionedPayload, type MethodPayload, type MethodVersionedPayload, type Methods, PLATFORMS, type PaymentErrorCode, type PaymentTestScenario, type PaymentWebhookStatus, type Platform, type SafeAreaInsets, type Version, getMethodMinVersion, getReleaseVersion, isMethodSupported, releases };
|
|
720
|
+
export { type CreateEventPayload, type CreateMethodPayload, type EventName, type EventPayload, type Events, type HapticImpactStyle, type HapticNotificationType, type LaunchParams, type MethodName, type MethodNameWithVersionedPayload, type MethodPayload, type MethodVersionedPayload, type Methods, PLATFORMS, type PaymentErrorCode, type PaymentTestScenario, type PaymentWebhookStatus, type Platform, type SafeAreaInsets, type SolanaChain, type SolanaCommitment, type Version, WALLET_ERROR, type WalletSolanaErrorCode, getMethodMinVersion, getReleaseVersion, isMethodSupported, releases };
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,6 @@ const PLATFORMS = ["ios", "android"];
|
|
|
8
8
|
//#region src/methods/versions/releases.ts
|
|
9
9
|
const releases = {
|
|
10
10
|
"0.0.9": ["app:ready"],
|
|
11
|
-
"0.0.14": ["miniapp:close.ack", "host.back.button:toggle"],
|
|
12
11
|
"0.1.1": [
|
|
13
12
|
"payment:request",
|
|
14
13
|
"clipboard:write",
|
|
@@ -19,6 +18,15 @@ const releases = {
|
|
|
19
18
|
"haptic:impact",
|
|
20
19
|
"haptic:notification",
|
|
21
20
|
"haptic:selection"
|
|
21
|
+
],
|
|
22
|
+
"1.0.0": [
|
|
23
|
+
"wallet.solana:connect",
|
|
24
|
+
"wallet.solana:disconnect",
|
|
25
|
+
"wallet.solana:sign.transaction",
|
|
26
|
+
"wallet.solana:sign.message",
|
|
27
|
+
"wallet.solana:sign.send",
|
|
28
|
+
"app:close",
|
|
29
|
+
"host.back.button:toggle"
|
|
22
30
|
]
|
|
23
31
|
};
|
|
24
32
|
|
|
@@ -83,4 +91,27 @@ function getMethodMinVersion(method) {
|
|
|
83
91
|
}
|
|
84
92
|
|
|
85
93
|
//#endregion
|
|
86
|
-
|
|
94
|
+
//#region src/utils.ts
|
|
95
|
+
/**
|
|
96
|
+
* Named constants for {@link WalletSolanaErrorCode}.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { WALLET_ERROR } from '@alien_org/contract';
|
|
101
|
+
*
|
|
102
|
+
* if (response.errorCode === WALLET_ERROR.USER_REJECTED) {
|
|
103
|
+
* // user cancelled
|
|
104
|
+
* }
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @since 1.0.0
|
|
108
|
+
*/
|
|
109
|
+
const WALLET_ERROR = {
|
|
110
|
+
USER_REJECTED: 5e3,
|
|
111
|
+
INVALID_PARAMS: -32602,
|
|
112
|
+
INTERNAL_ERROR: -32603,
|
|
113
|
+
REQUEST_EXPIRED: 8e3
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
export { PLATFORMS, WALLET_ERROR, getMethodMinVersion, getReleaseVersion, isMethodSupported, releases };
|