@tari-project/tari-universe-signer 0.5.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/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, The Tari Developer Community
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,3 @@
1
+ export * from "@tari-project/tari-permissions";
2
+ export * from "./signer";
3
+ export * from "./types";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "@tari-project/tari-permissions";
2
+ export * from "./signer";
3
+ export * from "./types";
@@ -0,0 +1,24 @@
1
+ import { SubmitTransactionResponse, Account, Substate, TemplateDefinition, VaultBalances, ListSubstatesResponse, SubmitTransactionRequest, TariSigner, TransactionResult } from "@tari-project/tari-signer";
2
+ import { TariUniverseSignerParameters, WindowSize, ListAccountNftFromBalancesRequest } from "./types";
3
+ import { AccountsGetBalancesResponse, ListAccountNftRequest, ListAccountNftResponse, SubstateType } from "@tari-project/wallet_jrpc_client";
4
+ export declare class TariUniverseSigner implements TariSigner {
5
+ params: TariUniverseSignerParameters;
6
+ signerName: string;
7
+ private __id;
8
+ constructor(params: TariUniverseSignerParameters);
9
+ private sendRequest;
10
+ isConnected(): boolean;
11
+ getPublicKey(): Promise<string>;
12
+ listSubstates(filter_by_template: string | null, filter_by_type: SubstateType | null, limit: number | null, offset: number | null): Promise<ListSubstatesResponse>;
13
+ getConfidentialVaultBalances(viewKeyId: number, vaultId: string, min: number | null, max: number | null): Promise<VaultBalances>;
14
+ createFreeTestCoins(): Promise<void>;
15
+ requestParentSize(): Promise<WindowSize>;
16
+ getAccount(): Promise<Account>;
17
+ getAccountBalances(componentAddress: string): Promise<AccountsGetBalancesResponse>;
18
+ getSubstate(substate_id: string): Promise<Substate>;
19
+ submitTransaction(req: SubmitTransactionRequest): Promise<SubmitTransactionResponse>;
20
+ getTransactionResult(transactionId: string): Promise<TransactionResult>;
21
+ getTemplateDefinition(template_address: string): Promise<TemplateDefinition>;
22
+ getNftsList(req: ListAccountNftRequest): Promise<ListAccountNftResponse>;
23
+ getNftsFromAccountBalances(req: ListAccountNftFromBalancesRequest): Promise<ListAccountNftResponse>;
24
+ }
package/dist/signer.js ADDED
@@ -0,0 +1,82 @@
1
+ import { sendSignerCall } from "./utils";
2
+ export class TariUniverseSigner {
3
+ params;
4
+ signerName = "TariUniverse";
5
+ __id = 0;
6
+ constructor(params) {
7
+ this.params = params;
8
+ const filterResizeEvent = function (event) {
9
+ if (event.data && event.data.type === "resize") {
10
+ const resizeEvent = new CustomEvent("resize", {
11
+ detail: { width: event.data.width, height: event.data.height },
12
+ });
13
+ window.dispatchEvent(resizeEvent);
14
+ }
15
+ };
16
+ window.addEventListener("message", (event) => filterResizeEvent(event), false);
17
+ }
18
+ async sendRequest(req) {
19
+ const id = ++this.__id;
20
+ return sendSignerCall(req, id);
21
+ }
22
+ isConnected() {
23
+ return true;
24
+ }
25
+ getPublicKey() {
26
+ return this.sendRequest({ methodName: "getPublicKey", args: [] });
27
+ }
28
+ async listSubstates(filter_by_template, filter_by_type, limit, offset) {
29
+ return this.sendRequest({
30
+ methodName: "listSubstates",
31
+ args: [filter_by_template, filter_by_type, limit, offset],
32
+ });
33
+ }
34
+ getConfidentialVaultBalances(viewKeyId, vaultId, min, max) {
35
+ return this.sendRequest({
36
+ methodName: "getConfidentialVaultBalances",
37
+ args: [viewKeyId, vaultId, min, max],
38
+ });
39
+ }
40
+ async createFreeTestCoins() {
41
+ return this.sendRequest({ methodName: "createFreeTestCoins", args: [] });
42
+ }
43
+ requestParentSize() {
44
+ return this.sendRequest({ methodName: "requestParentSize", args: [] });
45
+ }
46
+ async getAccount() {
47
+ return this.sendRequest({ methodName: "getAccount", args: [] });
48
+ }
49
+ async getAccountBalances(componentAddress) {
50
+ return this.sendRequest({
51
+ methodName: "getAccountBalances",
52
+ args: [componentAddress],
53
+ });
54
+ }
55
+ async getSubstate(substate_id) {
56
+ return this.sendRequest({
57
+ methodName: "getSubstate",
58
+ args: [substate_id],
59
+ });
60
+ }
61
+ async submitTransaction(req) {
62
+ return this.sendRequest({
63
+ methodName: "submitTransaction",
64
+ args: [req],
65
+ });
66
+ }
67
+ async getTransactionResult(transactionId) {
68
+ return this.sendRequest({
69
+ methodName: "getTransactionResult",
70
+ args: [transactionId],
71
+ });
72
+ }
73
+ async getTemplateDefinition(template_address) {
74
+ return this.sendRequest({ methodName: "getTemplateDefinition", args: [template_address] });
75
+ }
76
+ async getNftsList(req) {
77
+ return this.sendRequest({ methodName: "getNftsList", args: [req] });
78
+ }
79
+ async getNftsFromAccountBalances(req) {
80
+ return this.sendRequest({ methodName: "getNftsFromAccountBalances", args: [req] });
81
+ }
82
+ }
@@ -0,0 +1,34 @@
1
+ import { TariPermissions } from "@tari-project/tari-permissions";
2
+ import { TariUniverseSigner } from "./signer";
3
+ import { BalanceEntry } from "@tari-project/typescript-bindings";
4
+ export type TariUniverseSignerParameters = {
5
+ permissions: TariPermissions;
6
+ optionalPermissions: TariPermissions;
7
+ name?: string;
8
+ onConnection?: () => void;
9
+ };
10
+ export type WindowSize = {
11
+ width: number;
12
+ height: number;
13
+ };
14
+ export type PickMatching<T, V> = {
15
+ [K in keyof T as T[K] extends V ? K : never]: T[K];
16
+ };
17
+ export type ExtractMethods<T> = PickMatching<T, Function>;
18
+ export type SignerMethods = ExtractMethods<TariUniverseSigner>;
19
+ export type SignerMethodNames = keyof SignerMethods;
20
+ export type SignerReturnType<T extends SignerMethodNames> = Awaited<ReturnType<SignerMethods[T]>>;
21
+ export type SignerRequest<T extends SignerMethodNames> = {
22
+ id: number;
23
+ methodName: T;
24
+ args: Parameters<SignerMethods[T]>;
25
+ };
26
+ export type SignerResponse<T extends SignerMethodNames> = {
27
+ id: number;
28
+ type: "signer-call";
29
+ result: SignerReturnType<T>;
30
+ resultError?: string;
31
+ };
32
+ export interface ListAccountNftFromBalancesRequest {
33
+ balances: Array<BalanceEntry>;
34
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { SignerMethodNames, SignerRequest, SignerReturnType } from "./types";
2
+ export declare function sendSignerCall<MethodName extends SignerMethodNames>(req: Omit<SignerRequest<MethodName>, "id">, id: number): Promise<SignerReturnType<MethodName>>;
package/dist/utils.js ADDED
@@ -0,0 +1,16 @@
1
+ export function sendSignerCall(req, id) {
2
+ return new Promise((resolve, reject) => {
3
+ const event_ref = (resp) => {
4
+ if (resp.data.resultError) {
5
+ window.removeEventListener("message", event_ref);
6
+ reject(resp.data.resultError);
7
+ }
8
+ if (resp && resp.data && resp.data.id && resp.data.id === id && resp.data.type === "signer-call") {
9
+ window.removeEventListener("message", event_ref);
10
+ resolve(resp.data.result);
11
+ }
12
+ };
13
+ window.addEventListener("message", event_ref, false);
14
+ window.parent.postMessage({ ...req, id, type: "signer-call" }, "*");
15
+ });
16
+ }
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@tari-project/tari-universe-signer",
3
+ "version": "0.5.0",
4
+ "description": "",
5
+ "type": "module",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "@tari-project/typescript-bindings": "^1.5.1",
14
+ "@tari-project/wallet_jrpc_client": "^1.5.1",
15
+ "@tari-project/tari-permissions": "^0.5.0",
16
+ "@tari-project/tari-signer": "^0.5.0",
17
+ "@tari-project/tarijs-types": "^0.5.0"
18
+ },
19
+ "devDependencies": {
20
+ "@types/node": "^22.13.1",
21
+ "typescript": "^5.0.4"
22
+ },
23
+ "files": [
24
+ "/dist"
25
+ ],
26
+ "main": "dist/index.js",
27
+ "types": "dist/index.d.ts",
28
+ "scripts": {
29
+ "build": "tsc -b"
30
+ }
31
+ }