@reflecterlab/bridge-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 +48 -0
- package/package.json +23 -0
- package/src/client.ts +73 -0
- package/src/index.ts +2 -0
- package/src/types.ts +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @reflecter/bridge-sdk 馃毆
|
|
2
|
+
|
|
3
|
+
El SDK oficial para conectar tus aplicaciones con el ecosistema de **Open The Doorz**. Construye mini-apps Web3 que se ejecutan directamente en la billetera corporativa m谩s potente de Starknet.
|
|
4
|
+
|
|
5
|
+
## 馃摝 Instalaci贸n
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @reflecter/bridge-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 馃殌 Uso R谩pido
|
|
12
|
+
|
|
13
|
+
### 1. Inicializa el Bridge
|
|
14
|
+
Con茅ctate con el Host para recibir el contexto del usuario y la organizaci贸n.
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
import { OTDBridge } from '@reflecter/bridge-sdk';
|
|
18
|
+
|
|
19
|
+
const bridge = new OTDBridge('mi-app-id');
|
|
20
|
+
|
|
21
|
+
// Obtener contexto
|
|
22
|
+
const { handle, orgName, walletAddress } = await bridge.init();
|
|
23
|
+
console.log(`Hola ${handle} de ${orgName}`);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 2. Solicita una Transacci贸n
|
|
27
|
+
No te preocupes por la gesti贸n de llaves. Pide al Host que firme y ejecute la transacci贸n por ti.
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
try {
|
|
31
|
+
const result = await bridge.sendTransaction({
|
|
32
|
+
to: "0x0123...456",
|
|
33
|
+
amount: "10",
|
|
34
|
+
token: "STRK",
|
|
35
|
+
data: "0x..." // Opcional: calldata para contratos inteligentes
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
console.log("Transacci贸n enviada:", result.txHash);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error("Usuario rechaz贸 la transacci贸n o error de red");
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 馃攼 Seguridad
|
|
45
|
+
El Bridge utiliza un sistema de mensajer铆a as铆ncrona segura. Tu aplicaci贸n nunca tiene acceso a las claves privadas del usuario. Todas las acciones cr铆ticas requieren la aprobaci贸n expl铆cita del usuario en la interfaz nativa de Open The Doorz.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
Construido por **Reflecter Labs** 馃殌
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reflecterlab/bridge-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "The official bridge to build mini-apps on Open The Doorz ecosystem.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"dev": "tsc --watch"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"starknet",
|
|
13
|
+
"web3",
|
|
14
|
+
"mini-apps",
|
|
15
|
+
"bridge",
|
|
16
|
+
"wallet-sdk"
|
|
17
|
+
],
|
|
18
|
+
"author": "Reflecter Labs",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"typescript": "^5.0.0"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @reflecter/bridge-sdk
|
|
3
|
+
* Pure TypeScript SDK to interact with Open The Doorz Host
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { BridgeMessage, BridgeMessageType } from './types';
|
|
7
|
+
|
|
8
|
+
export class OTDBridge {
|
|
9
|
+
private appId: string;
|
|
10
|
+
private targetOrigin: string;
|
|
11
|
+
private pendingRequests: Map<string, { resolve: Function, reject: Function }> = new Map();
|
|
12
|
+
|
|
13
|
+
constructor(appId: string, targetOrigin: string = '*') {
|
|
14
|
+
this.appId = appId;
|
|
15
|
+
this.targetOrigin = targetOrigin;
|
|
16
|
+
this.setupListener();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
private setupListener() {
|
|
20
|
+
if (typeof window === 'undefined') return;
|
|
21
|
+
|
|
22
|
+
window.addEventListener('message', (event) => {
|
|
23
|
+
// Future: Strict origin validation can be added here
|
|
24
|
+
const message = event.data as BridgeMessage;
|
|
25
|
+
|
|
26
|
+
if (!message || !message.id || !this.pendingRequests.has(message.id)) return;
|
|
27
|
+
|
|
28
|
+
const { resolve, reject } = this.pendingRequests.get(message.id)!;
|
|
29
|
+
this.pendingRequests.delete(message.id);
|
|
30
|
+
|
|
31
|
+
if (message.type === 'OTD_ERROR') {
|
|
32
|
+
reject(message.payload);
|
|
33
|
+
} else {
|
|
34
|
+
resolve(message.payload);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private sendMessage(type: BridgeMessageType, payload: any): Promise<any> {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const id = Math.random().toString(36).substring(7);
|
|
42
|
+
const message: BridgeMessage = {
|
|
43
|
+
id,
|
|
44
|
+
type,
|
|
45
|
+
payload,
|
|
46
|
+
appId: this.appId,
|
|
47
|
+
origin: typeof window !== 'undefined' ? window.location.origin : ''
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
this.pendingRequests.set(id, { resolve, reject });
|
|
51
|
+
|
|
52
|
+
if (window.parent !== window) {
|
|
53
|
+
window.parent.postMessage(message, this.targetOrigin);
|
|
54
|
+
} else {
|
|
55
|
+
reject(new Error("Bridge must be executed inside Open The Doorz Host (Iframe)"));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Initialize connection and get user/org context
|
|
62
|
+
*/
|
|
63
|
+
async init(): Promise<{ handle: string, orgName: string, walletAddress: string }> {
|
|
64
|
+
return this.sendMessage('OTD_INIT_REQUEST', {});
|
|
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
|
+
}
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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';
|