@fedimint/types 0.0.1 → 0.0.3
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/index.d.ts +11 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +29 -16
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
export type JSONValue = string | number | boolean | null | {
|
|
2
2
|
[key: string]: JSONValue;
|
|
3
3
|
} | JSONValue[];
|
|
4
|
-
export declare const TRANSPORT_MESSAGE_TYPES: readonly ["init", "
|
|
4
|
+
export declare const TRANSPORT_MESSAGE_TYPES: readonly ["init", "error", "cleanup", "set_mnemonic", "generate_mnemonic", "get_mnemonic", "join_federation", "open_client", "close_client", "client_rpc", "cancel_rpc", "parse_invite_code", "parse_bolt11_invoice", "preview_federation"];
|
|
5
5
|
export type TransportMessageType = (typeof TRANSPORT_MESSAGE_TYPES)[number];
|
|
6
6
|
export type TransportRequest = {
|
|
7
7
|
type: TransportMessageType;
|
|
8
8
|
requestId?: number;
|
|
9
9
|
payload?: JSONValue;
|
|
10
10
|
};
|
|
11
|
+
declare const TransportResponseTypes: readonly ["data", "error", "end", "log"];
|
|
12
|
+
type TransportResponseType = (typeof TransportResponseTypes)[number];
|
|
11
13
|
export type TransportMessage = {
|
|
12
|
-
type:
|
|
13
|
-
|
|
14
|
+
type: TransportResponseType;
|
|
15
|
+
request_id?: number;
|
|
14
16
|
} & Record<string, unknown>;
|
|
15
17
|
export type TransportMessageHandler = (message: TransportMessage) => void;
|
|
16
18
|
export type TransportErrorHandler = (error: unknown) => void;
|
|
@@ -18,11 +20,13 @@ export type TransportErrorHandler = (error: unknown) => void;
|
|
|
18
20
|
* Generic Transport interface for communicating with a specific
|
|
19
21
|
* target of the FedimintClient. Can be Wasm, React Native, Node, etc.
|
|
20
22
|
*/
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
+
export declare abstract class Transport {
|
|
24
|
+
protected messageHandler: TransportMessageHandler;
|
|
25
|
+
protected errorHandler: TransportErrorHandler;
|
|
26
|
+
abstract logger: TransportLogger;
|
|
27
|
+
abstract postMessage(message: TransportRequest): void;
|
|
23
28
|
setMessageHandler(handler: TransportMessageHandler): void;
|
|
24
29
|
setErrorHandler(handler: TransportErrorHandler): void;
|
|
25
|
-
logger: TransportLogger;
|
|
26
30
|
}
|
|
27
31
|
/**
|
|
28
32
|
* Generic logger interface based on console-style logging.
|
|
@@ -33,4 +37,5 @@ export type TransportLogger = {
|
|
|
33
37
|
warn(message: string, ...args: any[]): void;
|
|
34
38
|
error(message: string, ...args: any[]): void;
|
|
35
39
|
};
|
|
40
|
+
export {};
|
|
36
41
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAC5B,SAAS,EAAE,CAAA;AAEf,eAAO,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAC5B,SAAS,EAAE,CAAA;AAEf,eAAO,MAAM,uBAAuB,6OAiB1B,CAAA;AAEV,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE3E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,oBAAoB,CAAA;IAC1B,S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G,EAAE,GAAG,IAAI,CAAA;CAC7C,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,36 @@
|
|
|
1
1
|
export const TRANSPORT_MESSAGE_TYPES = [
|
|
2
2
|
'init',
|
|
3
|
-
'initialized',
|
|
4
|
-
'rpc',
|
|
5
|
-
'log',
|
|
6
|
-
'open',
|
|
7
|
-
'join',
|
|
8
3
|
'error',
|
|
9
|
-
'unsubscribe',
|
|
10
4
|
'cleanup',
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
'
|
|
5
|
+
// Defined in fedimint-client-rpc crate: https://github.com/fedimint/fedimint/blob/master/fedimint-client-rpc/src/lib.rs#L60
|
|
6
|
+
// TODO: generate this list automatically
|
|
7
|
+
'set_mnemonic',
|
|
8
|
+
'generate_mnemonic',
|
|
9
|
+
'get_mnemonic',
|
|
10
|
+
'join_federation',
|
|
11
|
+
'open_client',
|
|
12
|
+
'close_client',
|
|
13
|
+
'client_rpc',
|
|
14
|
+
'cancel_rpc',
|
|
15
|
+
'parse_invite_code',
|
|
16
|
+
'parse_bolt11_invoice',
|
|
17
|
+
'preview_federation',
|
|
14
18
|
];
|
|
19
|
+
const TransportResponseTypes = ['data', 'error', 'end', 'log'];
|
|
20
|
+
/**
|
|
21
|
+
* Generic Transport interface for communicating with a specific
|
|
22
|
+
* target of the FedimintClient. Can be Wasm, React Native, Node, etc.
|
|
23
|
+
*/
|
|
24
|
+
export class Transport {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.messageHandler = () => { };
|
|
27
|
+
this.errorHandler = () => { };
|
|
28
|
+
}
|
|
29
|
+
setMessageHandler(handler) {
|
|
30
|
+
this.messageHandler = handler;
|
|
31
|
+
}
|
|
32
|
+
setErrorHandler(handler) {
|
|
33
|
+
this.errorHandler = handler;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
15
36
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,MAAM;IACN,aAAa;IACb,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,MAAM;IACN,OAAO;IACP,SAAS;IACT,4HAA4H;IAC5H,yCAAyC;IACzC,cAAc;IACd,mBAAmB;IACnB,cAAc;IACd,iBAAiB;IACjB,aAAa;IACb,cAAc;IACd,YAAY;IACZ,YAAY;IACZ,mBAAmB;IACnB,sBAAsB;IACtB,oBAAoB;CACZ,CAAA;AAUV,MAAM,sBAAsB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAU,CAAA;AAYvE;;;GAGG;AACH,MAAM,OAAgB,SAAS;IAA/B;QACY,mBAAc,GAA4B,GAAG,EAAE,GAAE,CAAC,CAAA;QAClD,iBAAY,GAA0B,GAAG,EAAE,GAAE,CAAC,CAAA;IAS1D,CAAC;IANC,iBAAiB,CAAC,OAAgC;QAChD,IAAI,CAAC,cAAc,GAAG,OAAO,CAAA;IAC/B,CAAC;IACD,eAAe,CAAC,OAA8B;QAC5C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAA;IAC7B,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedimint/types",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Shared transport interfaces for Fedimint client implementations",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
],
|
|
17
17
|
"sideEffects": false,
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"typescript": "^5.
|
|
19
|
+
"typescript": "^5.9.3"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "tsc --project tsconfig.json",
|
package/src/index.ts
CHANGED
|
@@ -8,17 +8,21 @@ export type JSONValue =
|
|
|
8
8
|
|
|
9
9
|
export const TRANSPORT_MESSAGE_TYPES = [
|
|
10
10
|
'init',
|
|
11
|
-
'initialized',
|
|
12
|
-
'rpc',
|
|
13
|
-
'log',
|
|
14
|
-
'open',
|
|
15
|
-
'join',
|
|
16
11
|
'error',
|
|
17
|
-
'unsubscribe',
|
|
18
12
|
'cleanup',
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
'
|
|
13
|
+
// Defined in fedimint-client-rpc crate: https://github.com/fedimint/fedimint/blob/master/fedimint-client-rpc/src/lib.rs#L60
|
|
14
|
+
// TODO: generate this list automatically
|
|
15
|
+
'set_mnemonic',
|
|
16
|
+
'generate_mnemonic',
|
|
17
|
+
'get_mnemonic',
|
|
18
|
+
'join_federation',
|
|
19
|
+
'open_client',
|
|
20
|
+
'close_client',
|
|
21
|
+
'client_rpc',
|
|
22
|
+
'cancel_rpc',
|
|
23
|
+
'parse_invite_code',
|
|
24
|
+
'parse_bolt11_invoice',
|
|
25
|
+
'preview_federation',
|
|
22
26
|
] as const
|
|
23
27
|
|
|
24
28
|
export type TransportMessageType = (typeof TRANSPORT_MESSAGE_TYPES)[number]
|
|
@@ -29,9 +33,12 @@ export type TransportRequest = {
|
|
|
29
33
|
payload?: JSONValue
|
|
30
34
|
}
|
|
31
35
|
|
|
36
|
+
const TransportResponseTypes = ['data', 'error', 'end', 'log'] as const
|
|
37
|
+
type TransportResponseType = (typeof TransportResponseTypes)[number]
|
|
38
|
+
|
|
32
39
|
export type TransportMessage = {
|
|
33
|
-
type:
|
|
34
|
-
|
|
40
|
+
type: TransportResponseType
|
|
41
|
+
request_id?: number
|
|
35
42
|
} & Record<string, unknown>
|
|
36
43
|
|
|
37
44
|
export type TransportMessageHandler = (message: TransportMessage) => void
|
|
@@ -42,11 +49,17 @@ export type TransportErrorHandler = (error: unknown) => void
|
|
|
42
49
|
* Generic Transport interface for communicating with a specific
|
|
43
50
|
* target of the FedimintClient. Can be Wasm, React Native, Node, etc.
|
|
44
51
|
*/
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
export abstract class Transport {
|
|
53
|
+
protected messageHandler: TransportMessageHandler = () => {}
|
|
54
|
+
protected errorHandler: TransportErrorHandler = () => {}
|
|
55
|
+
abstract logger: TransportLogger
|
|
56
|
+
abstract postMessage(message: TransportRequest): void
|
|
57
|
+
setMessageHandler(handler: TransportMessageHandler): void {
|
|
58
|
+
this.messageHandler = handler
|
|
59
|
+
}
|
|
60
|
+
setErrorHandler(handler: TransportErrorHandler): void {
|
|
61
|
+
this.errorHandler = handler
|
|
62
|
+
}
|
|
50
63
|
}
|
|
51
64
|
|
|
52
65
|
/**
|