@reflecterlab/bridge-sdk 1.0.0 → 1.0.1
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/dist/client.d.ts +31 -0
- package/{src/client.ts → dist/client.js} +65 -73
- package/{src/index.ts → dist/index.d.ts} +2 -2
- package/dist/index.js +18 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.js +2 -0
- package/package.json +4 -1
- package/src/types.ts +0 -33
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @reflecter/bridge-sdk
|
|
3
|
+
* Pure TypeScript SDK to interact with Open The Doorz Host
|
|
4
|
+
*/
|
|
5
|
+
export declare class OTDBridge {
|
|
6
|
+
private appId;
|
|
7
|
+
private targetOrigin;
|
|
8
|
+
private pendingRequests;
|
|
9
|
+
constructor(appId: string, targetOrigin?: string);
|
|
10
|
+
private setupListener;
|
|
11
|
+
private sendMessage;
|
|
12
|
+
/**
|
|
13
|
+
* Initialize connection and get user/org context
|
|
14
|
+
*/
|
|
15
|
+
init(): Promise<{
|
|
16
|
+
handle: string;
|
|
17
|
+
orgName: string;
|
|
18
|
+
walletAddress: string;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Request a transaction signature and execution
|
|
22
|
+
*/
|
|
23
|
+
sendTransaction(params: {
|
|
24
|
+
to: string;
|
|
25
|
+
amount: string;
|
|
26
|
+
token: string;
|
|
27
|
+
data?: string;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
txHash: string;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
@@ -1,73 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Request a transaction signature and execution
|
|
69
|
-
*/
|
|
70
|
-
async sendTransaction(params: { to: string, amount: string, token: string, data?: string }): Promise<{ txHash: string }> {
|
|
71
|
-
return this.sendMessage('OTD_TX_REQUEST', params);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @reflecter/bridge-sdk
|
|
4
|
+
* Pure TypeScript SDK to interact with Open The Doorz Host
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.OTDBridge = void 0;
|
|
8
|
+
class OTDBridge {
|
|
9
|
+
constructor(appId, targetOrigin = '*') {
|
|
10
|
+
this.pendingRequests = new Map();
|
|
11
|
+
this.appId = appId;
|
|
12
|
+
this.targetOrigin = targetOrigin;
|
|
13
|
+
this.setupListener();
|
|
14
|
+
}
|
|
15
|
+
setupListener() {
|
|
16
|
+
if (typeof window === 'undefined')
|
|
17
|
+
return;
|
|
18
|
+
window.addEventListener('message', (event) => {
|
|
19
|
+
// Future: Strict origin validation can be added here
|
|
20
|
+
const message = event.data;
|
|
21
|
+
if (!message || !message.id || !this.pendingRequests.has(message.id))
|
|
22
|
+
return;
|
|
23
|
+
const { resolve, reject } = this.pendingRequests.get(message.id);
|
|
24
|
+
this.pendingRequests.delete(message.id);
|
|
25
|
+
if (message.type === 'OTD_ERROR') {
|
|
26
|
+
reject(message.payload);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
resolve(message.payload);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
sendMessage(type, payload) {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const id = Math.random().toString(36).substring(7);
|
|
36
|
+
const message = {
|
|
37
|
+
id,
|
|
38
|
+
type,
|
|
39
|
+
payload,
|
|
40
|
+
appId: this.appId,
|
|
41
|
+
origin: typeof window !== 'undefined' ? window.location.origin : ''
|
|
42
|
+
};
|
|
43
|
+
this.pendingRequests.set(id, { resolve, reject });
|
|
44
|
+
if (window.parent !== window) {
|
|
45
|
+
window.parent.postMessage(message, this.targetOrigin);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
reject(new Error("Bridge must be executed inside Open The Doorz Host (Iframe)"));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Initialize connection and get user/org context
|
|
54
|
+
*/
|
|
55
|
+
async init() {
|
|
56
|
+
return this.sendMessage('OTD_INIT_REQUEST', {});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Request a transaction signature and execution
|
|
60
|
+
*/
|
|
61
|
+
async sendTransaction(params) {
|
|
62
|
+
return this.sendMessage('OTD_TX_REQUEST', params);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.OTDBridge = OTDBridge;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './client';
|
|
2
|
-
export * from './types';
|
|
1
|
+
export * from './client';
|
|
2
|
+
export * from './types';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./client"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface MiniApp {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
url: string;
|
|
6
|
+
icon?: string;
|
|
7
|
+
category: 'finance' | 'gaming' | 'social' | 'tools' | 'ecosystem';
|
|
8
|
+
permissions: AppPermission[];
|
|
9
|
+
developer_id: string;
|
|
10
|
+
created_at: Date;
|
|
11
|
+
status: 'pending' | 'active' | 'suspended';
|
|
12
|
+
}
|
|
13
|
+
export type AppPermission = 'read_identity' | 'read_balances' | 'sign_transaction' | 'sign_message';
|
|
14
|
+
export interface BridgeMessage<T = any> {
|
|
15
|
+
id: string;
|
|
16
|
+
type: BridgeMessageType;
|
|
17
|
+
payload: T;
|
|
18
|
+
appId: string;
|
|
19
|
+
origin: string;
|
|
20
|
+
}
|
|
21
|
+
export type BridgeMessageType = 'OTD_INIT_REQUEST' | 'OTD_INIT_RESPONSE' | 'OTD_TX_REQUEST' | 'OTD_TX_RESPONSE' | 'OTD_ERROR';
|
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reflecterlab/bridge-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "The official bridge to build mini-apps on Open The Doorz ecosystem.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
7
10
|
"scripts": {
|
|
8
11
|
"build": "tsc",
|
|
9
12
|
"dev": "tsc --watch"
|
package/src/types.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export interface MiniApp {
|
|
2
|
-
id: string;
|
|
3
|
-
name: string;
|
|
4
|
-
description: string;
|
|
5
|
-
url: string; // The hosted URL of the mini-app
|
|
6
|
-
icon?: string;
|
|
7
|
-
category: 'finance' | 'gaming' | 'social' | 'tools' | 'ecosystem';
|
|
8
|
-
permissions: AppPermission[];
|
|
9
|
-
developer_id: string; // ID of the organization or user who owns the app
|
|
10
|
-
created_at: Date;
|
|
11
|
-
status: 'pending' | 'active' | 'suspended';
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type AppPermission =
|
|
15
|
-
| 'read_identity' // Access to user alias/handle
|
|
16
|
-
| 'read_balances' // Access to token balances
|
|
17
|
-
| 'sign_transaction' // Ability to request a TX signature
|
|
18
|
-
| 'sign_message'; // Ability to request a Typed Data signature
|
|
19
|
-
|
|
20
|
-
export interface BridgeMessage<T = any> {
|
|
21
|
-
id: string; // Unique ID to match request/response
|
|
22
|
-
type: BridgeMessageType;
|
|
23
|
-
payload: T;
|
|
24
|
-
appId: string; // Identity of the sender
|
|
25
|
-
origin: string; // URL origin for validation
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type BridgeMessageType =
|
|
29
|
-
| 'OTD_INIT_REQUEST'
|
|
30
|
-
| 'OTD_INIT_RESPONSE'
|
|
31
|
-
| 'OTD_TX_REQUEST'
|
|
32
|
-
| 'OTD_TX_RESPONSE'
|
|
33
|
-
| 'OTD_ERROR';
|