@frak-labs/core-sdk 0.0.19 → 0.1.0-beta.8d103039
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/cdn/bundle.js +5 -5
- package/dist/actions.cjs +1 -1
- package/dist/actions.d.cts +154 -73
- package/dist/actions.d.ts +154 -73
- package/dist/actions.js +1 -1
- package/dist/bundle.cjs +2 -2
- package/dist/bundle.d.cts +257 -192
- package/dist/bundle.d.ts +257 -192
- package/dist/bundle.js +2 -2
- package/dist/index.cjs +11 -11
- package/dist/index.d.cts +199 -185
- package/dist/index.d.ts +199 -185
- package/dist/index.js +2 -2
- package/package.json +7 -2
- package/src/actions/displayEmbeddedWallet.ts +20 -0
- package/src/actions/displayModal.ts +131 -0
- package/src/actions/getProductInformation.ts +14 -0
- package/src/actions/index.ts +29 -0
- package/src/actions/openSso.ts +116 -0
- package/src/actions/prepareSso.ts +48 -0
- package/src/actions/referral/processReferral.ts +230 -0
- package/src/actions/referral/referralInteraction.ts +57 -0
- package/src/actions/sendInteraction.ts +32 -0
- package/src/actions/trackPurchaseStatus.ts +53 -0
- package/src/actions/watchWalletStatus.ts +94 -0
- package/src/actions/wrapper/modalBuilder.ts +212 -0
- package/src/actions/wrapper/sendTransaction.ts +62 -0
- package/src/actions/wrapper/siweAuthenticate.ts +94 -0
- package/src/bundle.ts +3 -0
- package/src/clients/DebugInfo.ts +182 -0
- package/src/clients/createIFrameFrakClient.ts +287 -0
- package/src/clients/index.ts +3 -0
- package/src/clients/setupClient.ts +71 -0
- package/src/clients/transports/iframeLifecycleManager.ts +88 -0
- package/src/constants/interactionTypes.ts +44 -0
- package/src/constants/locales.ts +14 -0
- package/src/constants/productTypes.ts +33 -0
- package/src/index.ts +103 -0
- package/src/interactions/index.ts +5 -0
- package/src/interactions/pressEncoder.ts +53 -0
- package/src/interactions/purchaseEncoder.ts +94 -0
- package/src/interactions/referralEncoder.ts +47 -0
- package/src/interactions/retailEncoder.ts +37 -0
- package/src/interactions/webshopEncoder.ts +30 -0
- package/src/types/client.ts +14 -0
- package/src/types/compression.ts +22 -0
- package/src/types/config.ts +111 -0
- package/src/types/context.ts +13 -0
- package/src/types/index.ts +70 -0
- package/src/types/lifecycle/client.ts +46 -0
- package/src/types/lifecycle/iframe.ts +35 -0
- package/src/types/lifecycle/index.ts +2 -0
- package/src/types/rpc/displayModal.ts +84 -0
- package/src/types/rpc/embedded/index.ts +68 -0
- package/src/types/rpc/embedded/loggedIn.ts +55 -0
- package/src/types/rpc/embedded/loggedOut.ts +28 -0
- package/src/types/rpc/interaction.ts +43 -0
- package/src/types/rpc/modal/final.ts +46 -0
- package/src/types/rpc/modal/generic.ts +46 -0
- package/src/types/rpc/modal/index.ts +20 -0
- package/src/types/rpc/modal/login.ts +32 -0
- package/src/types/rpc/modal/openSession.ts +25 -0
- package/src/types/rpc/modal/siweAuthenticate.ts +37 -0
- package/src/types/rpc/modal/transaction.ts +33 -0
- package/src/types/rpc/productInformation.ts +59 -0
- package/src/types/rpc/sso.ts +80 -0
- package/src/types/rpc/walletStatus.ts +35 -0
- package/src/types/rpc.ts +158 -0
- package/src/types/transport.ts +34 -0
- package/src/utils/FrakContext.ts +152 -0
- package/src/utils/compression/b64.ts +29 -0
- package/src/utils/compression/compress.ts +11 -0
- package/src/utils/compression/decompress.ts +11 -0
- package/src/utils/compression/index.ts +3 -0
- package/src/utils/computeProductId.ts +11 -0
- package/src/utils/constants.ts +4 -0
- package/src/utils/formatAmount.ts +18 -0
- package/src/utils/getCurrencyAmountKey.ts +15 -0
- package/src/utils/getSupportedCurrency.ts +14 -0
- package/src/utils/getSupportedLocale.ts +16 -0
- package/src/utils/iframeHelper.ts +142 -0
- package/src/utils/index.ts +21 -0
- package/src/utils/sso.ts +119 -0
- package/src/utils/ssoUrlListener.ts +60 -0
- package/src/utils/trackEvent.ts +26 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Deferred } from "@frak-labs/frame-connector";
|
|
2
|
+
import type { FrakLifecycleEvent } from "../../types";
|
|
3
|
+
import { BACKUP_KEY } from "../../utils/constants";
|
|
4
|
+
import { changeIframeVisibility } from "../../utils/iframeHelper";
|
|
5
|
+
|
|
6
|
+
/** @ignore */
|
|
7
|
+
export type IframeLifecycleManager = {
|
|
8
|
+
isConnected: Promise<boolean>;
|
|
9
|
+
handleEvent: (messageEvent: FrakLifecycleEvent) => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create a new iframe lifecycle handler
|
|
14
|
+
* @ignore
|
|
15
|
+
*/
|
|
16
|
+
export function createIFrameLifecycleManager({
|
|
17
|
+
iframe,
|
|
18
|
+
}: { iframe: HTMLIFrameElement }): IframeLifecycleManager {
|
|
19
|
+
// Create the isConnected listener
|
|
20
|
+
const isConnectedDeferred = new Deferred<boolean>();
|
|
21
|
+
|
|
22
|
+
// Build the handler itself
|
|
23
|
+
const handler = async (messageEvent: FrakLifecycleEvent) => {
|
|
24
|
+
if (!("iframeLifecycle" in messageEvent)) return;
|
|
25
|
+
|
|
26
|
+
const { iframeLifecycle: event, data } = messageEvent;
|
|
27
|
+
|
|
28
|
+
switch (event) {
|
|
29
|
+
// Resolve the isConnected promise
|
|
30
|
+
case "connected":
|
|
31
|
+
isConnectedDeferred.resolve(true);
|
|
32
|
+
break;
|
|
33
|
+
// Perform a frak backup
|
|
34
|
+
case "do-backup":
|
|
35
|
+
if (data.backup) {
|
|
36
|
+
localStorage.setItem(BACKUP_KEY, data.backup);
|
|
37
|
+
} else {
|
|
38
|
+
localStorage.removeItem(BACKUP_KEY);
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
// Remove frak backup
|
|
42
|
+
case "remove-backup":
|
|
43
|
+
localStorage.removeItem(BACKUP_KEY);
|
|
44
|
+
break;
|
|
45
|
+
// Change iframe visibility
|
|
46
|
+
case "show":
|
|
47
|
+
case "hide":
|
|
48
|
+
changeIframeVisibility({
|
|
49
|
+
iframe,
|
|
50
|
+
isVisible: event === "show",
|
|
51
|
+
});
|
|
52
|
+
break;
|
|
53
|
+
// Handshake handling
|
|
54
|
+
case "handshake": {
|
|
55
|
+
iframe.contentWindow?.postMessage(
|
|
56
|
+
{
|
|
57
|
+
clientLifecycle: "handshake-response",
|
|
58
|
+
data: {
|
|
59
|
+
token: data.token,
|
|
60
|
+
currentUrl: window.location.href,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
"*"
|
|
64
|
+
);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
// Redirect handling
|
|
68
|
+
case "redirect": {
|
|
69
|
+
const redirectUrl = new URL(data.baseRedirectUrl);
|
|
70
|
+
|
|
71
|
+
// If we got a u append the current location dynamicly
|
|
72
|
+
if (redirectUrl.searchParams.has("u")) {
|
|
73
|
+
redirectUrl.searchParams.delete("u");
|
|
74
|
+
redirectUrl.searchParams.append("u", window.location.href);
|
|
75
|
+
window.location.href = redirectUrl.toString();
|
|
76
|
+
} else {
|
|
77
|
+
window.location.href = data.baseRedirectUrl;
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
handleEvent: handler,
|
|
86
|
+
isConnected: isConnectedDeferred.promise,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The final keys for each interaction types (e.g. `openArticle`) -> interaction type
|
|
3
|
+
* @inline
|
|
4
|
+
*/
|
|
5
|
+
export type InteractionTypesKey = {
|
|
6
|
+
[K in keyof typeof interactionTypes]: keyof (typeof interactionTypes)[K];
|
|
7
|
+
}[keyof typeof interactionTypes];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The keys for each interaction types (e.g. `press.openArticle`) -> category_type.interaction_type
|
|
11
|
+
* @inline
|
|
12
|
+
*/
|
|
13
|
+
export type FullInteractionTypesKey = {
|
|
14
|
+
[Category in keyof typeof interactionTypes]: `${Category & string}.${keyof (typeof interactionTypes)[Category] & string}`;
|
|
15
|
+
}[keyof typeof interactionTypes];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Each interactions types according to the product types
|
|
19
|
+
*/
|
|
20
|
+
export const interactionTypes = {
|
|
21
|
+
press: {
|
|
22
|
+
openArticle: "0xc0a24ffb",
|
|
23
|
+
readArticle: "0xd5bd0fbe",
|
|
24
|
+
},
|
|
25
|
+
dapp: {
|
|
26
|
+
proofVerifiableStorageUpdate: "0x2ab2aeef",
|
|
27
|
+
callableVerifiableStorageUpdate: "0xa07da986",
|
|
28
|
+
},
|
|
29
|
+
webshop: {
|
|
30
|
+
open: "0xb311798f",
|
|
31
|
+
},
|
|
32
|
+
referral: {
|
|
33
|
+
referred: "0x010cc3b9",
|
|
34
|
+
createLink: "0xb2c0f17c",
|
|
35
|
+
},
|
|
36
|
+
purchase: {
|
|
37
|
+
started: "0xd87e90c3",
|
|
38
|
+
completed: "0x8403aeb4",
|
|
39
|
+
unsafeCompleted: "0x4d5b14e0",
|
|
40
|
+
},
|
|
41
|
+
retail: {
|
|
42
|
+
customerMeeting: "0x74489004",
|
|
43
|
+
},
|
|
44
|
+
} as const;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keys for each product types
|
|
3
|
+
* @inline
|
|
4
|
+
*/
|
|
5
|
+
export type ProductTypesKey = keyof typeof productTypes;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* List of the product types per denominator
|
|
9
|
+
*/
|
|
10
|
+
export const productTypes = {
|
|
11
|
+
// content type
|
|
12
|
+
dapp: 1,
|
|
13
|
+
press: 2,
|
|
14
|
+
webshop: 3,
|
|
15
|
+
retail: 4,
|
|
16
|
+
|
|
17
|
+
// feature type
|
|
18
|
+
referral: 30,
|
|
19
|
+
purchase: 31,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Bitmask for each product types
|
|
24
|
+
*/
|
|
25
|
+
export const productTypesMask: Record<ProductTypesKey, bigint> = Object.entries(
|
|
26
|
+
productTypes
|
|
27
|
+
).reduce(
|
|
28
|
+
(acc, [key, value]) => {
|
|
29
|
+
acc[key as ProductTypesKey] = BigInt(1) << BigInt(value);
|
|
30
|
+
return acc;
|
|
31
|
+
},
|
|
32
|
+
{} as Record<ProductTypesKey, bigint>
|
|
33
|
+
);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Clients
|
|
2
|
+
export {
|
|
3
|
+
createIFrameFrakClient,
|
|
4
|
+
setupClient,
|
|
5
|
+
DebugInfoGatherer,
|
|
6
|
+
} from "./clients";
|
|
7
|
+
|
|
8
|
+
// Utils
|
|
9
|
+
export {
|
|
10
|
+
compressJsonToB64,
|
|
11
|
+
decompressJsonFromB64,
|
|
12
|
+
createIframe,
|
|
13
|
+
FrakContextManager,
|
|
14
|
+
baseIframeProps,
|
|
15
|
+
findIframeInOpener,
|
|
16
|
+
getSupportedCurrency,
|
|
17
|
+
getSupportedLocale,
|
|
18
|
+
getCurrencyAmountKey,
|
|
19
|
+
formatAmount,
|
|
20
|
+
base64urlDecode,
|
|
21
|
+
base64urlEncode,
|
|
22
|
+
trackEvent,
|
|
23
|
+
generateSsoUrl,
|
|
24
|
+
type CompressedSsoData,
|
|
25
|
+
type FullSsoParams,
|
|
26
|
+
type AppSpecificSsoMetadata,
|
|
27
|
+
} from "./utils";
|
|
28
|
+
|
|
29
|
+
// Constants
|
|
30
|
+
export {
|
|
31
|
+
type ProductTypesKey,
|
|
32
|
+
productTypes,
|
|
33
|
+
productTypesMask,
|
|
34
|
+
} from "./constants/productTypes";
|
|
35
|
+
export {
|
|
36
|
+
interactionTypes,
|
|
37
|
+
type InteractionTypesKey,
|
|
38
|
+
type FullInteractionTypesKey,
|
|
39
|
+
} from "./constants/interactionTypes";
|
|
40
|
+
export { locales, type LocalesKey } from "./constants/locales";
|
|
41
|
+
export { ssoPopupFeatures, ssoPopupName } from "./actions/openSso";
|
|
42
|
+
|
|
43
|
+
// Types
|
|
44
|
+
export type {
|
|
45
|
+
// Rpc
|
|
46
|
+
WalletStatusReturnType,
|
|
47
|
+
IFrameRpcSchema,
|
|
48
|
+
PreparedInteraction,
|
|
49
|
+
SendInteractionParamsType,
|
|
50
|
+
SendInteractionReturnType,
|
|
51
|
+
SsoMetadata,
|
|
52
|
+
PrepareSsoParamsType,
|
|
53
|
+
PrepareSsoReturnType,
|
|
54
|
+
OpenSsoParamsType,
|
|
55
|
+
OpenSsoReturnType,
|
|
56
|
+
Currency,
|
|
57
|
+
Language,
|
|
58
|
+
I18nConfig,
|
|
59
|
+
LocalizedI18nConfig,
|
|
60
|
+
TokenAmountType,
|
|
61
|
+
GetProductInformationReturnType,
|
|
62
|
+
// RPC Embedded wallet
|
|
63
|
+
DisplayEmbeddedWalletParamsType,
|
|
64
|
+
DisplayEmbeddedWalletResultType,
|
|
65
|
+
LoggedOutEmbeddedView,
|
|
66
|
+
LoggedInEmbeddedView,
|
|
67
|
+
EmbeddedViewActionReferred,
|
|
68
|
+
EmbeddedViewActionSharing,
|
|
69
|
+
// RPC Modal generics
|
|
70
|
+
ModalStepTypes,
|
|
71
|
+
ModalRpcMetadata,
|
|
72
|
+
DisplayModalParamsType,
|
|
73
|
+
ModalRpcStepsInput,
|
|
74
|
+
ModalRpcStepsResultType,
|
|
75
|
+
// RPC Modal types
|
|
76
|
+
ModalStepMetadata,
|
|
77
|
+
LoginModalStepType,
|
|
78
|
+
SiweAuthenticateModalStepType,
|
|
79
|
+
SiweAuthenticationParams,
|
|
80
|
+
SiweAuthenticateReturnType,
|
|
81
|
+
SendTransactionTxType,
|
|
82
|
+
SendTransactionModalStepType,
|
|
83
|
+
SendTransactionReturnType,
|
|
84
|
+
OpenInteractionSessionReturnType,
|
|
85
|
+
OpenInteractionSessionModalStepType,
|
|
86
|
+
FinalModalStepType,
|
|
87
|
+
FinalActionType,
|
|
88
|
+
// Client
|
|
89
|
+
FrakClient,
|
|
90
|
+
// Transport
|
|
91
|
+
IFrameTransport,
|
|
92
|
+
IFrameLifecycleEvent,
|
|
93
|
+
ClientLifecycleEvent,
|
|
94
|
+
FrakLifecycleEvent,
|
|
95
|
+
// Config
|
|
96
|
+
FrakWalletSdkConfig,
|
|
97
|
+
// Compression
|
|
98
|
+
KeyProvider,
|
|
99
|
+
CompressedData,
|
|
100
|
+
HashProtectedData,
|
|
101
|
+
// Utils
|
|
102
|
+
FrakContext,
|
|
103
|
+
} from "./types";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { PressInteractionEncoder } from "./pressEncoder";
|
|
2
|
+
export { ReferralInteractionEncoder } from "./referralEncoder";
|
|
3
|
+
export { PurchaseInteractionEncoder } from "./purchaseEncoder";
|
|
4
|
+
export { WebShopInteractionEncoder } from "./webshopEncoder";
|
|
5
|
+
export { RetailInteractionEncoder } from "./retailEncoder";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type Hex, concatHex, pad, toHex } from "viem";
|
|
2
|
+
import { interactionTypes } from "../constants/interactionTypes";
|
|
3
|
+
import { productTypes } from "../constants/productTypes";
|
|
4
|
+
import type { PreparedInteraction } from "../types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Press interactions allow you to track user engagement with articles or other press content on your platform.
|
|
8
|
+
* After setting up these interactions, you can create acquisition campaign based on the user engagement with your press content.
|
|
9
|
+
*
|
|
10
|
+
* :::info
|
|
11
|
+
* To properly handle press interactions, ensure that the "Press" product type is enabled in your Business dashboard.
|
|
12
|
+
* :::
|
|
13
|
+
*
|
|
14
|
+
* @description Encode press related user interactions
|
|
15
|
+
*
|
|
16
|
+
* @group Interactions Encoder
|
|
17
|
+
*
|
|
18
|
+
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
19
|
+
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
20
|
+
*/
|
|
21
|
+
export const PressInteractionEncoder = {
|
|
22
|
+
/**
|
|
23
|
+
* Encode an open article interaction
|
|
24
|
+
* @param args
|
|
25
|
+
* @param args.articleId - The id of the article the user opened (32 bytes), could be a `keccak256` hash of the article slug, or your internal id
|
|
26
|
+
*/
|
|
27
|
+
openArticle({ articleId }: { articleId: Hex }): PreparedInteraction {
|
|
28
|
+
const interactionData = concatHex([
|
|
29
|
+
interactionTypes.press.openArticle,
|
|
30
|
+
pad(articleId, { size: 32 }),
|
|
31
|
+
]);
|
|
32
|
+
return {
|
|
33
|
+
handlerTypeDenominator: toHex(productTypes.press),
|
|
34
|
+
interactionData,
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Encode a read article interaction
|
|
40
|
+
* @param args
|
|
41
|
+
* @param args.articleId - The id of the article the user opened (32 bytes), could be a `keccak256` hash of the article slug, or your internal id
|
|
42
|
+
*/
|
|
43
|
+
readArticle({ articleId }: { articleId: Hex }): PreparedInteraction {
|
|
44
|
+
const interactionData = concatHex([
|
|
45
|
+
interactionTypes.press.readArticle,
|
|
46
|
+
pad(articleId, { size: 32 }),
|
|
47
|
+
]);
|
|
48
|
+
return {
|
|
49
|
+
handlerTypeDenominator: toHex(productTypes.press),
|
|
50
|
+
interactionData,
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type Hex, concatHex, encodeAbiParameters, pad, toHex } from "viem";
|
|
2
|
+
import { interactionTypes } from "../constants/interactionTypes";
|
|
3
|
+
import { productTypes } from "../constants/productTypes";
|
|
4
|
+
import type { PreparedInteraction } from "../types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Purchase interactions allow you to track user purchases on your platform.
|
|
8
|
+
* After setting up these interactions, you can create acquisition campaign based on the user purchase (starting a new one, completed, or even purchase dropped).
|
|
9
|
+
*
|
|
10
|
+
* :::info
|
|
11
|
+
* To properly handle purchase interactions, ensure that the "Purchase" product type is enabled in your Business dashboard, and that you have set up everything correctly in the `Purchasetracker` section.
|
|
12
|
+
* :::
|
|
13
|
+
*
|
|
14
|
+
* :::note
|
|
15
|
+
* The `purchaseId` is used on both interactions. It can be computed like this:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const purchaseId = keccak256(concatHex([productId, toHex(externalPurchaseId)]));
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* With:
|
|
22
|
+
* - `productId`: The id of your product, you can find it in the product dashboard.
|
|
23
|
+
* - `externalPurchaseId`: The id of the purchase in your system (e.g. the shopify `order_id`).
|
|
24
|
+
* :::
|
|
25
|
+
*
|
|
26
|
+
* @description Encode purchase related user interactions
|
|
27
|
+
*
|
|
28
|
+
* @group Interactions Encoder
|
|
29
|
+
*
|
|
30
|
+
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
31
|
+
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
32
|
+
* @see {@link !actions.trackPurchaseStatus | `trackPurchaseStatus()`} Action that will automatically send the purchase upon completion
|
|
33
|
+
* @see [Purchase Webhooks](/wallet-sdk/references-api/webhook) Webhooks to be implemented on your side to confirm a purchase
|
|
34
|
+
* @see [Purchase Proof](/wallet-sdk/references-api/purchaseProof) Get a merklee proof for the purchase
|
|
35
|
+
*/
|
|
36
|
+
export const PurchaseInteractionEncoder = {
|
|
37
|
+
/**
|
|
38
|
+
* Encode a start purchase interaction
|
|
39
|
+
* @param args
|
|
40
|
+
* @param args.purchaseId - The id of the purchase that is being started.
|
|
41
|
+
*/
|
|
42
|
+
startPurchase({ purchaseId }: { purchaseId: Hex }): PreparedInteraction {
|
|
43
|
+
const interactionData = concatHex([
|
|
44
|
+
interactionTypes.purchase.started,
|
|
45
|
+
pad(purchaseId, { size: 32 }),
|
|
46
|
+
]);
|
|
47
|
+
return {
|
|
48
|
+
handlerTypeDenominator: toHex(productTypes.purchase),
|
|
49
|
+
interactionData,
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Encode a complete purchase interaction
|
|
55
|
+
* @param args
|
|
56
|
+
* @param args.purchaseId - The id of the purchase that is being completed.
|
|
57
|
+
* @param args.proof - The merkle proof that the user has completed the purchase (see [Purchase Webhooks](/wallet-sdk/references-api/webhook) for more details).
|
|
58
|
+
*/
|
|
59
|
+
completedPurchase({
|
|
60
|
+
purchaseId,
|
|
61
|
+
proof,
|
|
62
|
+
}: { purchaseId: Hex; proof: Hex[] }): PreparedInteraction {
|
|
63
|
+
const innerData = encodeAbiParameters(
|
|
64
|
+
[{ type: "uint256" }, { type: "bytes32[]" }],
|
|
65
|
+
[BigInt(purchaseId), proof]
|
|
66
|
+
);
|
|
67
|
+
const interactionData = concatHex([
|
|
68
|
+
interactionTypes.purchase.completed,
|
|
69
|
+
innerData,
|
|
70
|
+
]);
|
|
71
|
+
return {
|
|
72
|
+
handlerTypeDenominator: toHex(productTypes.purchase),
|
|
73
|
+
interactionData,
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Encode an unsafe complete purchase interaction (when we can't provide the proof)
|
|
79
|
+
* @param args
|
|
80
|
+
* @param args.purchaseId - The id of the purchase that is being completed.
|
|
81
|
+
*/
|
|
82
|
+
unsafeCompletedPurchase({
|
|
83
|
+
purchaseId,
|
|
84
|
+
}: { purchaseId: Hex }): PreparedInteraction {
|
|
85
|
+
const interactionData = concatHex([
|
|
86
|
+
interactionTypes.purchase.unsafeCompleted,
|
|
87
|
+
pad(purchaseId, { size: 32 }),
|
|
88
|
+
]);
|
|
89
|
+
return {
|
|
90
|
+
handlerTypeDenominator: toHex(productTypes.purchase),
|
|
91
|
+
interactionData,
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Address, concatHex, pad, toHex } from "viem";
|
|
2
|
+
import { interactionTypes } from "../constants/interactionTypes";
|
|
3
|
+
import { productTypes } from "../constants/productTypes";
|
|
4
|
+
import type { PreparedInteraction } from "../types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Referral interactions allow you to track user sharing activities.
|
|
8
|
+
* These interactions are essential for platforms looking to grow their user base through user-to-user referrals and reward systems.
|
|
9
|
+
*
|
|
10
|
+
* :::info
|
|
11
|
+
* To properly handle referral interactions, ensure that the "Referral" product type is enabled in your Business dashboard.
|
|
12
|
+
* :::
|
|
13
|
+
*
|
|
14
|
+
* @description Encode referral related user interactions
|
|
15
|
+
*
|
|
16
|
+
* @group Interactions Encoder
|
|
17
|
+
*
|
|
18
|
+
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
19
|
+
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
20
|
+
*/
|
|
21
|
+
export const ReferralInteractionEncoder = {
|
|
22
|
+
/**
|
|
23
|
+
* Records the event of a user creating a referral link. Note that this interaction doesn't actually create the link itself; it only sends an event to track that a link was created.
|
|
24
|
+
*/
|
|
25
|
+
createLink(): PreparedInteraction {
|
|
26
|
+
return {
|
|
27
|
+
handlerTypeDenominator: toHex(productTypes.referral),
|
|
28
|
+
interactionData: interactionTypes.referral.createLink,
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Encode a referred interaction
|
|
34
|
+
* @param args
|
|
35
|
+
* @param args.referrer - The Ethereum address of the user who made the referral
|
|
36
|
+
*/
|
|
37
|
+
referred({ referrer }: { referrer: Address }): PreparedInteraction {
|
|
38
|
+
const interactionData = concatHex([
|
|
39
|
+
interactionTypes.referral.referred,
|
|
40
|
+
pad(referrer, { size: 32 }),
|
|
41
|
+
]);
|
|
42
|
+
return {
|
|
43
|
+
handlerTypeDenominator: toHex(productTypes.referral),
|
|
44
|
+
interactionData,
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Hex, concatHex, pad, toHex } from "viem";
|
|
2
|
+
import { interactionTypes } from "../constants/interactionTypes";
|
|
3
|
+
import { productTypes } from "../constants/productTypes";
|
|
4
|
+
import type { PreparedInteraction } from "../types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Retail interactions allow you to track user activities on your retails products.
|
|
8
|
+
*
|
|
9
|
+
* :::info
|
|
10
|
+
* To properly handle retail interactions, ensure that the "Retail" product type is enabled in your Business dashboard.
|
|
11
|
+
* :::
|
|
12
|
+
*
|
|
13
|
+
* @description Encode retail related user interactions
|
|
14
|
+
*
|
|
15
|
+
* @group Interactions Encoder
|
|
16
|
+
*
|
|
17
|
+
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
18
|
+
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
19
|
+
*/
|
|
20
|
+
export const RetailInteractionEncoder = {
|
|
21
|
+
/**
|
|
22
|
+
* Encode a customer meeting retail interaction
|
|
23
|
+
* @param args
|
|
24
|
+
* @param args.agencyId - The id of the agency that the customer is meeting with
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
customerMeeting({ agencyId }: { agencyId: Hex }): PreparedInteraction {
|
|
28
|
+
const interactionData = concatHex([
|
|
29
|
+
interactionTypes.retail.customerMeeting,
|
|
30
|
+
pad(agencyId, { size: 32 }),
|
|
31
|
+
]);
|
|
32
|
+
return {
|
|
33
|
+
handlerTypeDenominator: toHex(productTypes.retail),
|
|
34
|
+
interactionData,
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { toHex } from "viem";
|
|
2
|
+
import { interactionTypes } from "../constants/interactionTypes";
|
|
3
|
+
import { productTypes } from "../constants/productTypes";
|
|
4
|
+
import type { PreparedInteraction } from "../types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Webshop interactions allow you to track user activities on your webshop.
|
|
8
|
+
*
|
|
9
|
+
* :::info
|
|
10
|
+
* To properly handle webshop interactions, ensure that the "WebShop" product type is enabled in your Business dashboard.
|
|
11
|
+
* :::
|
|
12
|
+
*
|
|
13
|
+
* @description Encode webshop related user interactions
|
|
14
|
+
*
|
|
15
|
+
* @group Interactions Encoder
|
|
16
|
+
*
|
|
17
|
+
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
18
|
+
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
19
|
+
*/
|
|
20
|
+
export const WebShopInteractionEncoder = {
|
|
21
|
+
/**
|
|
22
|
+
* Encode an open webshop interaction
|
|
23
|
+
*/
|
|
24
|
+
open(): PreparedInteraction {
|
|
25
|
+
return {
|
|
26
|
+
handlerTypeDenominator: toHex(productTypes.webshop),
|
|
27
|
+
interactionData: interactionTypes.webshop.open,
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { OpenPanel } from "@openpanel/web";
|
|
2
|
+
import type { FrakWalletSdkConfig } from "./config";
|
|
3
|
+
import type { IFrameTransport } from "./transport";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Representing a Frak client, used to interact with the Frak Wallet
|
|
7
|
+
*/
|
|
8
|
+
export type FrakClient = {
|
|
9
|
+
config: FrakWalletSdkConfig;
|
|
10
|
+
debugInfo: {
|
|
11
|
+
formatDebugInfo: (error: Error | unknown | string) => string;
|
|
12
|
+
};
|
|
13
|
+
openPanel?: OpenPanel;
|
|
14
|
+
} & IFrameTransport;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The received encoded data from a client
|
|
3
|
+
* -> The encoded should contain a HashProtectedData once decoded
|
|
4
|
+
* @ignore
|
|
5
|
+
*/
|
|
6
|
+
export type CompressedData = Uint8Array;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The encoded data to send to a client / received by a client
|
|
10
|
+
* @ignore
|
|
11
|
+
*/
|
|
12
|
+
export type HashProtectedData<DataType> = Readonly<
|
|
13
|
+
DataType & {
|
|
14
|
+
validationHash: string;
|
|
15
|
+
}
|
|
16
|
+
>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Represent a key provider used for the hashed and secure compression
|
|
20
|
+
* @ignore
|
|
21
|
+
*/
|
|
22
|
+
export type KeyProvider<DataType> = (value: DataType) => string[];
|