@worldcoin/minikit-js 1.0.0 → 1.1.0
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 +22 -2
- package/build/index.cjs +114 -1
- package/build/index.d.cts +35 -2
- package/build/index.d.ts +35 -2
- package/build/index.js +114 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
# Minikit-JS
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## 🚀 Getting Started
|
|
4
|
+
|
|
5
|
+
Minikit is currently available on npm. To install, run:
|
|
6
|
+
`pnpm i @worldcoin/minikit-js`
|
|
7
|
+
|
|
8
|
+
or use the CDN:
|
|
9
|
+
`https://cdn.jsdelivr.net/npm/@worldcoin/minikit-js@[version]/+esm`
|
|
10
|
+
|
|
11
|
+
For comprehensive setup instructions and usage examples, visit our [developer documentation](https://docs.world.org/mini-apps).
|
|
12
|
+
|
|
13
|
+
## 🛠 ️Developing Locally
|
|
14
|
+
|
|
15
|
+
To run the example mini app locally:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
pnpm i
|
|
19
|
+
cd demo/with-next
|
|
20
|
+
pnpm dev
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This will launch a demo mini app with all essential commands implemented, allowing you to explore and test the features.
|
package/build/index.cjs
CHANGED
|
@@ -477,6 +477,17 @@ var _MiniKit = class _MiniKit {
|
|
|
477
477
|
}
|
|
478
478
|
this.listeners[event](payload);
|
|
479
479
|
}
|
|
480
|
+
static async awaitCommand(event, command, executor) {
|
|
481
|
+
return new Promise((resolve) => {
|
|
482
|
+
let commandPayload = null;
|
|
483
|
+
const handleAndUnsubscribe = (payload) => {
|
|
484
|
+
this.unsubscribe(event);
|
|
485
|
+
resolve({ commandPayload, finalPayload: payload });
|
|
486
|
+
};
|
|
487
|
+
this.subscribe(event, handleAndUnsubscribe);
|
|
488
|
+
commandPayload = executor();
|
|
489
|
+
});
|
|
490
|
+
}
|
|
480
491
|
static commandsValid(input) {
|
|
481
492
|
return Object.entries(this.commandVersion).every(
|
|
482
493
|
([commandName, version]) => {
|
|
@@ -494,7 +505,7 @@ var _MiniKit = class _MiniKit {
|
|
|
494
505
|
}
|
|
495
506
|
);
|
|
496
507
|
}
|
|
497
|
-
static install() {
|
|
508
|
+
static install(appId) {
|
|
498
509
|
if (typeof window === "undefined" || Boolean(window.MiniKit)) {
|
|
499
510
|
return {
|
|
500
511
|
success: false,
|
|
@@ -502,6 +513,11 @@ var _MiniKit = class _MiniKit {
|
|
|
502
513
|
errorMessage: MiniKitInstallErrorMessage["already_installed" /* AlreadyInstalled */]
|
|
503
514
|
};
|
|
504
515
|
}
|
|
516
|
+
if (!appId) {
|
|
517
|
+
console.warn("App ID not provided during install");
|
|
518
|
+
} else {
|
|
519
|
+
_MiniKit.appId = appId;
|
|
520
|
+
}
|
|
505
521
|
if (!window.WorldApp) {
|
|
506
522
|
return {
|
|
507
523
|
success: false,
|
|
@@ -573,6 +589,7 @@ _MiniKit.listeners = {
|
|
|
573
589
|
["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
|
|
574
590
|
}
|
|
575
591
|
};
|
|
592
|
+
_MiniKit.appId = null;
|
|
576
593
|
_MiniKit.walletAddress = null;
|
|
577
594
|
_MiniKit.commands = {
|
|
578
595
|
verify: (payload) => {
|
|
@@ -705,6 +722,102 @@ _MiniKit.commands = {
|
|
|
705
722
|
return payload;
|
|
706
723
|
}
|
|
707
724
|
};
|
|
725
|
+
/**
|
|
726
|
+
* This object contains async versions of all the commands.
|
|
727
|
+
* Instead of using event listeners, you can just `await` these.
|
|
728
|
+
*
|
|
729
|
+
* They return a standardized object
|
|
730
|
+
*
|
|
731
|
+
* commandPayload - object returned by the command function
|
|
732
|
+
*
|
|
733
|
+
* finalPayload - object returned by the event listener, or in other words, WorldApp response
|
|
734
|
+
*/
|
|
735
|
+
_MiniKit.commandsAsync = {
|
|
736
|
+
verify: async (payload) => {
|
|
737
|
+
return new Promise(async (resolve, reject) => {
|
|
738
|
+
try {
|
|
739
|
+
const response = await _MiniKit.awaitCommand(
|
|
740
|
+
"miniapp-verify-action" /* MiniAppVerifyAction */,
|
|
741
|
+
"verify" /* Verify */,
|
|
742
|
+
() => _MiniKit.commands.verify(payload)
|
|
743
|
+
);
|
|
744
|
+
resolve(response);
|
|
745
|
+
} catch (error) {
|
|
746
|
+
reject(error);
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
},
|
|
750
|
+
pay: async (payload) => {
|
|
751
|
+
return new Promise(async (resolve, reject) => {
|
|
752
|
+
try {
|
|
753
|
+
const response = await _MiniKit.awaitCommand(
|
|
754
|
+
"miniapp-payment" /* MiniAppPayment */,
|
|
755
|
+
"pay" /* Pay */,
|
|
756
|
+
() => _MiniKit.commands.pay(payload)
|
|
757
|
+
);
|
|
758
|
+
resolve(response);
|
|
759
|
+
} catch (error) {
|
|
760
|
+
reject(error);
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
},
|
|
764
|
+
walletAuth: async (payload) => {
|
|
765
|
+
return new Promise(async (resolve, reject) => {
|
|
766
|
+
try {
|
|
767
|
+
const response = await _MiniKit.awaitCommand(
|
|
768
|
+
"miniapp-wallet-auth" /* MiniAppWalletAuth */,
|
|
769
|
+
"wallet-auth" /* WalletAuth */,
|
|
770
|
+
() => _MiniKit.commands.walletAuth(payload)
|
|
771
|
+
);
|
|
772
|
+
return resolve(response);
|
|
773
|
+
} catch (error) {
|
|
774
|
+
reject(error);
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
},
|
|
778
|
+
sendTransaction: async (payload) => {
|
|
779
|
+
return new Promise(async (resolve, reject) => {
|
|
780
|
+
try {
|
|
781
|
+
const response = await _MiniKit.awaitCommand(
|
|
782
|
+
"miniapp-send-transaction" /* MiniAppSendTransaction */,
|
|
783
|
+
"send-transaction" /* SendTransaction */,
|
|
784
|
+
() => _MiniKit.commands.sendTransaction(payload)
|
|
785
|
+
);
|
|
786
|
+
return resolve(response);
|
|
787
|
+
} catch (error) {
|
|
788
|
+
reject(error);
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
},
|
|
792
|
+
signMessage: async (payload) => {
|
|
793
|
+
return new Promise(async (resolve, reject) => {
|
|
794
|
+
try {
|
|
795
|
+
const response = await _MiniKit.awaitCommand(
|
|
796
|
+
"miniapp-sign-message" /* MiniAppSignMessage */,
|
|
797
|
+
"sign-message" /* SignMessage */,
|
|
798
|
+
() => _MiniKit.commands.signMessage(payload)
|
|
799
|
+
);
|
|
800
|
+
return resolve(response);
|
|
801
|
+
} catch (error) {
|
|
802
|
+
reject(error);
|
|
803
|
+
}
|
|
804
|
+
});
|
|
805
|
+
},
|
|
806
|
+
signTypedData: async (payload) => {
|
|
807
|
+
return new Promise(async (resolve, reject) => {
|
|
808
|
+
try {
|
|
809
|
+
const response = await _MiniKit.awaitCommand(
|
|
810
|
+
"miniapp-sign-typed-data" /* MiniAppSignTypedData */,
|
|
811
|
+
"sign-typed-data" /* SignTypedData */,
|
|
812
|
+
() => _MiniKit.commands.signTypedData(payload)
|
|
813
|
+
);
|
|
814
|
+
return resolve(response);
|
|
815
|
+
} catch (error) {
|
|
816
|
+
reject(error);
|
|
817
|
+
}
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
};
|
|
708
821
|
var MiniKit = _MiniKit;
|
|
709
822
|
|
|
710
823
|
// index.ts
|
package/build/index.d.cts
CHANGED
|
@@ -142,6 +142,10 @@ type WebViewBasePayload = {
|
|
|
142
142
|
version: number;
|
|
143
143
|
payload: Record<string, any>;
|
|
144
144
|
};
|
|
145
|
+
type AsyncHandlerReturn<CommandPayload, FinalPayload> = Promise<{
|
|
146
|
+
commandPayload: CommandPayload;
|
|
147
|
+
finalPayload: FinalPayload;
|
|
148
|
+
}>;
|
|
145
149
|
type VerifyCommandInput = {
|
|
146
150
|
action: IDKitConfig["action"];
|
|
147
151
|
signal?: IDKitConfig["signal"];
|
|
@@ -195,6 +199,15 @@ type SignTypedDataInput = {
|
|
|
195
199
|
domain?: TypedDataDomain;
|
|
196
200
|
};
|
|
197
201
|
type SignTypedDataPayload = SignTypedDataInput;
|
|
202
|
+
type CommandReturnPayloadMap = {
|
|
203
|
+
[Command.Verify]: VerifyCommandPayload;
|
|
204
|
+
[Command.Pay]: PayCommandPayload;
|
|
205
|
+
[Command.WalletAuth]: WalletAuthPayload;
|
|
206
|
+
[Command.SendTransaction]: SendTransactionPayload;
|
|
207
|
+
[Command.SignMessage]: SignMessagePayload;
|
|
208
|
+
[Command.SignTypedData]: SignTypedDataPayload;
|
|
209
|
+
};
|
|
210
|
+
type CommandReturnPayload<T extends Command> = T extends keyof CommandReturnPayloadMap ? CommandReturnPayloadMap[T] : never;
|
|
198
211
|
|
|
199
212
|
declare enum ResponseEvent {
|
|
200
213
|
MiniAppVerifyAction = "miniapp-verify-action",
|
|
@@ -322,13 +335,15 @@ declare class MiniKit {
|
|
|
322
335
|
private static readonly commandVersion;
|
|
323
336
|
private static isCommandAvailable;
|
|
324
337
|
private static listeners;
|
|
338
|
+
static appId: string | null;
|
|
325
339
|
static walletAddress: string | null;
|
|
326
340
|
private static sendInit;
|
|
327
341
|
static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
|
|
328
342
|
static unsubscribe(event: ResponseEvent): void;
|
|
329
343
|
static trigger(event: ResponseEvent, payload: EventPayload): void;
|
|
344
|
+
private static awaitCommand;
|
|
330
345
|
private static commandsValid;
|
|
331
|
-
static install(): MiniKitInstallReturnType;
|
|
346
|
+
static install(appId?: string): MiniKitInstallReturnType;
|
|
332
347
|
static isInstalled(debug?: boolean): boolean;
|
|
333
348
|
static commands: {
|
|
334
349
|
verify: (payload: VerifyCommandInput) => VerifyCommandPayload | null;
|
|
@@ -338,6 +353,24 @@ declare class MiniKit {
|
|
|
338
353
|
signMessage: (payload: SignMessageInput) => SignMessagePayload | null;
|
|
339
354
|
signTypedData: (payload: SignTypedDataInput) => SignTypedDataPayload | null;
|
|
340
355
|
};
|
|
356
|
+
/**
|
|
357
|
+
* This object contains async versions of all the commands.
|
|
358
|
+
* Instead of using event listeners, you can just `await` these.
|
|
359
|
+
*
|
|
360
|
+
* They return a standardized object
|
|
361
|
+
*
|
|
362
|
+
* commandPayload - object returned by the command function
|
|
363
|
+
*
|
|
364
|
+
* finalPayload - object returned by the event listener, or in other words, WorldApp response
|
|
365
|
+
*/
|
|
366
|
+
static commandsAsync: {
|
|
367
|
+
verify: (payload: VerifyCommandInput) => AsyncHandlerReturn<VerifyCommandPayload | null, MiniAppVerifyActionPayload>;
|
|
368
|
+
pay: (payload: PayCommandInput) => AsyncHandlerReturn<PayCommandPayload | null, MiniAppPaymentPayload>;
|
|
369
|
+
walletAuth: (payload: WalletAuthInput) => AsyncHandlerReturn<WalletAuthPayload | null, MiniAppWalletAuthPayload>;
|
|
370
|
+
sendTransaction: (payload: SendTransactionInput) => AsyncHandlerReturn<SendTransactionPayload | null, MiniAppSendTransactionPayload>;
|
|
371
|
+
signMessage: (payload: SignMessageInput) => AsyncHandlerReturn<SignMessagePayload | null, MiniAppSignMessagePayload>;
|
|
372
|
+
signTypedData: (payload: SignTypedDataInput) => AsyncHandlerReturn<SignTypedDataPayload | null, MiniAppSignTypedDataPayload>;
|
|
373
|
+
};
|
|
341
374
|
}
|
|
342
375
|
|
|
343
376
|
declare const tokenToDecimals: (amount: number, token: Tokens) => number;
|
|
@@ -358,4 +391,4 @@ declare const verifySiweMessage: (payload: MiniAppWalletAuthSuccessPayload, nonc
|
|
|
358
391
|
siweMessageData: SiweMessage;
|
|
359
392
|
}>;
|
|
360
393
|
|
|
361
|
-
export { Command, type EventHandler, type EventPayload, type MiniAppPaymentErrorPayload, type MiniAppPaymentPayload, type MiniAppPaymentSuccessPayload, type MiniAppSendTransactionErrorPayload, type MiniAppSendTransactionPayload, type MiniAppSendTransactionSuccessPayload, type MiniAppSignMessageErrorPayload, type MiniAppSignMessagePayload, type MiniAppSignMessageSuccessPayload, type MiniAppSignTypedDataErrorPayload, type MiniAppSignTypedDataPayload, type MiniAppSignTypedDataSuccessPayload, type MiniAppVerifyActionErrorPayload, type MiniAppVerifyActionPayload, type MiniAppVerifyActionSuccessPayload, type MiniAppWalletAuthErrorPayload, type MiniAppWalletAuthPayload, type MiniAppWalletAuthSuccessPayload, MiniKit, MiniKitInstallErrorCodes, MiniKitInstallErrorMessage, type MiniKitInstallReturnType, Network, type PayCommandInput, type PayCommandPayload, PaymentErrorCodes, PaymentErrorMessage, PaymentValidationErrors, ResponseEvent, SAFE_CONTRACT_ABI, SendTransactionErrorCodes, SendTransactionErrorMessage, type SendTransactionInput, type SendTransactionPayload, SignMessageErrorCodes, SignMessageErrorMessage, type SignMessageInput, type SignMessagePayload, SignTypedDataErrorCodes, SignTypedDataErrorMessage, type SignTypedDataInput, type SignTypedDataPayload, type SiweMessage, TokenDecimals, Tokens, type TokensPayload, VerificationErrorMessage, type VerifyCommandInput, type VerifyCommandPayload, WalletAuthErrorCodes, WalletAuthErrorMessage, type WalletAuthInput, type WalletAuthPayload, type WebViewBasePayload, parseSiweMessage, tokenToDecimals, verifySiweMessage };
|
|
394
|
+
export { type AsyncHandlerReturn, Command, type CommandReturnPayload, type EventHandler, type EventPayload, type MiniAppPaymentErrorPayload, type MiniAppPaymentPayload, type MiniAppPaymentSuccessPayload, type MiniAppSendTransactionErrorPayload, type MiniAppSendTransactionPayload, type MiniAppSendTransactionSuccessPayload, type MiniAppSignMessageErrorPayload, type MiniAppSignMessagePayload, type MiniAppSignMessageSuccessPayload, type MiniAppSignTypedDataErrorPayload, type MiniAppSignTypedDataPayload, type MiniAppSignTypedDataSuccessPayload, type MiniAppVerifyActionErrorPayload, type MiniAppVerifyActionPayload, type MiniAppVerifyActionSuccessPayload, type MiniAppWalletAuthErrorPayload, type MiniAppWalletAuthPayload, type MiniAppWalletAuthSuccessPayload, MiniKit, MiniKitInstallErrorCodes, MiniKitInstallErrorMessage, type MiniKitInstallReturnType, Network, type PayCommandInput, type PayCommandPayload, PaymentErrorCodes, PaymentErrorMessage, PaymentValidationErrors, ResponseEvent, SAFE_CONTRACT_ABI, SendTransactionErrorCodes, SendTransactionErrorMessage, type SendTransactionInput, type SendTransactionPayload, SignMessageErrorCodes, SignMessageErrorMessage, type SignMessageInput, type SignMessagePayload, SignTypedDataErrorCodes, SignTypedDataErrorMessage, type SignTypedDataInput, type SignTypedDataPayload, type SiweMessage, TokenDecimals, Tokens, type TokensPayload, VerificationErrorMessage, type VerifyCommandInput, type VerifyCommandPayload, WalletAuthErrorCodes, WalletAuthErrorMessage, type WalletAuthInput, type WalletAuthPayload, type WebViewBasePayload, parseSiweMessage, tokenToDecimals, verifySiweMessage };
|
package/build/index.d.ts
CHANGED
|
@@ -142,6 +142,10 @@ type WebViewBasePayload = {
|
|
|
142
142
|
version: number;
|
|
143
143
|
payload: Record<string, any>;
|
|
144
144
|
};
|
|
145
|
+
type AsyncHandlerReturn<CommandPayload, FinalPayload> = Promise<{
|
|
146
|
+
commandPayload: CommandPayload;
|
|
147
|
+
finalPayload: FinalPayload;
|
|
148
|
+
}>;
|
|
145
149
|
type VerifyCommandInput = {
|
|
146
150
|
action: IDKitConfig["action"];
|
|
147
151
|
signal?: IDKitConfig["signal"];
|
|
@@ -195,6 +199,15 @@ type SignTypedDataInput = {
|
|
|
195
199
|
domain?: TypedDataDomain;
|
|
196
200
|
};
|
|
197
201
|
type SignTypedDataPayload = SignTypedDataInput;
|
|
202
|
+
type CommandReturnPayloadMap = {
|
|
203
|
+
[Command.Verify]: VerifyCommandPayload;
|
|
204
|
+
[Command.Pay]: PayCommandPayload;
|
|
205
|
+
[Command.WalletAuth]: WalletAuthPayload;
|
|
206
|
+
[Command.SendTransaction]: SendTransactionPayload;
|
|
207
|
+
[Command.SignMessage]: SignMessagePayload;
|
|
208
|
+
[Command.SignTypedData]: SignTypedDataPayload;
|
|
209
|
+
};
|
|
210
|
+
type CommandReturnPayload<T extends Command> = T extends keyof CommandReturnPayloadMap ? CommandReturnPayloadMap[T] : never;
|
|
198
211
|
|
|
199
212
|
declare enum ResponseEvent {
|
|
200
213
|
MiniAppVerifyAction = "miniapp-verify-action",
|
|
@@ -322,13 +335,15 @@ declare class MiniKit {
|
|
|
322
335
|
private static readonly commandVersion;
|
|
323
336
|
private static isCommandAvailable;
|
|
324
337
|
private static listeners;
|
|
338
|
+
static appId: string | null;
|
|
325
339
|
static walletAddress: string | null;
|
|
326
340
|
private static sendInit;
|
|
327
341
|
static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
|
|
328
342
|
static unsubscribe(event: ResponseEvent): void;
|
|
329
343
|
static trigger(event: ResponseEvent, payload: EventPayload): void;
|
|
344
|
+
private static awaitCommand;
|
|
330
345
|
private static commandsValid;
|
|
331
|
-
static install(): MiniKitInstallReturnType;
|
|
346
|
+
static install(appId?: string): MiniKitInstallReturnType;
|
|
332
347
|
static isInstalled(debug?: boolean): boolean;
|
|
333
348
|
static commands: {
|
|
334
349
|
verify: (payload: VerifyCommandInput) => VerifyCommandPayload | null;
|
|
@@ -338,6 +353,24 @@ declare class MiniKit {
|
|
|
338
353
|
signMessage: (payload: SignMessageInput) => SignMessagePayload | null;
|
|
339
354
|
signTypedData: (payload: SignTypedDataInput) => SignTypedDataPayload | null;
|
|
340
355
|
};
|
|
356
|
+
/**
|
|
357
|
+
* This object contains async versions of all the commands.
|
|
358
|
+
* Instead of using event listeners, you can just `await` these.
|
|
359
|
+
*
|
|
360
|
+
* They return a standardized object
|
|
361
|
+
*
|
|
362
|
+
* commandPayload - object returned by the command function
|
|
363
|
+
*
|
|
364
|
+
* finalPayload - object returned by the event listener, or in other words, WorldApp response
|
|
365
|
+
*/
|
|
366
|
+
static commandsAsync: {
|
|
367
|
+
verify: (payload: VerifyCommandInput) => AsyncHandlerReturn<VerifyCommandPayload | null, MiniAppVerifyActionPayload>;
|
|
368
|
+
pay: (payload: PayCommandInput) => AsyncHandlerReturn<PayCommandPayload | null, MiniAppPaymentPayload>;
|
|
369
|
+
walletAuth: (payload: WalletAuthInput) => AsyncHandlerReturn<WalletAuthPayload | null, MiniAppWalletAuthPayload>;
|
|
370
|
+
sendTransaction: (payload: SendTransactionInput) => AsyncHandlerReturn<SendTransactionPayload | null, MiniAppSendTransactionPayload>;
|
|
371
|
+
signMessage: (payload: SignMessageInput) => AsyncHandlerReturn<SignMessagePayload | null, MiniAppSignMessagePayload>;
|
|
372
|
+
signTypedData: (payload: SignTypedDataInput) => AsyncHandlerReturn<SignTypedDataPayload | null, MiniAppSignTypedDataPayload>;
|
|
373
|
+
};
|
|
341
374
|
}
|
|
342
375
|
|
|
343
376
|
declare const tokenToDecimals: (amount: number, token: Tokens) => number;
|
|
@@ -358,4 +391,4 @@ declare const verifySiweMessage: (payload: MiniAppWalletAuthSuccessPayload, nonc
|
|
|
358
391
|
siweMessageData: SiweMessage;
|
|
359
392
|
}>;
|
|
360
393
|
|
|
361
|
-
export { Command, type EventHandler, type EventPayload, type MiniAppPaymentErrorPayload, type MiniAppPaymentPayload, type MiniAppPaymentSuccessPayload, type MiniAppSendTransactionErrorPayload, type MiniAppSendTransactionPayload, type MiniAppSendTransactionSuccessPayload, type MiniAppSignMessageErrorPayload, type MiniAppSignMessagePayload, type MiniAppSignMessageSuccessPayload, type MiniAppSignTypedDataErrorPayload, type MiniAppSignTypedDataPayload, type MiniAppSignTypedDataSuccessPayload, type MiniAppVerifyActionErrorPayload, type MiniAppVerifyActionPayload, type MiniAppVerifyActionSuccessPayload, type MiniAppWalletAuthErrorPayload, type MiniAppWalletAuthPayload, type MiniAppWalletAuthSuccessPayload, MiniKit, MiniKitInstallErrorCodes, MiniKitInstallErrorMessage, type MiniKitInstallReturnType, Network, type PayCommandInput, type PayCommandPayload, PaymentErrorCodes, PaymentErrorMessage, PaymentValidationErrors, ResponseEvent, SAFE_CONTRACT_ABI, SendTransactionErrorCodes, SendTransactionErrorMessage, type SendTransactionInput, type SendTransactionPayload, SignMessageErrorCodes, SignMessageErrorMessage, type SignMessageInput, type SignMessagePayload, SignTypedDataErrorCodes, SignTypedDataErrorMessage, type SignTypedDataInput, type SignTypedDataPayload, type SiweMessage, TokenDecimals, Tokens, type TokensPayload, VerificationErrorMessage, type VerifyCommandInput, type VerifyCommandPayload, WalletAuthErrorCodes, WalletAuthErrorMessage, type WalletAuthInput, type WalletAuthPayload, type WebViewBasePayload, parseSiweMessage, tokenToDecimals, verifySiweMessage };
|
|
394
|
+
export { type AsyncHandlerReturn, Command, type CommandReturnPayload, type EventHandler, type EventPayload, type MiniAppPaymentErrorPayload, type MiniAppPaymentPayload, type MiniAppPaymentSuccessPayload, type MiniAppSendTransactionErrorPayload, type MiniAppSendTransactionPayload, type MiniAppSendTransactionSuccessPayload, type MiniAppSignMessageErrorPayload, type MiniAppSignMessagePayload, type MiniAppSignMessageSuccessPayload, type MiniAppSignTypedDataErrorPayload, type MiniAppSignTypedDataPayload, type MiniAppSignTypedDataSuccessPayload, type MiniAppVerifyActionErrorPayload, type MiniAppVerifyActionPayload, type MiniAppVerifyActionSuccessPayload, type MiniAppWalletAuthErrorPayload, type MiniAppWalletAuthPayload, type MiniAppWalletAuthSuccessPayload, MiniKit, MiniKitInstallErrorCodes, MiniKitInstallErrorMessage, type MiniKitInstallReturnType, Network, type PayCommandInput, type PayCommandPayload, PaymentErrorCodes, PaymentErrorMessage, PaymentValidationErrors, ResponseEvent, SAFE_CONTRACT_ABI, SendTransactionErrorCodes, SendTransactionErrorMessage, type SendTransactionInput, type SendTransactionPayload, SignMessageErrorCodes, SignMessageErrorMessage, type SignMessageInput, type SignMessagePayload, SignTypedDataErrorCodes, SignTypedDataErrorMessage, type SignTypedDataInput, type SignTypedDataPayload, type SiweMessage, TokenDecimals, Tokens, type TokensPayload, VerificationErrorMessage, type VerifyCommandInput, type VerifyCommandPayload, WalletAuthErrorCodes, WalletAuthErrorMessage, type WalletAuthInput, type WalletAuthPayload, type WebViewBasePayload, parseSiweMessage, tokenToDecimals, verifySiweMessage };
|
package/build/index.js
CHANGED
|
@@ -430,6 +430,17 @@ var _MiniKit = class _MiniKit {
|
|
|
430
430
|
}
|
|
431
431
|
this.listeners[event](payload);
|
|
432
432
|
}
|
|
433
|
+
static async awaitCommand(event, command, executor) {
|
|
434
|
+
return new Promise((resolve) => {
|
|
435
|
+
let commandPayload = null;
|
|
436
|
+
const handleAndUnsubscribe = (payload) => {
|
|
437
|
+
this.unsubscribe(event);
|
|
438
|
+
resolve({ commandPayload, finalPayload: payload });
|
|
439
|
+
};
|
|
440
|
+
this.subscribe(event, handleAndUnsubscribe);
|
|
441
|
+
commandPayload = executor();
|
|
442
|
+
});
|
|
443
|
+
}
|
|
433
444
|
static commandsValid(input) {
|
|
434
445
|
return Object.entries(this.commandVersion).every(
|
|
435
446
|
([commandName, version]) => {
|
|
@@ -447,7 +458,7 @@ var _MiniKit = class _MiniKit {
|
|
|
447
458
|
}
|
|
448
459
|
);
|
|
449
460
|
}
|
|
450
|
-
static install() {
|
|
461
|
+
static install(appId) {
|
|
451
462
|
if (typeof window === "undefined" || Boolean(window.MiniKit)) {
|
|
452
463
|
return {
|
|
453
464
|
success: false,
|
|
@@ -455,6 +466,11 @@ var _MiniKit = class _MiniKit {
|
|
|
455
466
|
errorMessage: MiniKitInstallErrorMessage["already_installed" /* AlreadyInstalled */]
|
|
456
467
|
};
|
|
457
468
|
}
|
|
469
|
+
if (!appId) {
|
|
470
|
+
console.warn("App ID not provided during install");
|
|
471
|
+
} else {
|
|
472
|
+
_MiniKit.appId = appId;
|
|
473
|
+
}
|
|
458
474
|
if (!window.WorldApp) {
|
|
459
475
|
return {
|
|
460
476
|
success: false,
|
|
@@ -526,6 +542,7 @@ _MiniKit.listeners = {
|
|
|
526
542
|
["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
|
|
527
543
|
}
|
|
528
544
|
};
|
|
545
|
+
_MiniKit.appId = null;
|
|
529
546
|
_MiniKit.walletAddress = null;
|
|
530
547
|
_MiniKit.commands = {
|
|
531
548
|
verify: (payload) => {
|
|
@@ -658,6 +675,102 @@ _MiniKit.commands = {
|
|
|
658
675
|
return payload;
|
|
659
676
|
}
|
|
660
677
|
};
|
|
678
|
+
/**
|
|
679
|
+
* This object contains async versions of all the commands.
|
|
680
|
+
* Instead of using event listeners, you can just `await` these.
|
|
681
|
+
*
|
|
682
|
+
* They return a standardized object
|
|
683
|
+
*
|
|
684
|
+
* commandPayload - object returned by the command function
|
|
685
|
+
*
|
|
686
|
+
* finalPayload - object returned by the event listener, or in other words, WorldApp response
|
|
687
|
+
*/
|
|
688
|
+
_MiniKit.commandsAsync = {
|
|
689
|
+
verify: async (payload) => {
|
|
690
|
+
return new Promise(async (resolve, reject) => {
|
|
691
|
+
try {
|
|
692
|
+
const response = await _MiniKit.awaitCommand(
|
|
693
|
+
"miniapp-verify-action" /* MiniAppVerifyAction */,
|
|
694
|
+
"verify" /* Verify */,
|
|
695
|
+
() => _MiniKit.commands.verify(payload)
|
|
696
|
+
);
|
|
697
|
+
resolve(response);
|
|
698
|
+
} catch (error) {
|
|
699
|
+
reject(error);
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
},
|
|
703
|
+
pay: async (payload) => {
|
|
704
|
+
return new Promise(async (resolve, reject) => {
|
|
705
|
+
try {
|
|
706
|
+
const response = await _MiniKit.awaitCommand(
|
|
707
|
+
"miniapp-payment" /* MiniAppPayment */,
|
|
708
|
+
"pay" /* Pay */,
|
|
709
|
+
() => _MiniKit.commands.pay(payload)
|
|
710
|
+
);
|
|
711
|
+
resolve(response);
|
|
712
|
+
} catch (error) {
|
|
713
|
+
reject(error);
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
},
|
|
717
|
+
walletAuth: async (payload) => {
|
|
718
|
+
return new Promise(async (resolve, reject) => {
|
|
719
|
+
try {
|
|
720
|
+
const response = await _MiniKit.awaitCommand(
|
|
721
|
+
"miniapp-wallet-auth" /* MiniAppWalletAuth */,
|
|
722
|
+
"wallet-auth" /* WalletAuth */,
|
|
723
|
+
() => _MiniKit.commands.walletAuth(payload)
|
|
724
|
+
);
|
|
725
|
+
return resolve(response);
|
|
726
|
+
} catch (error) {
|
|
727
|
+
reject(error);
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
},
|
|
731
|
+
sendTransaction: async (payload) => {
|
|
732
|
+
return new Promise(async (resolve, reject) => {
|
|
733
|
+
try {
|
|
734
|
+
const response = await _MiniKit.awaitCommand(
|
|
735
|
+
"miniapp-send-transaction" /* MiniAppSendTransaction */,
|
|
736
|
+
"send-transaction" /* SendTransaction */,
|
|
737
|
+
() => _MiniKit.commands.sendTransaction(payload)
|
|
738
|
+
);
|
|
739
|
+
return resolve(response);
|
|
740
|
+
} catch (error) {
|
|
741
|
+
reject(error);
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
},
|
|
745
|
+
signMessage: async (payload) => {
|
|
746
|
+
return new Promise(async (resolve, reject) => {
|
|
747
|
+
try {
|
|
748
|
+
const response = await _MiniKit.awaitCommand(
|
|
749
|
+
"miniapp-sign-message" /* MiniAppSignMessage */,
|
|
750
|
+
"sign-message" /* SignMessage */,
|
|
751
|
+
() => _MiniKit.commands.signMessage(payload)
|
|
752
|
+
);
|
|
753
|
+
return resolve(response);
|
|
754
|
+
} catch (error) {
|
|
755
|
+
reject(error);
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
},
|
|
759
|
+
signTypedData: async (payload) => {
|
|
760
|
+
return new Promise(async (resolve, reject) => {
|
|
761
|
+
try {
|
|
762
|
+
const response = await _MiniKit.awaitCommand(
|
|
763
|
+
"miniapp-sign-typed-data" /* MiniAppSignTypedData */,
|
|
764
|
+
"sign-typed-data" /* SignTypedData */,
|
|
765
|
+
() => _MiniKit.commands.signTypedData(payload)
|
|
766
|
+
);
|
|
767
|
+
return resolve(response);
|
|
768
|
+
} catch (error) {
|
|
769
|
+
reject(error);
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
};
|
|
661
774
|
var MiniKit = _MiniKit;
|
|
662
775
|
|
|
663
776
|
// index.ts
|