@worldcoin/minikit-js 1.0.1 → 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/build/index.cjs +107 -0
- package/build/index.d.cts +33 -1
- package/build/index.d.ts +33 -1
- package/build/index.js +107 -0
- package/package.json +1 -1
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]) => {
|
|
@@ -711,6 +722,102 @@ _MiniKit.commands = {
|
|
|
711
722
|
return payload;
|
|
712
723
|
}
|
|
713
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
|
+
};
|
|
714
821
|
var MiniKit = _MiniKit;
|
|
715
822
|
|
|
716
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",
|
|
@@ -328,6 +341,7 @@ declare class MiniKit {
|
|
|
328
341
|
static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
|
|
329
342
|
static unsubscribe(event: ResponseEvent): void;
|
|
330
343
|
static trigger(event: ResponseEvent, payload: EventPayload): void;
|
|
344
|
+
private static awaitCommand;
|
|
331
345
|
private static commandsValid;
|
|
332
346
|
static install(appId?: string): MiniKitInstallReturnType;
|
|
333
347
|
static isInstalled(debug?: boolean): boolean;
|
|
@@ -339,6 +353,24 @@ declare class MiniKit {
|
|
|
339
353
|
signMessage: (payload: SignMessageInput) => SignMessagePayload | null;
|
|
340
354
|
signTypedData: (payload: SignTypedDataInput) => SignTypedDataPayload | null;
|
|
341
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
|
+
};
|
|
342
374
|
}
|
|
343
375
|
|
|
344
376
|
declare const tokenToDecimals: (amount: number, token: Tokens) => number;
|
|
@@ -359,4 +391,4 @@ declare const verifySiweMessage: (payload: MiniAppWalletAuthSuccessPayload, nonc
|
|
|
359
391
|
siweMessageData: SiweMessage;
|
|
360
392
|
}>;
|
|
361
393
|
|
|
362
|
-
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",
|
|
@@ -328,6 +341,7 @@ declare class MiniKit {
|
|
|
328
341
|
static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
|
|
329
342
|
static unsubscribe(event: ResponseEvent): void;
|
|
330
343
|
static trigger(event: ResponseEvent, payload: EventPayload): void;
|
|
344
|
+
private static awaitCommand;
|
|
331
345
|
private static commandsValid;
|
|
332
346
|
static install(appId?: string): MiniKitInstallReturnType;
|
|
333
347
|
static isInstalled(debug?: boolean): boolean;
|
|
@@ -339,6 +353,24 @@ declare class MiniKit {
|
|
|
339
353
|
signMessage: (payload: SignMessageInput) => SignMessagePayload | null;
|
|
340
354
|
signTypedData: (payload: SignTypedDataInput) => SignTypedDataPayload | null;
|
|
341
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
|
+
};
|
|
342
374
|
}
|
|
343
375
|
|
|
344
376
|
declare const tokenToDecimals: (amount: number, token: Tokens) => number;
|
|
@@ -359,4 +391,4 @@ declare const verifySiweMessage: (payload: MiniAppWalletAuthSuccessPayload, nonc
|
|
|
359
391
|
siweMessageData: SiweMessage;
|
|
360
392
|
}>;
|
|
361
393
|
|
|
362
|
-
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]) => {
|
|
@@ -664,6 +675,102 @@ _MiniKit.commands = {
|
|
|
664
675
|
return payload;
|
|
665
676
|
}
|
|
666
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
|
+
};
|
|
667
774
|
var MiniKit = _MiniKit;
|
|
668
775
|
|
|
669
776
|
// index.ts
|