tribo-kit-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # TriboKit SDK
2
+
3
+ The official TypeScript SDK for building Mini Apps within the **Tribo Ecosystem**.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install tribo-kit-sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ### 1. Connect User Account
14
+
15
+ Before performing any action, you should request the user to connect their wallet.
16
+
17
+ ```typescript
18
+ import { Tribo } from 'tribo-kit-sdk';
19
+
20
+ const connect = async () => {
21
+ const result = await Tribo.connect();
22
+ if (result.success) {
23
+ console.log("Connected wallet:", result.address);
24
+ console.log("User FID:", result.fid);
25
+ } else {
26
+ console.error("Connection failed:", result.error);
27
+ }
28
+ };
29
+ ```
30
+
31
+ ### 2. Request Payment
32
+
33
+ Ask the user to pay for a service or item.
34
+
35
+ ```typescript
36
+ const handlePay = async () => {
37
+ const result = await Tribo.pay({
38
+ amount: 0.5,
39
+ recipient: "0x123...", // Your recipient address
40
+ description: "Premium Access"
41
+ });
42
+
43
+ if (result.success) {
44
+ console.log("Transaction Hash:", result.txHash);
45
+ }
46
+ };
47
+ ```
48
+
49
+ ### 3. Check Balance
50
+
51
+ Get the balance of the connected user.
52
+
53
+ ```typescript
54
+ const checkBal = async () => {
55
+ if (!Tribo.wallet) return;
56
+
57
+ const res = await Tribo.getBalance(Tribo.wallet);
58
+ console.log("Balance:", res.balance);
59
+ };
60
+ ```
61
+
62
+ ## Deployment
63
+
64
+ To test your app, host it on a public URL and add it to the Tribo Ecosystem dashboard. Your app must be running inside the Tribo host to communicate with the SDK.
65
+
66
+ ---
67
+
68
+ Built with ❤️ by [Tribo](https://tribovault.co)
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Tribo SDK
3
+ *
4
+ * Official SDK for Tribo Ecosystem Mini Apps.
5
+ * Allows apps to request payments and user connection when running inside the Tribo host.
6
+ */
7
+ interface PayParams {
8
+ amount: number;
9
+ recipient: string;
10
+ tokenAddress?: string;
11
+ description?: string;
12
+ }
13
+ interface PaymentResponse {
14
+ success: boolean;
15
+ txHash?: string;
16
+ error?: string;
17
+ }
18
+ interface ConnectResponse {
19
+ success: boolean;
20
+ address?: string;
21
+ username?: string;
22
+ fid?: string;
23
+ pfpUrl?: string | null;
24
+ error?: string;
25
+ }
26
+ declare class TriboSDK {
27
+ private static instance;
28
+ private isConnected;
29
+ private userWallet;
30
+ private constructor();
31
+ static getInstance(): TriboSDK;
32
+ /**
33
+ * Check if we are running inside the Tribo Ecosystem bridge (iframe)
34
+ */
35
+ isInsideEcosystem(): boolean;
36
+ private setupResponseListener;
37
+ /**
38
+ * Internal: Send message to parent frame and wait for response
39
+ */
40
+ private sendToParent;
41
+ /**
42
+ * Request connection from the host.
43
+ * This will trigger the connection modal in the Tribo App.
44
+ */
45
+ connect(): Promise<ConnectResponse>;
46
+ /**
47
+ * Request a payment.
48
+ * This will trigger the transaction modal in the Tribo App.
49
+ */
50
+ pay(params: PayParams): Promise<PaymentResponse>;
51
+ /**
52
+ * Request a generic transaction (swap or specialized send).
53
+ */
54
+ sendTransaction(params: any): Promise<PaymentResponse>;
55
+ /**
56
+ * Get balance of a specific token for the connected user.
57
+ */
58
+ getBalance(address: string, tokenAddress?: string): Promise<{
59
+ success: boolean;
60
+ balance: string;
61
+ error?: string;
62
+ }>;
63
+ /**
64
+ * Request verification (Proof of Personhood/Orb).
65
+ */
66
+ verify(params: {
67
+ action: string;
68
+ signal: string;
69
+ }): Promise<{
70
+ success: boolean;
71
+ data?: any;
72
+ error?: string;
73
+ }>;
74
+ /**
75
+ * Request notification permissions.
76
+ */
77
+ requestNotifications(): Promise<{
78
+ success: boolean;
79
+ data?: any;
80
+ error?: string;
81
+ }>;
82
+ get wallet(): string | null;
83
+ get connected(): boolean;
84
+ }
85
+ declare const Tribo: TriboSDK;
86
+
87
+ export { type ConnectResponse, type PayParams, type PaymentResponse, Tribo, Tribo as default };
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Tribo SDK
3
+ *
4
+ * Official SDK for Tribo Ecosystem Mini Apps.
5
+ * Allows apps to request payments and user connection when running inside the Tribo host.
6
+ */
7
+ interface PayParams {
8
+ amount: number;
9
+ recipient: string;
10
+ tokenAddress?: string;
11
+ description?: string;
12
+ }
13
+ interface PaymentResponse {
14
+ success: boolean;
15
+ txHash?: string;
16
+ error?: string;
17
+ }
18
+ interface ConnectResponse {
19
+ success: boolean;
20
+ address?: string;
21
+ username?: string;
22
+ fid?: string;
23
+ pfpUrl?: string | null;
24
+ error?: string;
25
+ }
26
+ declare class TriboSDK {
27
+ private static instance;
28
+ private isConnected;
29
+ private userWallet;
30
+ private constructor();
31
+ static getInstance(): TriboSDK;
32
+ /**
33
+ * Check if we are running inside the Tribo Ecosystem bridge (iframe)
34
+ */
35
+ isInsideEcosystem(): boolean;
36
+ private setupResponseListener;
37
+ /**
38
+ * Internal: Send message to parent frame and wait for response
39
+ */
40
+ private sendToParent;
41
+ /**
42
+ * Request connection from the host.
43
+ * This will trigger the connection modal in the Tribo App.
44
+ */
45
+ connect(): Promise<ConnectResponse>;
46
+ /**
47
+ * Request a payment.
48
+ * This will trigger the transaction modal in the Tribo App.
49
+ */
50
+ pay(params: PayParams): Promise<PaymentResponse>;
51
+ /**
52
+ * Request a generic transaction (swap or specialized send).
53
+ */
54
+ sendTransaction(params: any): Promise<PaymentResponse>;
55
+ /**
56
+ * Get balance of a specific token for the connected user.
57
+ */
58
+ getBalance(address: string, tokenAddress?: string): Promise<{
59
+ success: boolean;
60
+ balance: string;
61
+ error?: string;
62
+ }>;
63
+ /**
64
+ * Request verification (Proof of Personhood/Orb).
65
+ */
66
+ verify(params: {
67
+ action: string;
68
+ signal: string;
69
+ }): Promise<{
70
+ success: boolean;
71
+ data?: any;
72
+ error?: string;
73
+ }>;
74
+ /**
75
+ * Request notification permissions.
76
+ */
77
+ requestNotifications(): Promise<{
78
+ success: boolean;
79
+ data?: any;
80
+ error?: string;
81
+ }>;
82
+ get wallet(): string | null;
83
+ get connected(): boolean;
84
+ }
85
+ declare const Tribo: TriboSDK;
86
+
87
+ export { type ConnectResponse, type PayParams, type PaymentResponse, Tribo, Tribo as default };
package/dist/index.js ADDED
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Tribo: () => Tribo,
24
+ default: () => index_default
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var TriboSDK = class _TriboSDK {
28
+ static instance;
29
+ isConnected = false;
30
+ userWallet = null;
31
+ constructor() {
32
+ if (typeof window !== "undefined") {
33
+ this.setupResponseListener();
34
+ }
35
+ }
36
+ static getInstance() {
37
+ if (!_TriboSDK.instance) {
38
+ _TriboSDK.instance = new _TriboSDK();
39
+ }
40
+ return _TriboSDK.instance;
41
+ }
42
+ /**
43
+ * Check if we are running inside the Tribo Ecosystem bridge (iframe)
44
+ */
45
+ isInsideEcosystem() {
46
+ if (typeof window === "undefined") return false;
47
+ return window.self !== window.top;
48
+ }
49
+ setupResponseListener() {
50
+ }
51
+ /**
52
+ * Internal: Send message to parent frame and wait for response
53
+ */
54
+ async sendToParent(command, params) {
55
+ return new Promise((resolve) => {
56
+ if (!this.isInsideEcosystem()) {
57
+ resolve({ success: false, error: "Not running inside Tribo Ecosystem" });
58
+ return;
59
+ }
60
+ const requestId = Math.random().toString(36).substring(7);
61
+ const handler = (event) => {
62
+ const { type, requestId: responseId } = event.data;
63
+ if (type === "TRIBO_RESPONSE" && responseId === requestId) {
64
+ window.removeEventListener("message", handler);
65
+ const { type: _, requestId: __, ...response } = event.data;
66
+ resolve(response);
67
+ }
68
+ };
69
+ window.addEventListener("message", handler);
70
+ window.parent.postMessage({ command, params, requestId }, "*");
71
+ setTimeout(() => {
72
+ window.removeEventListener("message", handler);
73
+ resolve({ success: false, error: "Request timed out" });
74
+ }, 6e4);
75
+ });
76
+ }
77
+ /**
78
+ * Request connection from the host.
79
+ * This will trigger the connection modal in the Tribo App.
80
+ */
81
+ async connect() {
82
+ const response = await this.sendToParent("CONNECT");
83
+ if (response.success && response.data) {
84
+ this.isConnected = true;
85
+ this.userWallet = response.data.address;
86
+ return { ...response.data, success: true };
87
+ }
88
+ return response;
89
+ }
90
+ /**
91
+ * Request a payment.
92
+ * This will trigger the transaction modal in the Tribo App.
93
+ */
94
+ async pay(params) {
95
+ return await this.sendToParent("PAY", params);
96
+ }
97
+ /**
98
+ * Request a generic transaction (swap or specialized send).
99
+ */
100
+ async sendTransaction(params) {
101
+ return await this.sendToParent("SEND_TRANSACTION", params);
102
+ }
103
+ /**
104
+ * Get balance of a specific token for the connected user.
105
+ */
106
+ async getBalance(address, tokenAddress) {
107
+ return await this.sendToParent("GET_BALANCE", { address, tokenAddress });
108
+ }
109
+ /**
110
+ * Request verification (Proof of Personhood/Orb).
111
+ */
112
+ async verify(params) {
113
+ return await this.sendToParent("VERIFY", params);
114
+ }
115
+ /**
116
+ * Request notification permissions.
117
+ */
118
+ async requestNotifications() {
119
+ return await this.sendToParent("REQUEST_NOTIFICATIONS");
120
+ }
121
+ get wallet() {
122
+ return this.userWallet;
123
+ }
124
+ get connected() {
125
+ return this.isConnected;
126
+ }
127
+ };
128
+ var Tribo = TriboSDK.getInstance();
129
+ var index_default = Tribo;
130
+ // Annotate the CommonJS export names for ESM import in node:
131
+ 0 && (module.exports = {
132
+ Tribo
133
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,108 @@
1
+ // src/index.ts
2
+ var TriboSDK = class _TriboSDK {
3
+ static instance;
4
+ isConnected = false;
5
+ userWallet = null;
6
+ constructor() {
7
+ if (typeof window !== "undefined") {
8
+ this.setupResponseListener();
9
+ }
10
+ }
11
+ static getInstance() {
12
+ if (!_TriboSDK.instance) {
13
+ _TriboSDK.instance = new _TriboSDK();
14
+ }
15
+ return _TriboSDK.instance;
16
+ }
17
+ /**
18
+ * Check if we are running inside the Tribo Ecosystem bridge (iframe)
19
+ */
20
+ isInsideEcosystem() {
21
+ if (typeof window === "undefined") return false;
22
+ return window.self !== window.top;
23
+ }
24
+ setupResponseListener() {
25
+ }
26
+ /**
27
+ * Internal: Send message to parent frame and wait for response
28
+ */
29
+ async sendToParent(command, params) {
30
+ return new Promise((resolve) => {
31
+ if (!this.isInsideEcosystem()) {
32
+ resolve({ success: false, error: "Not running inside Tribo Ecosystem" });
33
+ return;
34
+ }
35
+ const requestId = Math.random().toString(36).substring(7);
36
+ const handler = (event) => {
37
+ const { type, requestId: responseId } = event.data;
38
+ if (type === "TRIBO_RESPONSE" && responseId === requestId) {
39
+ window.removeEventListener("message", handler);
40
+ const { type: _, requestId: __, ...response } = event.data;
41
+ resolve(response);
42
+ }
43
+ };
44
+ window.addEventListener("message", handler);
45
+ window.parent.postMessage({ command, params, requestId }, "*");
46
+ setTimeout(() => {
47
+ window.removeEventListener("message", handler);
48
+ resolve({ success: false, error: "Request timed out" });
49
+ }, 6e4);
50
+ });
51
+ }
52
+ /**
53
+ * Request connection from the host.
54
+ * This will trigger the connection modal in the Tribo App.
55
+ */
56
+ async connect() {
57
+ const response = await this.sendToParent("CONNECT");
58
+ if (response.success && response.data) {
59
+ this.isConnected = true;
60
+ this.userWallet = response.data.address;
61
+ return { ...response.data, success: true };
62
+ }
63
+ return response;
64
+ }
65
+ /**
66
+ * Request a payment.
67
+ * This will trigger the transaction modal in the Tribo App.
68
+ */
69
+ async pay(params) {
70
+ return await this.sendToParent("PAY", params);
71
+ }
72
+ /**
73
+ * Request a generic transaction (swap or specialized send).
74
+ */
75
+ async sendTransaction(params) {
76
+ return await this.sendToParent("SEND_TRANSACTION", params);
77
+ }
78
+ /**
79
+ * Get balance of a specific token for the connected user.
80
+ */
81
+ async getBalance(address, tokenAddress) {
82
+ return await this.sendToParent("GET_BALANCE", { address, tokenAddress });
83
+ }
84
+ /**
85
+ * Request verification (Proof of Personhood/Orb).
86
+ */
87
+ async verify(params) {
88
+ return await this.sendToParent("VERIFY", params);
89
+ }
90
+ /**
91
+ * Request notification permissions.
92
+ */
93
+ async requestNotifications() {
94
+ return await this.sendToParent("REQUEST_NOTIFICATIONS");
95
+ }
96
+ get wallet() {
97
+ return this.userWallet;
98
+ }
99
+ get connected() {
100
+ return this.isConnected;
101
+ }
102
+ };
103
+ var Tribo = TriboSDK.getInstance();
104
+ var index_default = Tribo;
105
+ export {
106
+ Tribo,
107
+ index_default as default
108
+ };
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "tribo-kit-sdk",
3
+ "version": "1.0.0",
4
+ "description": "Official SDK for Tribo Ecosystem Mini Apps",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
13
+ "dev": "tsup src/index.ts --format cjs,esm --watch --dts",
14
+ "lint": "tsc --noEmit"
15
+ },
16
+ "keywords": [
17
+ "tribo",
18
+ "ecosystem",
19
+ "farcaster",
20
+ "minikit",
21
+ "sdk",
22
+ "web3"
23
+ ],
24
+ "author": "Tribo",
25
+ "license": "MIT",
26
+ "devDependencies": {
27
+ "tsup": "^8.0.0",
28
+ "typescript": "^5.0.0"
29
+ }
30
+ }