@worldcoin/minikit-js 1.9.3 → 1.9.5
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/{chunk-QXLGARWF.js → chunk-HO7P24JI.js} +120 -43
- package/build/index.cjs +120 -43
- package/build/index.d.cts +53 -33
- package/build/index.d.ts +53 -33
- package/build/index.js +1 -1
- package/build/minikit-provider.cjs +118 -42
- package/build/minikit-provider.js +1 -1
- package/index.ts +1 -1
- package/package.json +1 -1
|
@@ -325,6 +325,7 @@ var Command = /* @__PURE__ */ ((Command2) => {
|
|
|
325
325
|
Command2["RequestPermission"] = "request-permission";
|
|
326
326
|
Command2["GetPermissions"] = "get-permissions";
|
|
327
327
|
Command2["SendHapticFeedback"] = "send-haptic-feedback";
|
|
328
|
+
Command2["Share"] = "share";
|
|
328
329
|
return Command2;
|
|
329
330
|
})(Command || {});
|
|
330
331
|
var Permission = /* @__PURE__ */ ((Permission2) => {
|
|
@@ -530,7 +531,7 @@ var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
|
|
|
530
531
|
ResponseEvent2["MiniAppRequestPermission"] = "miniapp-request-permission";
|
|
531
532
|
ResponseEvent2["MiniAppGetPermissions"] = "miniapp-get-permissions";
|
|
532
533
|
ResponseEvent2["MiniAppSendHapticFeedback"] = "miniapp-send-haptic-feedback";
|
|
533
|
-
ResponseEvent2["
|
|
534
|
+
ResponseEvent2["MiniAppShare"] = "miniapp-share";
|
|
534
535
|
return ResponseEvent2;
|
|
535
536
|
})(ResponseEvent || {});
|
|
536
537
|
|
|
@@ -593,6 +594,72 @@ var compressAndPadProof = async (proof, rpcUrl) => {
|
|
|
593
594
|
}
|
|
594
595
|
};
|
|
595
596
|
|
|
597
|
+
// helpers/share/index.ts
|
|
598
|
+
var MAX_FILES = 10;
|
|
599
|
+
var MAX_TOTAL_SIZE_MB = 50;
|
|
600
|
+
var MAX_TOTAL_SIZE_BYTES = MAX_TOTAL_SIZE_MB * 1024 * 1024;
|
|
601
|
+
var processFile = async (file) => {
|
|
602
|
+
const buffer = await file.arrayBuffer();
|
|
603
|
+
const uint8Array = new Uint8Array(buffer);
|
|
604
|
+
let binaryString = "";
|
|
605
|
+
const K_CHUNK_SIZE = 32768;
|
|
606
|
+
for (let i = 0; i < uint8Array.length; i += K_CHUNK_SIZE) {
|
|
607
|
+
const chunk = uint8Array.subarray(
|
|
608
|
+
i,
|
|
609
|
+
Math.min(i + K_CHUNK_SIZE, uint8Array.length)
|
|
610
|
+
);
|
|
611
|
+
binaryString += String.fromCharCode.apply(
|
|
612
|
+
null,
|
|
613
|
+
Array.from(chunk)
|
|
614
|
+
// Convert Uint8Array chunk to number[]
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
const base64Data = btoa(binaryString);
|
|
618
|
+
return {
|
|
619
|
+
name: file.name,
|
|
620
|
+
type: file.type,
|
|
621
|
+
data: base64Data
|
|
622
|
+
};
|
|
623
|
+
};
|
|
624
|
+
var formatShareInput = async (input) => {
|
|
625
|
+
if (!input.files) {
|
|
626
|
+
return {
|
|
627
|
+
title: input.title,
|
|
628
|
+
text: input.text,
|
|
629
|
+
url: input.url
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
if (!Array.isArray(input.files)) {
|
|
633
|
+
throw new Error('The "files" property must be an array.');
|
|
634
|
+
}
|
|
635
|
+
if (input.files.length === 0) {
|
|
636
|
+
} else {
|
|
637
|
+
if (input.files.length > MAX_FILES) {
|
|
638
|
+
throw new Error(`Cannot share more than ${MAX_FILES} files.`);
|
|
639
|
+
}
|
|
640
|
+
let totalSize = 0;
|
|
641
|
+
for (const file of input.files) {
|
|
642
|
+
if (!(file instanceof File)) {
|
|
643
|
+
throw new Error(
|
|
644
|
+
`Each item in the 'files' array must be a File object. Received: ${typeof file}`
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
totalSize += file.size;
|
|
648
|
+
}
|
|
649
|
+
if (totalSize > MAX_TOTAL_SIZE_BYTES) {
|
|
650
|
+
throw new Error(`Total file size cannot exceed ${MAX_TOTAL_SIZE_MB}MB.`);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
const fileProcessingPromises = input.files.map((file) => processFile(file));
|
|
654
|
+
const processedFiles = await Promise.all(fileProcessingPromises);
|
|
655
|
+
return {
|
|
656
|
+
files: processedFiles,
|
|
657
|
+
title: input.title,
|
|
658
|
+
text: input.text,
|
|
659
|
+
url: input.url
|
|
660
|
+
};
|
|
661
|
+
};
|
|
662
|
+
|
|
596
663
|
// helpers/siwe/validate-wallet-auth-command-input.ts
|
|
597
664
|
var validateWalletAuthCommandInput = (params) => {
|
|
598
665
|
if (!params.nonce) {
|
|
@@ -790,6 +857,7 @@ var _MiniKit = class _MiniKit {
|
|
|
790
857
|
_MiniKit.isCommandAvailable[minikitCommandName] = true;
|
|
791
858
|
isCommandValid = true;
|
|
792
859
|
} else {
|
|
860
|
+
isCommandValid = true;
|
|
793
861
|
console.warn(
|
|
794
862
|
`Command ${minikitCommandName} version ${version} is not supported by the app. Supported versions: ${commandInput.supported_versions.join(", ")}. This is not an error, but it is recommended to update the World App version.`
|
|
795
863
|
);
|
|
@@ -826,6 +894,7 @@ var _MiniKit = class _MiniKit {
|
|
|
826
894
|
_MiniKit.user.optedIntoOptionalAnalytics = window.WorldApp.is_optional_analytics;
|
|
827
895
|
_MiniKit.user.deviceOS = window.WorldApp.device_os;
|
|
828
896
|
_MiniKit.user.worldAppVersion = window.WorldApp.world_app_version;
|
|
897
|
+
_MiniKit.deviceProperties.safeAreaInsets = window.WorldApp.safe_area_insets;
|
|
829
898
|
try {
|
|
830
899
|
window.MiniKit = _MiniKit;
|
|
831
900
|
this.sendInit();
|
|
@@ -871,8 +940,8 @@ _MiniKit.miniKitCommandVersion = {
|
|
|
871
940
|
["share-contacts" /* ShareContacts */]: 1,
|
|
872
941
|
["request-permission" /* RequestPermission */]: 1,
|
|
873
942
|
["get-permissions" /* GetPermissions */]: 1,
|
|
874
|
-
["send-haptic-feedback" /* SendHapticFeedback */]: 1
|
|
875
|
-
|
|
943
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: 1,
|
|
944
|
+
["share" /* Share */]: 1
|
|
876
945
|
};
|
|
877
946
|
_MiniKit.isCommandAvailable = {
|
|
878
947
|
["verify" /* Verify */]: false,
|
|
@@ -884,8 +953,8 @@ _MiniKit.isCommandAvailable = {
|
|
|
884
953
|
["share-contacts" /* ShareContacts */]: false,
|
|
885
954
|
["request-permission" /* RequestPermission */]: false,
|
|
886
955
|
["get-permissions" /* GetPermissions */]: false,
|
|
887
|
-
["send-haptic-feedback" /* SendHapticFeedback */]: false
|
|
888
|
-
|
|
956
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: false,
|
|
957
|
+
["share" /* Share */]: false
|
|
889
958
|
};
|
|
890
959
|
_MiniKit.listeners = {
|
|
891
960
|
["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
|
|
@@ -908,12 +977,13 @@ _MiniKit.listeners = {
|
|
|
908
977
|
},
|
|
909
978
|
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
910
979
|
},
|
|
911
|
-
["miniapp-share
|
|
980
|
+
["miniapp-share" /* MiniAppShare */]: () => {
|
|
912
981
|
}
|
|
913
982
|
};
|
|
914
983
|
_MiniKit.appId = null;
|
|
915
984
|
_MiniKit.user = {};
|
|
916
985
|
_MiniKit.isReady = false;
|
|
986
|
+
_MiniKit.deviceProperties = {};
|
|
917
987
|
_MiniKit.getUserByAddress = async (address) => {
|
|
918
988
|
const userProfile = await getUserProfile(
|
|
919
989
|
address ?? _MiniKit.user.walletAddress
|
|
@@ -1079,7 +1149,7 @@ _MiniKit.commands = {
|
|
|
1079
1149
|
return payload;
|
|
1080
1150
|
},
|
|
1081
1151
|
shareContacts: (payload) => {
|
|
1082
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["
|
|
1152
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["share-contacts" /* ShareContacts */]) {
|
|
1083
1153
|
console.error(
|
|
1084
1154
|
"'shareContacts' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1085
1155
|
);
|
|
@@ -1135,24 +1205,33 @@ _MiniKit.commands = {
|
|
|
1135
1205
|
payload
|
|
1136
1206
|
});
|
|
1137
1207
|
return payload;
|
|
1208
|
+
},
|
|
1209
|
+
// We return share input here because the payload is formatted asynchronously
|
|
1210
|
+
share: (payload) => {
|
|
1211
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["share" /* Share */]) {
|
|
1212
|
+
console.error(
|
|
1213
|
+
"'share' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1214
|
+
);
|
|
1215
|
+
return null;
|
|
1216
|
+
}
|
|
1217
|
+
if (_MiniKit.user.deviceOS === "ios") {
|
|
1218
|
+
navigator.share(payload);
|
|
1219
|
+
} else {
|
|
1220
|
+
formatShareInput(payload).then((formattedResult) => {
|
|
1221
|
+
sendMiniKitEvent({
|
|
1222
|
+
command: "share" /* Share */,
|
|
1223
|
+
version: _MiniKit.miniKitCommandVersion["share" /* Share */],
|
|
1224
|
+
payload: formattedResult
|
|
1225
|
+
});
|
|
1226
|
+
}).catch((error) => {
|
|
1227
|
+
console.error("Failed to format share input", error);
|
|
1228
|
+
});
|
|
1229
|
+
_MiniKit.subscribe("miniapp-share" /* MiniAppShare */, (payload2) => {
|
|
1230
|
+
console.log("Share Response", payload2);
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
return payload;
|
|
1138
1234
|
}
|
|
1139
|
-
// shareFiles: (payload: ShareFilesInput): ShareFilesPayload | null => {
|
|
1140
|
-
// if (
|
|
1141
|
-
// typeof window === 'undefined' ||
|
|
1142
|
-
// !this.isCommandAvailable[Command.ShareFiles]
|
|
1143
|
-
// ) {
|
|
1144
|
-
// console.error(
|
|
1145
|
-
// "'shareFiles' command is unavailable. Check MiniKit.install() or update the app version",
|
|
1146
|
-
// );
|
|
1147
|
-
// return null;
|
|
1148
|
-
// }
|
|
1149
|
-
// sendMiniKitEvent<WebViewBasePayload>({
|
|
1150
|
-
// command: Command.ShareFiles,
|
|
1151
|
-
// version: this.miniKitCommandVersion[Command.ShareFiles],
|
|
1152
|
-
// payload,
|
|
1153
|
-
// });
|
|
1154
|
-
// return payload;
|
|
1155
|
-
// },
|
|
1156
1235
|
};
|
|
1157
1236
|
/**
|
|
1158
1237
|
* This object contains async versions of all the commands.
|
|
@@ -1309,26 +1388,24 @@ _MiniKit.commandsAsync = {
|
|
|
1309
1388
|
reject(error);
|
|
1310
1389
|
}
|
|
1311
1390
|
});
|
|
1391
|
+
},
|
|
1392
|
+
share: async (payload) => {
|
|
1393
|
+
return new Promise(async (resolve, reject) => {
|
|
1394
|
+
try {
|
|
1395
|
+
const response = await _MiniKit.awaitCommand(
|
|
1396
|
+
"miniapp-share" /* MiniAppShare */,
|
|
1397
|
+
"share" /* Share */,
|
|
1398
|
+
() => _MiniKit.commands.share(payload)
|
|
1399
|
+
);
|
|
1400
|
+
resolve({
|
|
1401
|
+
commandPayload: response.commandPayload,
|
|
1402
|
+
finalPayload: response.finalPayload
|
|
1403
|
+
});
|
|
1404
|
+
} catch (error) {
|
|
1405
|
+
reject(error);
|
|
1406
|
+
}
|
|
1407
|
+
});
|
|
1312
1408
|
}
|
|
1313
|
-
// shareFiles: async (
|
|
1314
|
-
// payload: ShareFilesInput,
|
|
1315
|
-
// ): AsyncHandlerReturn<
|
|
1316
|
-
// ShareFilesPayload | null,
|
|
1317
|
-
// MiniAppShareFilesPayload
|
|
1318
|
-
// > => {
|
|
1319
|
-
// return new Promise(async (resolve, reject) => {
|
|
1320
|
-
// try {
|
|
1321
|
-
// const response = await MiniKit.awaitCommand(
|
|
1322
|
-
// ResponseEvent.MiniAppShareFiles,
|
|
1323
|
-
// Command.ShareFiles,
|
|
1324
|
-
// () => this.commands.shareFiles(payload),
|
|
1325
|
-
// );
|
|
1326
|
-
// resolve(response);
|
|
1327
|
-
// } catch (error) {
|
|
1328
|
-
// reject(error);
|
|
1329
|
-
// }
|
|
1330
|
-
// });
|
|
1331
|
-
// },
|
|
1332
1409
|
};
|
|
1333
1410
|
var MiniKit = _MiniKit;
|
|
1334
1411
|
|
package/build/index.cjs
CHANGED
|
@@ -161,6 +161,72 @@ var compressAndPadProof = async (proof, rpcUrl) => {
|
|
|
161
161
|
}
|
|
162
162
|
};
|
|
163
163
|
|
|
164
|
+
// helpers/share/index.ts
|
|
165
|
+
var MAX_FILES = 10;
|
|
166
|
+
var MAX_TOTAL_SIZE_MB = 50;
|
|
167
|
+
var MAX_TOTAL_SIZE_BYTES = MAX_TOTAL_SIZE_MB * 1024 * 1024;
|
|
168
|
+
var processFile = async (file) => {
|
|
169
|
+
const buffer = await file.arrayBuffer();
|
|
170
|
+
const uint8Array = new Uint8Array(buffer);
|
|
171
|
+
let binaryString = "";
|
|
172
|
+
const K_CHUNK_SIZE = 32768;
|
|
173
|
+
for (let i = 0; i < uint8Array.length; i += K_CHUNK_SIZE) {
|
|
174
|
+
const chunk = uint8Array.subarray(
|
|
175
|
+
i,
|
|
176
|
+
Math.min(i + K_CHUNK_SIZE, uint8Array.length)
|
|
177
|
+
);
|
|
178
|
+
binaryString += String.fromCharCode.apply(
|
|
179
|
+
null,
|
|
180
|
+
Array.from(chunk)
|
|
181
|
+
// Convert Uint8Array chunk to number[]
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
const base64Data = btoa(binaryString);
|
|
185
|
+
return {
|
|
186
|
+
name: file.name,
|
|
187
|
+
type: file.type,
|
|
188
|
+
data: base64Data
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
var formatShareInput = async (input) => {
|
|
192
|
+
if (!input.files) {
|
|
193
|
+
return {
|
|
194
|
+
title: input.title,
|
|
195
|
+
text: input.text,
|
|
196
|
+
url: input.url
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
if (!Array.isArray(input.files)) {
|
|
200
|
+
throw new Error('The "files" property must be an array.');
|
|
201
|
+
}
|
|
202
|
+
if (input.files.length === 0) {
|
|
203
|
+
} else {
|
|
204
|
+
if (input.files.length > MAX_FILES) {
|
|
205
|
+
throw new Error(`Cannot share more than ${MAX_FILES} files.`);
|
|
206
|
+
}
|
|
207
|
+
let totalSize = 0;
|
|
208
|
+
for (const file of input.files) {
|
|
209
|
+
if (!(file instanceof File)) {
|
|
210
|
+
throw new Error(
|
|
211
|
+
`Each item in the 'files' array must be a File object. Received: ${typeof file}`
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
totalSize += file.size;
|
|
215
|
+
}
|
|
216
|
+
if (totalSize > MAX_TOTAL_SIZE_BYTES) {
|
|
217
|
+
throw new Error(`Total file size cannot exceed ${MAX_TOTAL_SIZE_MB}MB.`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const fileProcessingPromises = input.files.map((file) => processFile(file));
|
|
221
|
+
const processedFiles = await Promise.all(fileProcessingPromises);
|
|
222
|
+
return {
|
|
223
|
+
files: processedFiles,
|
|
224
|
+
title: input.title,
|
|
225
|
+
text: input.text,
|
|
226
|
+
url: input.url
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
|
|
164
230
|
// helpers/siwe/siwe.ts
|
|
165
231
|
var import_viem2 = require("viem");
|
|
166
232
|
var import_chains2 = require("viem/chains");
|
|
@@ -538,6 +604,7 @@ var Command = /* @__PURE__ */ ((Command2) => {
|
|
|
538
604
|
Command2["RequestPermission"] = "request-permission";
|
|
539
605
|
Command2["GetPermissions"] = "get-permissions";
|
|
540
606
|
Command2["SendHapticFeedback"] = "send-haptic-feedback";
|
|
607
|
+
Command2["Share"] = "share";
|
|
541
608
|
return Command2;
|
|
542
609
|
})(Command || {});
|
|
543
610
|
var Permission = /* @__PURE__ */ ((Permission2) => {
|
|
@@ -752,7 +819,7 @@ var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
|
|
|
752
819
|
ResponseEvent2["MiniAppRequestPermission"] = "miniapp-request-permission";
|
|
753
820
|
ResponseEvent2["MiniAppGetPermissions"] = "miniapp-get-permissions";
|
|
754
821
|
ResponseEvent2["MiniAppSendHapticFeedback"] = "miniapp-send-haptic-feedback";
|
|
755
|
-
ResponseEvent2["
|
|
822
|
+
ResponseEvent2["MiniAppShare"] = "miniapp-share";
|
|
756
823
|
return ResponseEvent2;
|
|
757
824
|
})(ResponseEvent || {});
|
|
758
825
|
|
|
@@ -842,6 +909,7 @@ var _MiniKit = class _MiniKit {
|
|
|
842
909
|
_MiniKit.isCommandAvailable[minikitCommandName] = true;
|
|
843
910
|
isCommandValid = true;
|
|
844
911
|
} else {
|
|
912
|
+
isCommandValid = true;
|
|
845
913
|
console.warn(
|
|
846
914
|
`Command ${minikitCommandName} version ${version} is not supported by the app. Supported versions: ${commandInput.supported_versions.join(", ")}. This is not an error, but it is recommended to update the World App version.`
|
|
847
915
|
);
|
|
@@ -878,6 +946,7 @@ var _MiniKit = class _MiniKit {
|
|
|
878
946
|
_MiniKit.user.optedIntoOptionalAnalytics = window.WorldApp.is_optional_analytics;
|
|
879
947
|
_MiniKit.user.deviceOS = window.WorldApp.device_os;
|
|
880
948
|
_MiniKit.user.worldAppVersion = window.WorldApp.world_app_version;
|
|
949
|
+
_MiniKit.deviceProperties.safeAreaInsets = window.WorldApp.safe_area_insets;
|
|
881
950
|
try {
|
|
882
951
|
window.MiniKit = _MiniKit;
|
|
883
952
|
this.sendInit();
|
|
@@ -923,8 +992,8 @@ _MiniKit.miniKitCommandVersion = {
|
|
|
923
992
|
["share-contacts" /* ShareContacts */]: 1,
|
|
924
993
|
["request-permission" /* RequestPermission */]: 1,
|
|
925
994
|
["get-permissions" /* GetPermissions */]: 1,
|
|
926
|
-
["send-haptic-feedback" /* SendHapticFeedback */]: 1
|
|
927
|
-
|
|
995
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: 1,
|
|
996
|
+
["share" /* Share */]: 1
|
|
928
997
|
};
|
|
929
998
|
_MiniKit.isCommandAvailable = {
|
|
930
999
|
["verify" /* Verify */]: false,
|
|
@@ -936,8 +1005,8 @@ _MiniKit.isCommandAvailable = {
|
|
|
936
1005
|
["share-contacts" /* ShareContacts */]: false,
|
|
937
1006
|
["request-permission" /* RequestPermission */]: false,
|
|
938
1007
|
["get-permissions" /* GetPermissions */]: false,
|
|
939
|
-
["send-haptic-feedback" /* SendHapticFeedback */]: false
|
|
940
|
-
|
|
1008
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: false,
|
|
1009
|
+
["share" /* Share */]: false
|
|
941
1010
|
};
|
|
942
1011
|
_MiniKit.listeners = {
|
|
943
1012
|
["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
|
|
@@ -960,12 +1029,13 @@ _MiniKit.listeners = {
|
|
|
960
1029
|
},
|
|
961
1030
|
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
962
1031
|
},
|
|
963
|
-
["miniapp-share
|
|
1032
|
+
["miniapp-share" /* MiniAppShare */]: () => {
|
|
964
1033
|
}
|
|
965
1034
|
};
|
|
966
1035
|
_MiniKit.appId = null;
|
|
967
1036
|
_MiniKit.user = {};
|
|
968
1037
|
_MiniKit.isReady = false;
|
|
1038
|
+
_MiniKit.deviceProperties = {};
|
|
969
1039
|
_MiniKit.getUserByAddress = async (address) => {
|
|
970
1040
|
const userProfile = await getUserProfile(
|
|
971
1041
|
address ?? _MiniKit.user.walletAddress
|
|
@@ -1131,7 +1201,7 @@ _MiniKit.commands = {
|
|
|
1131
1201
|
return payload;
|
|
1132
1202
|
},
|
|
1133
1203
|
shareContacts: (payload) => {
|
|
1134
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["
|
|
1204
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["share-contacts" /* ShareContacts */]) {
|
|
1135
1205
|
console.error(
|
|
1136
1206
|
"'shareContacts' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1137
1207
|
);
|
|
@@ -1187,24 +1257,33 @@ _MiniKit.commands = {
|
|
|
1187
1257
|
payload
|
|
1188
1258
|
});
|
|
1189
1259
|
return payload;
|
|
1260
|
+
},
|
|
1261
|
+
// We return share input here because the payload is formatted asynchronously
|
|
1262
|
+
share: (payload) => {
|
|
1263
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["share" /* Share */]) {
|
|
1264
|
+
console.error(
|
|
1265
|
+
"'share' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1266
|
+
);
|
|
1267
|
+
return null;
|
|
1268
|
+
}
|
|
1269
|
+
if (_MiniKit.user.deviceOS === "ios") {
|
|
1270
|
+
navigator.share(payload);
|
|
1271
|
+
} else {
|
|
1272
|
+
formatShareInput(payload).then((formattedResult) => {
|
|
1273
|
+
sendMiniKitEvent({
|
|
1274
|
+
command: "share" /* Share */,
|
|
1275
|
+
version: _MiniKit.miniKitCommandVersion["share" /* Share */],
|
|
1276
|
+
payload: formattedResult
|
|
1277
|
+
});
|
|
1278
|
+
}).catch((error) => {
|
|
1279
|
+
console.error("Failed to format share input", error);
|
|
1280
|
+
});
|
|
1281
|
+
_MiniKit.subscribe("miniapp-share" /* MiniAppShare */, (payload2) => {
|
|
1282
|
+
console.log("Share Response", payload2);
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
return payload;
|
|
1190
1286
|
}
|
|
1191
|
-
// shareFiles: (payload: ShareFilesInput): ShareFilesPayload | null => {
|
|
1192
|
-
// if (
|
|
1193
|
-
// typeof window === 'undefined' ||
|
|
1194
|
-
// !this.isCommandAvailable[Command.ShareFiles]
|
|
1195
|
-
// ) {
|
|
1196
|
-
// console.error(
|
|
1197
|
-
// "'shareFiles' command is unavailable. Check MiniKit.install() or update the app version",
|
|
1198
|
-
// );
|
|
1199
|
-
// return null;
|
|
1200
|
-
// }
|
|
1201
|
-
// sendMiniKitEvent<WebViewBasePayload>({
|
|
1202
|
-
// command: Command.ShareFiles,
|
|
1203
|
-
// version: this.miniKitCommandVersion[Command.ShareFiles],
|
|
1204
|
-
// payload,
|
|
1205
|
-
// });
|
|
1206
|
-
// return payload;
|
|
1207
|
-
// },
|
|
1208
1287
|
};
|
|
1209
1288
|
/**
|
|
1210
1289
|
* This object contains async versions of all the commands.
|
|
@@ -1361,26 +1440,24 @@ _MiniKit.commandsAsync = {
|
|
|
1361
1440
|
reject(error);
|
|
1362
1441
|
}
|
|
1363
1442
|
});
|
|
1443
|
+
},
|
|
1444
|
+
share: async (payload) => {
|
|
1445
|
+
return new Promise(async (resolve, reject) => {
|
|
1446
|
+
try {
|
|
1447
|
+
const response = await _MiniKit.awaitCommand(
|
|
1448
|
+
"miniapp-share" /* MiniAppShare */,
|
|
1449
|
+
"share" /* Share */,
|
|
1450
|
+
() => _MiniKit.commands.share(payload)
|
|
1451
|
+
);
|
|
1452
|
+
resolve({
|
|
1453
|
+
commandPayload: response.commandPayload,
|
|
1454
|
+
finalPayload: response.finalPayload
|
|
1455
|
+
});
|
|
1456
|
+
} catch (error) {
|
|
1457
|
+
reject(error);
|
|
1458
|
+
}
|
|
1459
|
+
});
|
|
1364
1460
|
}
|
|
1365
|
-
// shareFiles: async (
|
|
1366
|
-
// payload: ShareFilesInput,
|
|
1367
|
-
// ): AsyncHandlerReturn<
|
|
1368
|
-
// ShareFilesPayload | null,
|
|
1369
|
-
// MiniAppShareFilesPayload
|
|
1370
|
-
// > => {
|
|
1371
|
-
// return new Promise(async (resolve, reject) => {
|
|
1372
|
-
// try {
|
|
1373
|
-
// const response = await MiniKit.awaitCommand(
|
|
1374
|
-
// ResponseEvent.MiniAppShareFiles,
|
|
1375
|
-
// Command.ShareFiles,
|
|
1376
|
-
// () => this.commands.shareFiles(payload),
|
|
1377
|
-
// );
|
|
1378
|
-
// resolve(response);
|
|
1379
|
-
// } catch (error) {
|
|
1380
|
-
// reject(error);
|
|
1381
|
-
// }
|
|
1382
|
-
// });
|
|
1383
|
-
// },
|
|
1384
1461
|
};
|
|
1385
1462
|
var MiniKit = _MiniKit;
|
|
1386
1463
|
|
package/build/index.d.cts
CHANGED
|
@@ -181,7 +181,8 @@ declare enum Command {
|
|
|
181
181
|
ShareContacts = "share-contacts",
|
|
182
182
|
RequestPermission = "request-permission",
|
|
183
183
|
GetPermissions = "get-permissions",
|
|
184
|
-
SendHapticFeedback = "send-haptic-feedback"
|
|
184
|
+
SendHapticFeedback = "send-haptic-feedback",
|
|
185
|
+
Share = "share"
|
|
185
186
|
}
|
|
186
187
|
type WebViewBasePayload = {
|
|
187
188
|
command: Command;
|
|
@@ -273,15 +274,22 @@ type SendHapticFeedbackInput = {
|
|
|
273
274
|
style: 'light' | 'medium' | 'heavy';
|
|
274
275
|
};
|
|
275
276
|
type SendHapticFeedbackPayload = SendHapticFeedbackInput;
|
|
276
|
-
type
|
|
277
|
-
|
|
278
|
-
|
|
277
|
+
type ShareInput = {
|
|
278
|
+
files?: File[];
|
|
279
|
+
title?: string;
|
|
280
|
+
text?: string;
|
|
281
|
+
url?: string;
|
|
282
|
+
};
|
|
283
|
+
type SharePayload = {
|
|
284
|
+
files?: Array<{
|
|
285
|
+
name: string;
|
|
286
|
+
type: string;
|
|
287
|
+
data: string;
|
|
288
|
+
}>;
|
|
289
|
+
title?: string;
|
|
290
|
+
text?: string;
|
|
291
|
+
url?: string;
|
|
279
292
|
};
|
|
280
|
-
type ShareFilesInput = {
|
|
281
|
-
files: ShareFile[];
|
|
282
|
-
mime_type: string;
|
|
283
|
-
};
|
|
284
|
-
type ShareFilesPayload = ShareFilesInput;
|
|
285
293
|
type CommandReturnPayloadMap = {
|
|
286
294
|
[Command.Verify]: VerifyCommandPayload;
|
|
287
295
|
[Command.Pay]: PayCommandPayload;
|
|
@@ -293,9 +301,36 @@ type CommandReturnPayloadMap = {
|
|
|
293
301
|
[Command.RequestPermission]: RequestPermissionPayload;
|
|
294
302
|
[Command.GetPermissions]: GetPermissionsPayload;
|
|
295
303
|
[Command.SendHapticFeedback]: SendHapticFeedbackPayload;
|
|
304
|
+
[Command.Share]: SharePayload;
|
|
296
305
|
};
|
|
297
306
|
type CommandReturnPayload<T extends Command> = T extends keyof CommandReturnPayloadMap ? CommandReturnPayloadMap[T] : never;
|
|
298
307
|
|
|
308
|
+
type User = {
|
|
309
|
+
walletAddress?: string;
|
|
310
|
+
username?: string;
|
|
311
|
+
profilePictureUrl?: string;
|
|
312
|
+
permissions?: {
|
|
313
|
+
notifications: boolean;
|
|
314
|
+
contacts: boolean;
|
|
315
|
+
};
|
|
316
|
+
optedIntoOptionalAnalytics?: boolean;
|
|
317
|
+
worldAppVersion?: number;
|
|
318
|
+
deviceOS?: string;
|
|
319
|
+
};
|
|
320
|
+
type DeviceProperties = {
|
|
321
|
+
safeAreaInsets?: {
|
|
322
|
+
top: number;
|
|
323
|
+
right: number;
|
|
324
|
+
bottom: number;
|
|
325
|
+
left: number;
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
type UserNameService = {
|
|
329
|
+
walletAddress: string;
|
|
330
|
+
username?: string;
|
|
331
|
+
profilePictureUrl?: string;
|
|
332
|
+
};
|
|
333
|
+
|
|
299
334
|
declare enum ResponseEvent {
|
|
300
335
|
MiniAppVerifyAction = "miniapp-verify-action",
|
|
301
336
|
MiniAppPayment = "miniapp-payment",
|
|
@@ -307,7 +342,7 @@ declare enum ResponseEvent {
|
|
|
307
342
|
MiniAppRequestPermission = "miniapp-request-permission",
|
|
308
343
|
MiniAppGetPermissions = "miniapp-get-permissions",
|
|
309
344
|
MiniAppSendHapticFeedback = "miniapp-send-haptic-feedback",
|
|
310
|
-
|
|
345
|
+
MiniAppShare = "miniapp-share"
|
|
311
346
|
}
|
|
312
347
|
type MiniAppVerifyActionSuccessPayload = {
|
|
313
348
|
status: 'success';
|
|
@@ -455,18 +490,18 @@ type MiniAppSendHapticFeedbackErrorPayload = {
|
|
|
455
490
|
version: number;
|
|
456
491
|
};
|
|
457
492
|
type MiniAppSendHapticFeedbackPayload = MiniAppSendHapticFeedbackSuccessPayload | MiniAppSendHapticFeedbackErrorPayload;
|
|
458
|
-
type
|
|
493
|
+
type MiniAppShareSuccessPayload = {
|
|
459
494
|
status: 'success';
|
|
460
495
|
shared_files_count: number;
|
|
461
496
|
version: number;
|
|
462
497
|
timestamp: string;
|
|
463
498
|
};
|
|
464
|
-
type
|
|
499
|
+
type MiniAppShareErrorPayload = {
|
|
465
500
|
status: 'error';
|
|
466
501
|
error_code: ShareFilesErrorCodes;
|
|
467
502
|
version: number;
|
|
468
503
|
};
|
|
469
|
-
type
|
|
504
|
+
type MiniAppSharePayload = MiniAppShareSuccessPayload | MiniAppShareErrorPayload;
|
|
470
505
|
type EventPayloadMap = {
|
|
471
506
|
[ResponseEvent.MiniAppVerifyAction]: MiniAppVerifyActionPayload;
|
|
472
507
|
[ResponseEvent.MiniAppPayment]: MiniAppPaymentPayload;
|
|
@@ -478,29 +513,11 @@ type EventPayloadMap = {
|
|
|
478
513
|
[ResponseEvent.MiniAppRequestPermission]: MiniAppRequestPermissionPayload;
|
|
479
514
|
[ResponseEvent.MiniAppGetPermissions]: MiniAppGetPermissionsPayload;
|
|
480
515
|
[ResponseEvent.MiniAppSendHapticFeedback]: MiniAppSendHapticFeedbackPayload;
|
|
481
|
-
[ResponseEvent.
|
|
516
|
+
[ResponseEvent.MiniAppShare]: MiniAppSharePayload;
|
|
482
517
|
};
|
|
483
518
|
type EventPayload<T extends ResponseEvent = ResponseEvent> = T extends keyof EventPayloadMap ? EventPayloadMap[T] : never;
|
|
484
519
|
type EventHandler<E extends ResponseEvent = ResponseEvent> = <T extends EventPayload<E>>(data: T) => void;
|
|
485
520
|
|
|
486
|
-
type User = {
|
|
487
|
-
walletAddress?: string;
|
|
488
|
-
username?: string;
|
|
489
|
-
profilePictureUrl?: string;
|
|
490
|
-
permissions?: {
|
|
491
|
-
notifications: boolean;
|
|
492
|
-
contacts: boolean;
|
|
493
|
-
};
|
|
494
|
-
optedIntoOptionalAnalytics?: boolean;
|
|
495
|
-
worldAppVersion?: number;
|
|
496
|
-
deviceOS?: string;
|
|
497
|
-
};
|
|
498
|
-
type UserNameService = {
|
|
499
|
-
walletAddress: string;
|
|
500
|
-
username?: string;
|
|
501
|
-
profilePictureUrl?: string;
|
|
502
|
-
};
|
|
503
|
-
|
|
504
521
|
declare class MiniKit {
|
|
505
522
|
private static readonly MINIKIT_VERSION;
|
|
506
523
|
private static readonly miniKitCommandVersion;
|
|
@@ -509,6 +526,7 @@ declare class MiniKit {
|
|
|
509
526
|
static appId: string | null;
|
|
510
527
|
static user: User;
|
|
511
528
|
private static isReady;
|
|
529
|
+
static deviceProperties: DeviceProperties;
|
|
512
530
|
private static sendInit;
|
|
513
531
|
static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
|
|
514
532
|
static unsubscribe(event: ResponseEvent): void;
|
|
@@ -531,6 +549,7 @@ declare class MiniKit {
|
|
|
531
549
|
requestPermission: (payload: RequestPermissionInput) => RequestPermissionPayload | null;
|
|
532
550
|
getPermissions: () => GetPermissionsPayload | null;
|
|
533
551
|
sendHapticFeedback: (payload: SendHapticFeedbackInput) => SendHapticFeedbackPayload | null;
|
|
552
|
+
share: (payload: ShareInput) => ShareInput | null;
|
|
534
553
|
};
|
|
535
554
|
/**
|
|
536
555
|
* This object contains async versions of all the commands.
|
|
@@ -553,6 +572,7 @@ declare class MiniKit {
|
|
|
553
572
|
requestPermission: (payload: RequestPermissionInput) => AsyncHandlerReturn<RequestPermissionPayload | null, MiniAppRequestPermissionPayload>;
|
|
554
573
|
getPermissions: () => AsyncHandlerReturn<GetPermissionsPayload | null, MiniAppGetPermissionsPayload>;
|
|
555
574
|
sendHapticFeedback: (payload: SendHapticFeedbackInput) => AsyncHandlerReturn<SendHapticFeedbackPayload | null, MiniAppSendHapticFeedbackPayload>;
|
|
575
|
+
share: (payload: ShareInput) => AsyncHandlerReturn<ShareInput | null, MiniAppSharePayload>;
|
|
556
576
|
};
|
|
557
577
|
}
|
|
558
578
|
|
|
@@ -581,4 +601,4 @@ declare const verifySiweMessage: (payload: MiniAppWalletAuthSuccessPayload, nonc
|
|
|
581
601
|
|
|
582
602
|
declare const getIsUserVerified: (walletAddress: string, rpcUrl?: string) => Promise<boolean>;
|
|
583
603
|
|
|
584
|
-
export { type AsyncHandlerReturn, Command, type CommandReturnPayload, type Contact, type EventHandler, type EventPayload, GetPermissionsErrorCodes, GetPermissionsErrorMessage, type GetPermissionsInput, type GetPermissionsPayload, type MiniAppGetPermissionsErrorPayload, type MiniAppGetPermissionsPayload, type MiniAppGetPermissionsSuccessPayload, type MiniAppPaymentErrorPayload, type MiniAppPaymentPayload, type MiniAppPaymentSuccessPayload, type MiniAppRequestPermissionErrorPayload, type MiniAppRequestPermissionPayload, type MiniAppRequestPermissionSuccessPayload, type MiniAppSendHapticFeedbackErrorPayload, type MiniAppSendHapticFeedbackPayload, type MiniAppSendHapticFeedbackSuccessPayload, type MiniAppSendTransactionErrorPayload, type MiniAppSendTransactionPayload, type MiniAppSendTransactionSuccessPayload, type MiniAppShareContactsErrorPayload, type MiniAppShareContactsPayload, type MiniAppShareContactsSuccessPayload, type
|
|
604
|
+
export { type AsyncHandlerReturn, Command, type CommandReturnPayload, type Contact, type DeviceProperties, type EventHandler, type EventPayload, GetPermissionsErrorCodes, GetPermissionsErrorMessage, type GetPermissionsInput, type GetPermissionsPayload, type MiniAppGetPermissionsErrorPayload, type MiniAppGetPermissionsPayload, type MiniAppGetPermissionsSuccessPayload, type MiniAppPaymentErrorPayload, type MiniAppPaymentPayload, type MiniAppPaymentSuccessPayload, type MiniAppRequestPermissionErrorPayload, type MiniAppRequestPermissionPayload, type MiniAppRequestPermissionSuccessPayload, type MiniAppSendHapticFeedbackErrorPayload, type MiniAppSendHapticFeedbackPayload, type MiniAppSendHapticFeedbackSuccessPayload, type MiniAppSendTransactionErrorPayload, type MiniAppSendTransactionPayload, type MiniAppSendTransactionSuccessPayload, type MiniAppShareContactsErrorPayload, type MiniAppShareContactsPayload, type MiniAppShareContactsSuccessPayload, type MiniAppShareErrorPayload, type MiniAppSharePayload, type MiniAppShareSuccessPayload, 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, Permission, type PermissionSettings, RequestPermissionErrorCodes, RequestPermissionErrorMessage, type RequestPermissionInput, type RequestPermissionPayload, ResponseEvent, SendHapticFeedbackErrorCodes, SendHapticFeedbackErrorMessage, type SendHapticFeedbackInput, type SendHapticFeedbackPayload, SendTransactionErrorCodes, SendTransactionErrorMessage, type SendTransactionInput, type SendTransactionPayload, ShareContactsErrorCodes, ShareContactsErrorMessage, type ShareContactsInput, type ShareContactsPayload, ShareFilesErrorCodes, ShareFilesErrorMessage, type ShareInput, type SharePayload, SignMessageErrorCodes, SignMessageErrorMessage, type SignMessageInput, type SignMessagePayload, SignTypedDataErrorCodes, SignTypedDataErrorMessage, type SignTypedDataInput, type SignTypedDataPayload, type SiweMessage, TokenDecimals, Tokens, type TokensPayload, type User, type UserNameService, VerificationErrorMessage, type VerifyCommandInput, type VerifyCommandPayload, WalletAuthErrorCodes, WalletAuthErrorMessage, type WalletAuthInput, type WalletAuthPayload, type WebViewBasePayload, getIsUserVerified, parseSiweMessage, tokenToDecimals, verifySiweMessage };
|
package/build/index.d.ts
CHANGED
|
@@ -181,7 +181,8 @@ declare enum Command {
|
|
|
181
181
|
ShareContacts = "share-contacts",
|
|
182
182
|
RequestPermission = "request-permission",
|
|
183
183
|
GetPermissions = "get-permissions",
|
|
184
|
-
SendHapticFeedback = "send-haptic-feedback"
|
|
184
|
+
SendHapticFeedback = "send-haptic-feedback",
|
|
185
|
+
Share = "share"
|
|
185
186
|
}
|
|
186
187
|
type WebViewBasePayload = {
|
|
187
188
|
command: Command;
|
|
@@ -273,15 +274,22 @@ type SendHapticFeedbackInput = {
|
|
|
273
274
|
style: 'light' | 'medium' | 'heavy';
|
|
274
275
|
};
|
|
275
276
|
type SendHapticFeedbackPayload = SendHapticFeedbackInput;
|
|
276
|
-
type
|
|
277
|
-
|
|
278
|
-
|
|
277
|
+
type ShareInput = {
|
|
278
|
+
files?: File[];
|
|
279
|
+
title?: string;
|
|
280
|
+
text?: string;
|
|
281
|
+
url?: string;
|
|
282
|
+
};
|
|
283
|
+
type SharePayload = {
|
|
284
|
+
files?: Array<{
|
|
285
|
+
name: string;
|
|
286
|
+
type: string;
|
|
287
|
+
data: string;
|
|
288
|
+
}>;
|
|
289
|
+
title?: string;
|
|
290
|
+
text?: string;
|
|
291
|
+
url?: string;
|
|
279
292
|
};
|
|
280
|
-
type ShareFilesInput = {
|
|
281
|
-
files: ShareFile[];
|
|
282
|
-
mime_type: string;
|
|
283
|
-
};
|
|
284
|
-
type ShareFilesPayload = ShareFilesInput;
|
|
285
293
|
type CommandReturnPayloadMap = {
|
|
286
294
|
[Command.Verify]: VerifyCommandPayload;
|
|
287
295
|
[Command.Pay]: PayCommandPayload;
|
|
@@ -293,9 +301,36 @@ type CommandReturnPayloadMap = {
|
|
|
293
301
|
[Command.RequestPermission]: RequestPermissionPayload;
|
|
294
302
|
[Command.GetPermissions]: GetPermissionsPayload;
|
|
295
303
|
[Command.SendHapticFeedback]: SendHapticFeedbackPayload;
|
|
304
|
+
[Command.Share]: SharePayload;
|
|
296
305
|
};
|
|
297
306
|
type CommandReturnPayload<T extends Command> = T extends keyof CommandReturnPayloadMap ? CommandReturnPayloadMap[T] : never;
|
|
298
307
|
|
|
308
|
+
type User = {
|
|
309
|
+
walletAddress?: string;
|
|
310
|
+
username?: string;
|
|
311
|
+
profilePictureUrl?: string;
|
|
312
|
+
permissions?: {
|
|
313
|
+
notifications: boolean;
|
|
314
|
+
contacts: boolean;
|
|
315
|
+
};
|
|
316
|
+
optedIntoOptionalAnalytics?: boolean;
|
|
317
|
+
worldAppVersion?: number;
|
|
318
|
+
deviceOS?: string;
|
|
319
|
+
};
|
|
320
|
+
type DeviceProperties = {
|
|
321
|
+
safeAreaInsets?: {
|
|
322
|
+
top: number;
|
|
323
|
+
right: number;
|
|
324
|
+
bottom: number;
|
|
325
|
+
left: number;
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
type UserNameService = {
|
|
329
|
+
walletAddress: string;
|
|
330
|
+
username?: string;
|
|
331
|
+
profilePictureUrl?: string;
|
|
332
|
+
};
|
|
333
|
+
|
|
299
334
|
declare enum ResponseEvent {
|
|
300
335
|
MiniAppVerifyAction = "miniapp-verify-action",
|
|
301
336
|
MiniAppPayment = "miniapp-payment",
|
|
@@ -307,7 +342,7 @@ declare enum ResponseEvent {
|
|
|
307
342
|
MiniAppRequestPermission = "miniapp-request-permission",
|
|
308
343
|
MiniAppGetPermissions = "miniapp-get-permissions",
|
|
309
344
|
MiniAppSendHapticFeedback = "miniapp-send-haptic-feedback",
|
|
310
|
-
|
|
345
|
+
MiniAppShare = "miniapp-share"
|
|
311
346
|
}
|
|
312
347
|
type MiniAppVerifyActionSuccessPayload = {
|
|
313
348
|
status: 'success';
|
|
@@ -455,18 +490,18 @@ type MiniAppSendHapticFeedbackErrorPayload = {
|
|
|
455
490
|
version: number;
|
|
456
491
|
};
|
|
457
492
|
type MiniAppSendHapticFeedbackPayload = MiniAppSendHapticFeedbackSuccessPayload | MiniAppSendHapticFeedbackErrorPayload;
|
|
458
|
-
type
|
|
493
|
+
type MiniAppShareSuccessPayload = {
|
|
459
494
|
status: 'success';
|
|
460
495
|
shared_files_count: number;
|
|
461
496
|
version: number;
|
|
462
497
|
timestamp: string;
|
|
463
498
|
};
|
|
464
|
-
type
|
|
499
|
+
type MiniAppShareErrorPayload = {
|
|
465
500
|
status: 'error';
|
|
466
501
|
error_code: ShareFilesErrorCodes;
|
|
467
502
|
version: number;
|
|
468
503
|
};
|
|
469
|
-
type
|
|
504
|
+
type MiniAppSharePayload = MiniAppShareSuccessPayload | MiniAppShareErrorPayload;
|
|
470
505
|
type EventPayloadMap = {
|
|
471
506
|
[ResponseEvent.MiniAppVerifyAction]: MiniAppVerifyActionPayload;
|
|
472
507
|
[ResponseEvent.MiniAppPayment]: MiniAppPaymentPayload;
|
|
@@ -478,29 +513,11 @@ type EventPayloadMap = {
|
|
|
478
513
|
[ResponseEvent.MiniAppRequestPermission]: MiniAppRequestPermissionPayload;
|
|
479
514
|
[ResponseEvent.MiniAppGetPermissions]: MiniAppGetPermissionsPayload;
|
|
480
515
|
[ResponseEvent.MiniAppSendHapticFeedback]: MiniAppSendHapticFeedbackPayload;
|
|
481
|
-
[ResponseEvent.
|
|
516
|
+
[ResponseEvent.MiniAppShare]: MiniAppSharePayload;
|
|
482
517
|
};
|
|
483
518
|
type EventPayload<T extends ResponseEvent = ResponseEvent> = T extends keyof EventPayloadMap ? EventPayloadMap[T] : never;
|
|
484
519
|
type EventHandler<E extends ResponseEvent = ResponseEvent> = <T extends EventPayload<E>>(data: T) => void;
|
|
485
520
|
|
|
486
|
-
type User = {
|
|
487
|
-
walletAddress?: string;
|
|
488
|
-
username?: string;
|
|
489
|
-
profilePictureUrl?: string;
|
|
490
|
-
permissions?: {
|
|
491
|
-
notifications: boolean;
|
|
492
|
-
contacts: boolean;
|
|
493
|
-
};
|
|
494
|
-
optedIntoOptionalAnalytics?: boolean;
|
|
495
|
-
worldAppVersion?: number;
|
|
496
|
-
deviceOS?: string;
|
|
497
|
-
};
|
|
498
|
-
type UserNameService = {
|
|
499
|
-
walletAddress: string;
|
|
500
|
-
username?: string;
|
|
501
|
-
profilePictureUrl?: string;
|
|
502
|
-
};
|
|
503
|
-
|
|
504
521
|
declare class MiniKit {
|
|
505
522
|
private static readonly MINIKIT_VERSION;
|
|
506
523
|
private static readonly miniKitCommandVersion;
|
|
@@ -509,6 +526,7 @@ declare class MiniKit {
|
|
|
509
526
|
static appId: string | null;
|
|
510
527
|
static user: User;
|
|
511
528
|
private static isReady;
|
|
529
|
+
static deviceProperties: DeviceProperties;
|
|
512
530
|
private static sendInit;
|
|
513
531
|
static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
|
|
514
532
|
static unsubscribe(event: ResponseEvent): void;
|
|
@@ -531,6 +549,7 @@ declare class MiniKit {
|
|
|
531
549
|
requestPermission: (payload: RequestPermissionInput) => RequestPermissionPayload | null;
|
|
532
550
|
getPermissions: () => GetPermissionsPayload | null;
|
|
533
551
|
sendHapticFeedback: (payload: SendHapticFeedbackInput) => SendHapticFeedbackPayload | null;
|
|
552
|
+
share: (payload: ShareInput) => ShareInput | null;
|
|
534
553
|
};
|
|
535
554
|
/**
|
|
536
555
|
* This object contains async versions of all the commands.
|
|
@@ -553,6 +572,7 @@ declare class MiniKit {
|
|
|
553
572
|
requestPermission: (payload: RequestPermissionInput) => AsyncHandlerReturn<RequestPermissionPayload | null, MiniAppRequestPermissionPayload>;
|
|
554
573
|
getPermissions: () => AsyncHandlerReturn<GetPermissionsPayload | null, MiniAppGetPermissionsPayload>;
|
|
555
574
|
sendHapticFeedback: (payload: SendHapticFeedbackInput) => AsyncHandlerReturn<SendHapticFeedbackPayload | null, MiniAppSendHapticFeedbackPayload>;
|
|
575
|
+
share: (payload: ShareInput) => AsyncHandlerReturn<ShareInput | null, MiniAppSharePayload>;
|
|
556
576
|
};
|
|
557
577
|
}
|
|
558
578
|
|
|
@@ -581,4 +601,4 @@ declare const verifySiweMessage: (payload: MiniAppWalletAuthSuccessPayload, nonc
|
|
|
581
601
|
|
|
582
602
|
declare const getIsUserVerified: (walletAddress: string, rpcUrl?: string) => Promise<boolean>;
|
|
583
603
|
|
|
584
|
-
export { type AsyncHandlerReturn, Command, type CommandReturnPayload, type Contact, type EventHandler, type EventPayload, GetPermissionsErrorCodes, GetPermissionsErrorMessage, type GetPermissionsInput, type GetPermissionsPayload, type MiniAppGetPermissionsErrorPayload, type MiniAppGetPermissionsPayload, type MiniAppGetPermissionsSuccessPayload, type MiniAppPaymentErrorPayload, type MiniAppPaymentPayload, type MiniAppPaymentSuccessPayload, type MiniAppRequestPermissionErrorPayload, type MiniAppRequestPermissionPayload, type MiniAppRequestPermissionSuccessPayload, type MiniAppSendHapticFeedbackErrorPayload, type MiniAppSendHapticFeedbackPayload, type MiniAppSendHapticFeedbackSuccessPayload, type MiniAppSendTransactionErrorPayload, type MiniAppSendTransactionPayload, type MiniAppSendTransactionSuccessPayload, type MiniAppShareContactsErrorPayload, type MiniAppShareContactsPayload, type MiniAppShareContactsSuccessPayload, type
|
|
604
|
+
export { type AsyncHandlerReturn, Command, type CommandReturnPayload, type Contact, type DeviceProperties, type EventHandler, type EventPayload, GetPermissionsErrorCodes, GetPermissionsErrorMessage, type GetPermissionsInput, type GetPermissionsPayload, type MiniAppGetPermissionsErrorPayload, type MiniAppGetPermissionsPayload, type MiniAppGetPermissionsSuccessPayload, type MiniAppPaymentErrorPayload, type MiniAppPaymentPayload, type MiniAppPaymentSuccessPayload, type MiniAppRequestPermissionErrorPayload, type MiniAppRequestPermissionPayload, type MiniAppRequestPermissionSuccessPayload, type MiniAppSendHapticFeedbackErrorPayload, type MiniAppSendHapticFeedbackPayload, type MiniAppSendHapticFeedbackSuccessPayload, type MiniAppSendTransactionErrorPayload, type MiniAppSendTransactionPayload, type MiniAppSendTransactionSuccessPayload, type MiniAppShareContactsErrorPayload, type MiniAppShareContactsPayload, type MiniAppShareContactsSuccessPayload, type MiniAppShareErrorPayload, type MiniAppSharePayload, type MiniAppShareSuccessPayload, 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, Permission, type PermissionSettings, RequestPermissionErrorCodes, RequestPermissionErrorMessage, type RequestPermissionInput, type RequestPermissionPayload, ResponseEvent, SendHapticFeedbackErrorCodes, SendHapticFeedbackErrorMessage, type SendHapticFeedbackInput, type SendHapticFeedbackPayload, SendTransactionErrorCodes, SendTransactionErrorMessage, type SendTransactionInput, type SendTransactionPayload, ShareContactsErrorCodes, ShareContactsErrorMessage, type ShareContactsInput, type ShareContactsPayload, ShareFilesErrorCodes, ShareFilesErrorMessage, type ShareInput, type SharePayload, SignMessageErrorCodes, SignMessageErrorMessage, type SignMessageInput, type SignMessagePayload, SignTypedDataErrorCodes, SignTypedDataErrorMessage, type SignTypedDataInput, type SignTypedDataPayload, type SiweMessage, TokenDecimals, Tokens, type TokensPayload, type User, type UserNameService, VerificationErrorMessage, type VerifyCommandInput, type VerifyCommandPayload, WalletAuthErrorCodes, WalletAuthErrorMessage, type WalletAuthInput, type WalletAuthPayload, type WebViewBasePayload, getIsUserVerified, parseSiweMessage, tokenToDecimals, verifySiweMessage };
|
package/build/index.js
CHANGED
|
@@ -99,6 +99,72 @@ var compressAndPadProof = async (proof, rpcUrl) => {
|
|
|
99
99
|
}
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
+
// helpers/share/index.ts
|
|
103
|
+
var MAX_FILES = 10;
|
|
104
|
+
var MAX_TOTAL_SIZE_MB = 50;
|
|
105
|
+
var MAX_TOTAL_SIZE_BYTES = MAX_TOTAL_SIZE_MB * 1024 * 1024;
|
|
106
|
+
var processFile = async (file) => {
|
|
107
|
+
const buffer = await file.arrayBuffer();
|
|
108
|
+
const uint8Array = new Uint8Array(buffer);
|
|
109
|
+
let binaryString = "";
|
|
110
|
+
const K_CHUNK_SIZE = 32768;
|
|
111
|
+
for (let i = 0; i < uint8Array.length; i += K_CHUNK_SIZE) {
|
|
112
|
+
const chunk = uint8Array.subarray(
|
|
113
|
+
i,
|
|
114
|
+
Math.min(i + K_CHUNK_SIZE, uint8Array.length)
|
|
115
|
+
);
|
|
116
|
+
binaryString += String.fromCharCode.apply(
|
|
117
|
+
null,
|
|
118
|
+
Array.from(chunk)
|
|
119
|
+
// Convert Uint8Array chunk to number[]
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
const base64Data = btoa(binaryString);
|
|
123
|
+
return {
|
|
124
|
+
name: file.name,
|
|
125
|
+
type: file.type,
|
|
126
|
+
data: base64Data
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
var formatShareInput = async (input) => {
|
|
130
|
+
if (!input.files) {
|
|
131
|
+
return {
|
|
132
|
+
title: input.title,
|
|
133
|
+
text: input.text,
|
|
134
|
+
url: input.url
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
if (!Array.isArray(input.files)) {
|
|
138
|
+
throw new Error('The "files" property must be an array.');
|
|
139
|
+
}
|
|
140
|
+
if (input.files.length === 0) {
|
|
141
|
+
} else {
|
|
142
|
+
if (input.files.length > MAX_FILES) {
|
|
143
|
+
throw new Error(`Cannot share more than ${MAX_FILES} files.`);
|
|
144
|
+
}
|
|
145
|
+
let totalSize = 0;
|
|
146
|
+
for (const file of input.files) {
|
|
147
|
+
if (!(file instanceof File)) {
|
|
148
|
+
throw new Error(
|
|
149
|
+
`Each item in the 'files' array must be a File object. Received: ${typeof file}`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
totalSize += file.size;
|
|
153
|
+
}
|
|
154
|
+
if (totalSize > MAX_TOTAL_SIZE_BYTES) {
|
|
155
|
+
throw new Error(`Total file size cannot exceed ${MAX_TOTAL_SIZE_MB}MB.`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const fileProcessingPromises = input.files.map((file) => processFile(file));
|
|
159
|
+
const processedFiles = await Promise.all(fileProcessingPromises);
|
|
160
|
+
return {
|
|
161
|
+
files: processedFiles,
|
|
162
|
+
title: input.title,
|
|
163
|
+
text: input.text,
|
|
164
|
+
url: input.url
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
|
|
102
168
|
// helpers/siwe/siwe.ts
|
|
103
169
|
var import_viem2 = require("viem");
|
|
104
170
|
var import_chains2 = require("viem/chains");
|
|
@@ -369,6 +435,7 @@ var _MiniKit = class _MiniKit {
|
|
|
369
435
|
_MiniKit.isCommandAvailable[minikitCommandName] = true;
|
|
370
436
|
isCommandValid = true;
|
|
371
437
|
} else {
|
|
438
|
+
isCommandValid = true;
|
|
372
439
|
console.warn(
|
|
373
440
|
`Command ${minikitCommandName} version ${version} is not supported by the app. Supported versions: ${commandInput.supported_versions.join(", ")}. This is not an error, but it is recommended to update the World App version.`
|
|
374
441
|
);
|
|
@@ -405,6 +472,7 @@ var _MiniKit = class _MiniKit {
|
|
|
405
472
|
_MiniKit.user.optedIntoOptionalAnalytics = window.WorldApp.is_optional_analytics;
|
|
406
473
|
_MiniKit.user.deviceOS = window.WorldApp.device_os;
|
|
407
474
|
_MiniKit.user.worldAppVersion = window.WorldApp.world_app_version;
|
|
475
|
+
_MiniKit.deviceProperties.safeAreaInsets = window.WorldApp.safe_area_insets;
|
|
408
476
|
try {
|
|
409
477
|
window.MiniKit = _MiniKit;
|
|
410
478
|
this.sendInit();
|
|
@@ -450,8 +518,8 @@ _MiniKit.miniKitCommandVersion = {
|
|
|
450
518
|
["share-contacts" /* ShareContacts */]: 1,
|
|
451
519
|
["request-permission" /* RequestPermission */]: 1,
|
|
452
520
|
["get-permissions" /* GetPermissions */]: 1,
|
|
453
|
-
["send-haptic-feedback" /* SendHapticFeedback */]: 1
|
|
454
|
-
|
|
521
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: 1,
|
|
522
|
+
["share" /* Share */]: 1
|
|
455
523
|
};
|
|
456
524
|
_MiniKit.isCommandAvailable = {
|
|
457
525
|
["verify" /* Verify */]: false,
|
|
@@ -463,8 +531,8 @@ _MiniKit.isCommandAvailable = {
|
|
|
463
531
|
["share-contacts" /* ShareContacts */]: false,
|
|
464
532
|
["request-permission" /* RequestPermission */]: false,
|
|
465
533
|
["get-permissions" /* GetPermissions */]: false,
|
|
466
|
-
["send-haptic-feedback" /* SendHapticFeedback */]: false
|
|
467
|
-
|
|
534
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: false,
|
|
535
|
+
["share" /* Share */]: false
|
|
468
536
|
};
|
|
469
537
|
_MiniKit.listeners = {
|
|
470
538
|
["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
|
|
@@ -487,12 +555,13 @@ _MiniKit.listeners = {
|
|
|
487
555
|
},
|
|
488
556
|
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
489
557
|
},
|
|
490
|
-
["miniapp-share
|
|
558
|
+
["miniapp-share" /* MiniAppShare */]: () => {
|
|
491
559
|
}
|
|
492
560
|
};
|
|
493
561
|
_MiniKit.appId = null;
|
|
494
562
|
_MiniKit.user = {};
|
|
495
563
|
_MiniKit.isReady = false;
|
|
564
|
+
_MiniKit.deviceProperties = {};
|
|
496
565
|
_MiniKit.getUserByAddress = async (address) => {
|
|
497
566
|
const userProfile = await getUserProfile(
|
|
498
567
|
address ?? _MiniKit.user.walletAddress
|
|
@@ -658,7 +727,7 @@ _MiniKit.commands = {
|
|
|
658
727
|
return payload;
|
|
659
728
|
},
|
|
660
729
|
shareContacts: (payload) => {
|
|
661
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["
|
|
730
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["share-contacts" /* ShareContacts */]) {
|
|
662
731
|
console.error(
|
|
663
732
|
"'shareContacts' command is unavailable. Check MiniKit.install() or update the app version"
|
|
664
733
|
);
|
|
@@ -714,24 +783,33 @@ _MiniKit.commands = {
|
|
|
714
783
|
payload
|
|
715
784
|
});
|
|
716
785
|
return payload;
|
|
786
|
+
},
|
|
787
|
+
// We return share input here because the payload is formatted asynchronously
|
|
788
|
+
share: (payload) => {
|
|
789
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["share" /* Share */]) {
|
|
790
|
+
console.error(
|
|
791
|
+
"'share' command is unavailable. Check MiniKit.install() or update the app version"
|
|
792
|
+
);
|
|
793
|
+
return null;
|
|
794
|
+
}
|
|
795
|
+
if (_MiniKit.user.deviceOS === "ios") {
|
|
796
|
+
navigator.share(payload);
|
|
797
|
+
} else {
|
|
798
|
+
formatShareInput(payload).then((formattedResult) => {
|
|
799
|
+
sendMiniKitEvent({
|
|
800
|
+
command: "share" /* Share */,
|
|
801
|
+
version: _MiniKit.miniKitCommandVersion["share" /* Share */],
|
|
802
|
+
payload: formattedResult
|
|
803
|
+
});
|
|
804
|
+
}).catch((error) => {
|
|
805
|
+
console.error("Failed to format share input", error);
|
|
806
|
+
});
|
|
807
|
+
_MiniKit.subscribe("miniapp-share" /* MiniAppShare */, (payload2) => {
|
|
808
|
+
console.log("Share Response", payload2);
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
return payload;
|
|
717
812
|
}
|
|
718
|
-
// shareFiles: (payload: ShareFilesInput): ShareFilesPayload | null => {
|
|
719
|
-
// if (
|
|
720
|
-
// typeof window === 'undefined' ||
|
|
721
|
-
// !this.isCommandAvailable[Command.ShareFiles]
|
|
722
|
-
// ) {
|
|
723
|
-
// console.error(
|
|
724
|
-
// "'shareFiles' command is unavailable. Check MiniKit.install() or update the app version",
|
|
725
|
-
// );
|
|
726
|
-
// return null;
|
|
727
|
-
// }
|
|
728
|
-
// sendMiniKitEvent<WebViewBasePayload>({
|
|
729
|
-
// command: Command.ShareFiles,
|
|
730
|
-
// version: this.miniKitCommandVersion[Command.ShareFiles],
|
|
731
|
-
// payload,
|
|
732
|
-
// });
|
|
733
|
-
// return payload;
|
|
734
|
-
// },
|
|
735
813
|
};
|
|
736
814
|
/**
|
|
737
815
|
* This object contains async versions of all the commands.
|
|
@@ -888,26 +966,24 @@ _MiniKit.commandsAsync = {
|
|
|
888
966
|
reject(error);
|
|
889
967
|
}
|
|
890
968
|
});
|
|
969
|
+
},
|
|
970
|
+
share: async (payload) => {
|
|
971
|
+
return new Promise(async (resolve, reject) => {
|
|
972
|
+
try {
|
|
973
|
+
const response = await _MiniKit.awaitCommand(
|
|
974
|
+
"miniapp-share" /* MiniAppShare */,
|
|
975
|
+
"share" /* Share */,
|
|
976
|
+
() => _MiniKit.commands.share(payload)
|
|
977
|
+
);
|
|
978
|
+
resolve({
|
|
979
|
+
commandPayload: response.commandPayload,
|
|
980
|
+
finalPayload: response.finalPayload
|
|
981
|
+
});
|
|
982
|
+
} catch (error) {
|
|
983
|
+
reject(error);
|
|
984
|
+
}
|
|
985
|
+
});
|
|
891
986
|
}
|
|
892
|
-
// shareFiles: async (
|
|
893
|
-
// payload: ShareFilesInput,
|
|
894
|
-
// ): AsyncHandlerReturn<
|
|
895
|
-
// ShareFilesPayload | null,
|
|
896
|
-
// MiniAppShareFilesPayload
|
|
897
|
-
// > => {
|
|
898
|
-
// return new Promise(async (resolve, reject) => {
|
|
899
|
-
// try {
|
|
900
|
-
// const response = await MiniKit.awaitCommand(
|
|
901
|
-
// ResponseEvent.MiniAppShareFiles,
|
|
902
|
-
// Command.ShareFiles,
|
|
903
|
-
// () => this.commands.shareFiles(payload),
|
|
904
|
-
// );
|
|
905
|
-
// resolve(response);
|
|
906
|
-
// } catch (error) {
|
|
907
|
-
// reject(error);
|
|
908
|
-
// }
|
|
909
|
-
// });
|
|
910
|
-
// },
|
|
911
987
|
};
|
|
912
988
|
var MiniKit = _MiniKit;
|
|
913
989
|
|
package/index.ts
CHANGED
|
@@ -2,9 +2,9 @@ export { MiniKit } from './minikit';
|
|
|
2
2
|
|
|
3
3
|
export * from './types/commands';
|
|
4
4
|
export * from './types/errors';
|
|
5
|
+
export * from './types/init';
|
|
5
6
|
export * from './types/payment';
|
|
6
7
|
export * from './types/responses';
|
|
7
|
-
export * from './types/user';
|
|
8
8
|
export * from './types/wallet-auth';
|
|
9
9
|
|
|
10
10
|
export { tokenToDecimals } from 'helpers/payment/client';
|