zano_web3 9.6.0 → 10.1.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/package.json +17 -9
- package/server/dist/server.d.ts +13 -2
- package/server/dist/server.js +68 -6
- package/server/dist/server.js.map +1 -1
- package/server/dist/types.d.ts +24 -24
- package/server/src/server.ts +101 -8
- package/server/src/types.ts +111 -111
- package/shared/dist/utils.d.ts +61 -0
- package/shared/dist/utils.js +188 -0
- package/shared/dist/utils.js.map +1 -1
- package/shared/src/utils.ts +276 -1
- package/web/dist/index.d.ts +2 -4
- package/web/dist/index.js +2 -4
- package/web/dist/index.js.map +1 -1
- package/web/dist/types/errors/index.d.ts +7 -0
- package/web/dist/types/errors/index.js +9 -0
- package/web/dist/types/errors/index.js.map +1 -0
- package/web/dist/types/index.d.ts +4 -0
- package/web/dist/types/index.js +5 -0
- package/web/dist/types/index.js.map +1 -0
- package/web/dist/types/params/companion-requests/index.d.ts +1 -0
- package/web/dist/types/params/companion-requests/index.js +2 -0
- package/web/dist/types/params/companion-requests/index.js.map +1 -0
- package/web/dist/types/params/companion-requests/request-permissions/index.d.ts +5 -0
- package/web/dist/types/params/companion-requests/request-permissions/index.js +2 -0
- package/web/dist/types/params/companion-requests/request-permissions/index.js.map +1 -0
- package/web/dist/types/params/index.d.ts +1 -0
- package/web/dist/types/params/index.js +2 -0
- package/web/dist/types/params/index.js.map +1 -0
- package/web/dist/types/responses/companion-methods/create-alias/index.d.ts +13 -0
- package/web/dist/types/responses/companion-methods/create-alias/index.js +10 -0
- package/web/dist/types/responses/companion-methods/create-alias/index.js.map +1 -0
- package/web/dist/types/responses/companion-methods/get-address-by-alias/index.d.ts +12 -0
- package/web/dist/types/responses/companion-methods/get-address-by-alias/index.js +8 -0
- package/web/dist/types/responses/companion-methods/get-address-by-alias/index.js.map +1 -0
- package/web/dist/types/responses/companion-methods/get-wallet-data/index.d.ts +73 -0
- package/web/dist/types/responses/companion-methods/get-wallet-data/index.js +39 -0
- package/web/dist/types/responses/companion-methods/get-wallet-data/index.js.map +1 -0
- package/web/dist/types/responses/companion-methods/index.d.ts +5 -0
- package/web/dist/types/responses/companion-methods/index.js +2 -0
- package/web/dist/types/responses/companion-methods/index.js.map +1 -0
- package/web/dist/types/responses/companion-methods/request-message-sign/index.d.ts +23 -0
- package/web/dist/types/responses/companion-methods/request-message-sign/index.js +16 -0
- package/web/dist/types/responses/companion-methods/request-message-sign/index.js.map +1 -0
- package/web/dist/types/responses/companion-methods/request-permissions/index.d.ts +13 -0
- package/web/dist/types/responses/companion-methods/request-permissions/index.js +10 -0
- package/web/dist/types/responses/companion-methods/request-permissions/index.js.map +1 -0
- package/web/dist/types/responses/index.d.ts +1 -0
- package/web/dist/types/responses/index.js +2 -0
- package/web/dist/types/responses/index.js.map +1 -0
- package/web/dist/types/special/index.d.ts +1 -0
- package/web/dist/types/special/index.js +2 -0
- package/web/dist/types/special/index.js.map +1 -0
- package/web/dist/types/special/zano-window/index.d.ts +7 -0
- package/web/dist/types/special/zano-window/index.js +2 -0
- package/web/dist/types/special/zano-window/index.js.map +1 -0
- package/web/dist/zano-wallet.d.ts +11 -0
- package/web/dist/zano-wallet.js +125 -0
- package/web/dist/zano-wallet.js.map +1 -0
- package/web/src/index.ts +4 -7
- package/web/src/types/errors/index.ts +10 -0
- package/web/src/types/index.ts +4 -0
- package/web/src/types/params/companion-requests/index.ts +1 -0
- package/web/src/types/params/companion-requests/request-permissions/index.ts +10 -0
- package/web/src/types/params/index.ts +1 -0
- package/web/src/types/responses/companion-methods/create-alias/index.ts +19 -0
- package/web/src/types/responses/companion-methods/get-address-by-alias/index.ts +18 -0
- package/web/src/types/responses/companion-methods/get-wallet-data/index.ts +52 -0
- package/web/src/types/responses/companion-methods/index.ts +5 -0
- package/web/src/types/responses/companion-methods/request-message-sign/index.ts +33 -0
- package/web/src/types/responses/companion-methods/request-permissions/index.ts +19 -0
- package/web/src/types/responses/index.ts +2 -0
- package/web/src/types/special/index.ts +1 -0
- package/web/src/types/special/zano-window/index.ts +9 -0
- package/web/src/zano-wallet.ts +161 -0
- package/web/dist/hooks.d.ts +0 -3
- package/web/dist/hooks.js +0 -14
- package/web/dist/hooks.js.map +0 -1
- package/web/dist/types.d.ts +0 -32
- package/web/dist/types.js +0 -2
- package/web/dist/types.js.map +0 -1
- package/web/dist/zanoWallet.d.ts +0 -42
- package/web/dist/zanoWallet.js +0 -156
- package/web/dist/zanoWallet.js.map +0 -1
- package/web/src/hooks.ts +0 -18
- package/web/src/types.ts +0 -35
- package/web/src/zanoWallet.ts +0 -240
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/responses/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/special/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type GlobalWindow = Window & typeof globalThis;
|
|
2
|
+
export interface ZanoWindowObject {
|
|
3
|
+
request: (str: string, params?: any, timeoutMs?: number | null) => Promise<any>;
|
|
4
|
+
}
|
|
5
|
+
export type ZanoWindow = Omit<GlobalWindow, 'Infinity'> & {
|
|
6
|
+
zano: ZanoWindowObject;
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/types/special/zano-window/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RequestPermissionsResponse, GetAddressByAliasResponse, CreateAliasResponse, RequestMessageSignResponse, CompanionPermissionsParam } from './types';
|
|
2
|
+
import { GetWalletDataResponse } from './types/responses/companion-methods/get-wallet-data';
|
|
3
|
+
declare class ZanoWallet {
|
|
4
|
+
private getZanoWallet;
|
|
5
|
+
requestPermissions: (permissions: CompanionPermissionsParam) => Promise<RequestPermissionsResponse>;
|
|
6
|
+
getWallet: () => Promise<GetWalletDataResponse>;
|
|
7
|
+
getAddressByAlias: (alias: string) => Promise<GetAddressByAliasResponse>;
|
|
8
|
+
createAlias: (alias: string) => Promise<CreateAliasResponse>;
|
|
9
|
+
requestMessageSign: (message: string) => Promise<RequestMessageSignResponse>;
|
|
10
|
+
}
|
|
11
|
+
export default ZanoWallet;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { ZanoWebError, } from './types';
|
|
2
|
+
import { createAliasCompanionResponseSchema } from './types/responses/companion-methods/create-alias';
|
|
3
|
+
import { getAddressByAliasCompanionResponseSchema } from './types/responses/companion-methods/get-address-by-alias';
|
|
4
|
+
import { getWalletDataCompanionResponseSchema } from './types/responses/companion-methods/get-wallet-data';
|
|
5
|
+
import { requestMessageSignCompanionResponseSchema } from './types/responses/companion-methods/request-message-sign';
|
|
6
|
+
import { requestPermissionsCompanionResponseSchema } from './types/responses/companion-methods/request-permissions';
|
|
7
|
+
class ZanoWallet {
|
|
8
|
+
getZanoWallet = () => {
|
|
9
|
+
const zanoWindow = window;
|
|
10
|
+
if (!zanoWindow.zano) {
|
|
11
|
+
throw new ZanoWebError({
|
|
12
|
+
message: 'Zano wallet is not available in the current window context.',
|
|
13
|
+
code: 'ZANO_WALLET_NOT_AVAILABLE',
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return zanoWindow.zano;
|
|
17
|
+
};
|
|
18
|
+
requestPermissions = async (permissions) => {
|
|
19
|
+
const companionResponseRaw = await this.getZanoWallet().request('REQUEST_ACCESS', {
|
|
20
|
+
permissions,
|
|
21
|
+
});
|
|
22
|
+
const companionResponseParsingResult = requestPermissionsCompanionResponseSchema.safeParse(companionResponseRaw);
|
|
23
|
+
if (!companionResponseParsingResult.success) {
|
|
24
|
+
throw new ZanoWebError({
|
|
25
|
+
message: 'Failed to parse companion response.',
|
|
26
|
+
code: 'INTERNAL_ERROR',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const companionResponse = companionResponseParsingResult.data;
|
|
30
|
+
if (!('success' in companionResponse)) {
|
|
31
|
+
return {
|
|
32
|
+
success: false,
|
|
33
|
+
error: companionResponse.error,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
success: true,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
getWallet = async () => {
|
|
41
|
+
const companionResponseRaw = await this.getZanoWallet().request('GET_WALLET_DATA');
|
|
42
|
+
const companionResponseParsingResult = getWalletDataCompanionResponseSchema.safeParse(companionResponseRaw);
|
|
43
|
+
if (!companionResponseParsingResult.success) {
|
|
44
|
+
throw new ZanoWebError({
|
|
45
|
+
message: 'Failed to parse companion response.',
|
|
46
|
+
code: 'INTERNAL_ERROR',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const companionResponse = companionResponseParsingResult.data;
|
|
50
|
+
if (!('data' in companionResponse)) {
|
|
51
|
+
return {
|
|
52
|
+
success: false,
|
|
53
|
+
error: companionResponse.error,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
success: true,
|
|
58
|
+
data: companionResponse.data,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
getAddressByAlias = async (alias) => {
|
|
62
|
+
const companionResponseRaw = await this.getZanoWallet().request('GET_ALIAS_DETAILS', { alias });
|
|
63
|
+
const companionResponseParsingResult = getAddressByAliasCompanionResponseSchema.safeParse(companionResponseRaw);
|
|
64
|
+
if (!companionResponseParsingResult.success) {
|
|
65
|
+
throw new ZanoWebError({
|
|
66
|
+
message: 'Failed to parse companion response.',
|
|
67
|
+
code: 'INTERNAL_ERROR',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const companionResponse = companionResponseParsingResult.data;
|
|
71
|
+
if (typeof companionResponse !== 'string') {
|
|
72
|
+
return {
|
|
73
|
+
success: false,
|
|
74
|
+
error: companionResponse.error,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
success: true,
|
|
79
|
+
data: companionResponse,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
createAlias = async (alias) => {
|
|
83
|
+
const companionResponseRaw = await this.getZanoWallet().request('CREATE_ALIAS', { alias });
|
|
84
|
+
const companionResponseParsingResult = createAliasCompanionResponseSchema.safeParse(companionResponseRaw);
|
|
85
|
+
if (!companionResponseParsingResult.success) {
|
|
86
|
+
throw new ZanoWebError({
|
|
87
|
+
message: 'Failed to parse companion response.',
|
|
88
|
+
code: 'INTERNAL_ERROR',
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const companionResponse = companionResponseParsingResult.data;
|
|
92
|
+
if (!('data' in companionResponse)) {
|
|
93
|
+
return {
|
|
94
|
+
success: false,
|
|
95
|
+
error: companionResponse.error,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
success: true,
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
requestMessageSign = async (message) => {
|
|
103
|
+
const companionResponseRaw = await this.getZanoWallet().request('REQUEST_MESSAGE_SIGN', { message });
|
|
104
|
+
const companionResponseParsingResult = requestMessageSignCompanionResponseSchema.safeParse(companionResponseRaw);
|
|
105
|
+
if (!companionResponseParsingResult.success) {
|
|
106
|
+
throw new ZanoWebError({
|
|
107
|
+
message: 'Failed to parse companion response.',
|
|
108
|
+
code: 'INTERNAL_ERROR',
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const companionResponse = companionResponseParsingResult.data;
|
|
112
|
+
if (!('data' in companionResponse)) {
|
|
113
|
+
return {
|
|
114
|
+
success: false,
|
|
115
|
+
error: companionResponse.error,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
success: true,
|
|
120
|
+
data: companionResponse.data.result,
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export default ZanoWallet;
|
|
125
|
+
//# sourceMappingURL=zano-wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zano-wallet.js","sourceRoot":"","sources":["../src/zano-wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,YAAY,GAMf,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,kCAAkC,EAAE,MAAM,kDAAkD,CAAC;AACtG,OAAO,EAAE,wCAAwC,EAAE,MAAM,0DAA0D,CAAC;AACpH,OAAO,EAAE,oCAAoC,EAAyB,MAAM,qDAAqD,CAAC;AAClI,OAAO,EAAE,yCAAyC,EAAE,MAAM,0DAA0D,CAAC;AACrH,OAAO,EAAE,yCAAyC,EAAE,MAAM,yDAAyD,CAAC;AAGpH,MAAM,UAAU;IACJ,aAAa,GAAG,GAAqB,EAAE;QAC3C,MAAM,UAAU,GAAG,MAA+B,CAAC;QAEnD,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YACnB,MAAM,IAAI,YAAY,CAAC;gBACnB,OAAO,EAAE,6DAA6D;gBACtE,IAAI,EAAE,2BAA2B;aACpC,CAAC,CAAC;QACP,CAAC;QAED,OAAO,UAAU,CAAC,IAAI,CAAC;IAC3B,CAAC,CAAA;IAED,kBAAkB,GAAG,KAAK,EAAE,WAAsC,EAAuC,EAAE;QACvG,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,gBAAgB,EAAE;YAC9E,WAAW;SACd,CAAC,CAAC;QAEH,MAAM,8BAA8B,GAAG,yCAAyC,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;QACjH,IAAI,CAAC,8BAA8B,CAAC,OAAO,EAAE,CAAC;YAC1C,MAAM,IAAI,YAAY,CAAC;gBACnB,OAAO,EAAE,qCAAqC;gBAC9C,IAAI,EAAE,gBAAgB;aACzB,CAAC,CAAC;QACP,CAAC;QAED,MAAM,iBAAiB,GAAG,8BAA8B,CAAC,I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AE,CAAC,CAAC;QAErG,MAAM,8BAA8B,GAAG,yCAAyC,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;QACjH,IAAI,CAAC,8BAA8B,CAAC,OAAO,EAAE,CAAC;YAC1C,MAAM,IAAI,YAAY,CAAC;gBACnB,OAAO,EAAE,qCAAqC;gBAC9C,IAAI,EAAE,gBAAgB;aACzB,CAAC,CAAC;QACP,CAAC;QAED,MAAM,iBAAiB,GAAG,8BAA8B,CAAC,IAAI,CAAC;QAE9D,IAAI,CAAC,CAAC,MAAM,IAAI,iBAAiB,CAAC,EAAE,CAAC;YACjC,OAAO;gBACH,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,iBAAiB,CAAC,KAAK;aACjC,CAAC;QACN,CAAC;QAED,OAAO;YACH,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,iBAAiB,CAAC,IAAI,CAAC,MAAM;SACtC,CAAC;IACN,CAAC,CAAA;CACJ;AAED,eAAe,UAAU,CAAC"}
|
package/web/src/index.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CompanionPermission, CompanionPermissionsParam, PermissionType } from './request-permissions';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './companion-requests';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
|
|
3
|
+
export const createAliasCompanionResponseSchema = z.union([
|
|
4
|
+
z.object({
|
|
5
|
+
data: z.literal(true),
|
|
6
|
+
}),
|
|
7
|
+
z.object({
|
|
8
|
+
error: z.string(),
|
|
9
|
+
})
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
export type CreateAliasCompanionResponse = z.infer<typeof createAliasCompanionResponseSchema>;
|
|
13
|
+
|
|
14
|
+
export type CreateAliasResponse = {
|
|
15
|
+
success: true;
|
|
16
|
+
} | {
|
|
17
|
+
success: false;
|
|
18
|
+
error: string;
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
|
|
3
|
+
export const getAddressByAliasCompanionResponseSchema = z.union([
|
|
4
|
+
z.string(),
|
|
5
|
+
z.object({
|
|
6
|
+
error: z.string(),
|
|
7
|
+
})
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
export type GetAddressByAliasCompanionResponse = z.infer<typeof getAddressByAliasCompanionResponseSchema>;
|
|
11
|
+
|
|
12
|
+
export type GetAddressByAliasResponse = {
|
|
13
|
+
success: true;
|
|
14
|
+
data: string;
|
|
15
|
+
} | {
|
|
16
|
+
success: false;
|
|
17
|
+
error: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
|
|
3
|
+
const getWalletDataCompanionResponseWalletSchema = z.object({
|
|
4
|
+
address: z.string(),
|
|
5
|
+
alias: z.string(),
|
|
6
|
+
balance: z.string().optional(),
|
|
7
|
+
assets: z.array(z.object({
|
|
8
|
+
name: z.string(),
|
|
9
|
+
ticker: z.string(),
|
|
10
|
+
assetId: z.string(),
|
|
11
|
+
decimalPoint: z.number(),
|
|
12
|
+
balance: z.string(),
|
|
13
|
+
unlockedBalance: z.string(),
|
|
14
|
+
})).optional(),
|
|
15
|
+
transactions: z.array(z.object({
|
|
16
|
+
isConfirmed: z.boolean(),
|
|
17
|
+
txHash: z.string(),
|
|
18
|
+
blobSize: z.custom<number>(),
|
|
19
|
+
timestamp: z.custom<number>(),
|
|
20
|
+
height: z.number(),
|
|
21
|
+
paymentId: z.custom<string>(),
|
|
22
|
+
comment: z.custom<string>(),
|
|
23
|
+
fee: z.custom<string>(),
|
|
24
|
+
isInitiator: z.boolean(),
|
|
25
|
+
transfers: z.array(z.object({
|
|
26
|
+
amount: z.string(),
|
|
27
|
+
assetId: z.string(),
|
|
28
|
+
incoming: z.boolean(),
|
|
29
|
+
})),
|
|
30
|
+
})).optional(),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export type GetWalletDataResponseWallet = z.infer<typeof getWalletDataCompanionResponseWalletSchema>;
|
|
34
|
+
|
|
35
|
+
export const getWalletDataCompanionResponseSchema = z.union([
|
|
36
|
+
z.object({
|
|
37
|
+
data: getWalletDataCompanionResponseWalletSchema,
|
|
38
|
+
}),
|
|
39
|
+
z.object({
|
|
40
|
+
error: z.string(),
|
|
41
|
+
})
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
export type GetWalletDataCompanionResponse = z.infer<typeof getWalletDataCompanionResponseSchema>;
|
|
45
|
+
|
|
46
|
+
export type GetWalletDataResponse = {
|
|
47
|
+
success: true;
|
|
48
|
+
data: GetWalletDataResponseWallet;
|
|
49
|
+
} | {
|
|
50
|
+
success: false;
|
|
51
|
+
error: string;
|
|
52
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { RequestPermissionsResponse } from './request-permissions';
|
|
2
|
+
export { GetWalletDataResponse, GetWalletDataResponseWallet } from './get-wallet-data';
|
|
3
|
+
export { GetAddressByAliasResponse } from './get-address-by-alias';
|
|
4
|
+
export { CreateAliasResponse } from './create-alias';
|
|
5
|
+
export { RequestMessageSignResponse, RequestMessageSignData } from './request-message-sign';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
|
|
3
|
+
const requestMessageSignCompanionResponseDataSchema = z.object({
|
|
4
|
+
result: z.object({
|
|
5
|
+
pkey: z.string(),
|
|
6
|
+
sig: z.string(),
|
|
7
|
+
})
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const requestMessageSignCompanionResponseSchema = z.union([
|
|
11
|
+
z.object({
|
|
12
|
+
data: requestMessageSignCompanionResponseDataSchema,
|
|
13
|
+
}),
|
|
14
|
+
z.object({
|
|
15
|
+
error: z.string(),
|
|
16
|
+
})
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export type RequestMessageSignCompanionResponse = z.infer<typeof requestMessageSignCompanionResponseSchema>;
|
|
21
|
+
|
|
22
|
+
export type RequestMessageSignData = {
|
|
23
|
+
pkey: string;
|
|
24
|
+
sig: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type RequestMessageSignResponse = {
|
|
28
|
+
success: true;
|
|
29
|
+
data: RequestMessageSignData;
|
|
30
|
+
} | {
|
|
31
|
+
success: false;
|
|
32
|
+
error: string;
|
|
33
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
|
|
3
|
+
export const requestPermissionsCompanionResponseSchema = z.union([
|
|
4
|
+
z.object({
|
|
5
|
+
success: z.literal(true),
|
|
6
|
+
}),
|
|
7
|
+
z.object({
|
|
8
|
+
error: z.string(),
|
|
9
|
+
})
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
export type RequestPermissionsCompanionResponse = z.infer<typeof requestPermissionsCompanionResponseSchema>;
|
|
13
|
+
|
|
14
|
+
export type RequestPermissionsResponse = {
|
|
15
|
+
success: true;
|
|
16
|
+
} | {
|
|
17
|
+
success: false;
|
|
18
|
+
error: string;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type GlobalWindow = Window & typeof globalThis;
|
|
2
|
+
|
|
3
|
+
export interface ZanoWindowObject {
|
|
4
|
+
request: (str: string, params?: any, timeoutMs?: number | null) => Promise<any>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type ZanoWindow = Omit<GlobalWindow, 'Infinity'> & {
|
|
8
|
+
zano: ZanoWindowObject
|
|
9
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ZanoWebError,
|
|
3
|
+
RequestPermissionsResponse,
|
|
4
|
+
GetAddressByAliasResponse,
|
|
5
|
+
CreateAliasResponse,
|
|
6
|
+
RequestMessageSignResponse,
|
|
7
|
+
CompanionPermissionsParam,
|
|
8
|
+
} from './types';
|
|
9
|
+
import { createAliasCompanionResponseSchema } from './types/responses/companion-methods/create-alias';
|
|
10
|
+
import { getAddressByAliasCompanionResponseSchema } from './types/responses/companion-methods/get-address-by-alias';
|
|
11
|
+
import { getWalletDataCompanionResponseSchema, GetWalletDataResponse } from './types/responses/companion-methods/get-wallet-data';
|
|
12
|
+
import { requestMessageSignCompanionResponseSchema } from './types/responses/companion-methods/request-message-sign';
|
|
13
|
+
import { requestPermissionsCompanionResponseSchema } from './types/responses/companion-methods/request-permissions';
|
|
14
|
+
import { ZanoWindowObject, ZanoWindow } from './types/special/zano-window';
|
|
15
|
+
|
|
16
|
+
class ZanoWallet {
|
|
17
|
+
private getZanoWallet = (): ZanoWindowObject => {
|
|
18
|
+
const zanoWindow = window as unknown as ZanoWindow;
|
|
19
|
+
|
|
20
|
+
if (!zanoWindow.zano) {
|
|
21
|
+
throw new ZanoWebError({
|
|
22
|
+
message: 'Zano wallet is not available in the current window context.',
|
|
23
|
+
code: 'ZANO_WALLET_NOT_AVAILABLE',
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return zanoWindow.zano;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
requestPermissions = async (permissions: CompanionPermissionsParam): Promise<RequestPermissionsResponse> => {
|
|
31
|
+
const companionResponseRaw = await this.getZanoWallet().request('REQUEST_ACCESS', {
|
|
32
|
+
permissions,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const companionResponseParsingResult = requestPermissionsCompanionResponseSchema.safeParse(companionResponseRaw);
|
|
36
|
+
if (!companionResponseParsingResult.success) {
|
|
37
|
+
throw new ZanoWebError({
|
|
38
|
+
message: 'Failed to parse companion response.',
|
|
39
|
+
code: 'INTERNAL_ERROR',
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const companionResponse = companionResponseParsingResult.data;
|
|
44
|
+
|
|
45
|
+
if (!('success' in companionResponse)) {
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
error: companionResponse.error,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
success: true,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getWallet = async (): Promise<GetWalletDataResponse> => {
|
|
58
|
+
const companionResponseRaw = await this.getZanoWallet().request('GET_WALLET_DATA');
|
|
59
|
+
|
|
60
|
+
const companionResponseParsingResult = getWalletDataCompanionResponseSchema.safeParse(companionResponseRaw);
|
|
61
|
+
if (!companionResponseParsingResult.success) {
|
|
62
|
+
throw new ZanoWebError({
|
|
63
|
+
message: 'Failed to parse companion response.',
|
|
64
|
+
code: 'INTERNAL_ERROR',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const companionResponse = companionResponseParsingResult.data;
|
|
69
|
+
|
|
70
|
+
if (!('data' in companionResponse)) {
|
|
71
|
+
return {
|
|
72
|
+
success: false,
|
|
73
|
+
error: companionResponse.error,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
success: true,
|
|
79
|
+
data: companionResponse.data,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
getAddressByAlias = async (alias: string): Promise<GetAddressByAliasResponse> => {
|
|
84
|
+
const companionResponseRaw = await this.getZanoWallet().request('GET_ALIAS_DETAILS', { alias });
|
|
85
|
+
|
|
86
|
+
const companionResponseParsingResult = getAddressByAliasCompanionResponseSchema.safeParse(companionResponseRaw);
|
|
87
|
+
if (!companionResponseParsingResult.success) {
|
|
88
|
+
throw new ZanoWebError({
|
|
89
|
+
message: 'Failed to parse companion response.',
|
|
90
|
+
code: 'INTERNAL_ERROR',
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const companionResponse = companionResponseParsingResult.data;
|
|
95
|
+
|
|
96
|
+
if (typeof companionResponse !== 'string') {
|
|
97
|
+
return {
|
|
98
|
+
success: false,
|
|
99
|
+
error: companionResponse.error,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
success: true,
|
|
105
|
+
data: companionResponse,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
createAlias = async (alias: string): Promise<CreateAliasResponse> => {
|
|
110
|
+
const companionResponseRaw = await this.getZanoWallet().request('CREATE_ALIAS', { alias });
|
|
111
|
+
|
|
112
|
+
const companionResponseParsingResult = createAliasCompanionResponseSchema.safeParse(companionResponseRaw);
|
|
113
|
+
if (!companionResponseParsingResult.success) {
|
|
114
|
+
throw new ZanoWebError({
|
|
115
|
+
message: 'Failed to parse companion response.',
|
|
116
|
+
code: 'INTERNAL_ERROR',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const companionResponse = companionResponseParsingResult.data;
|
|
121
|
+
|
|
122
|
+
if (!('data' in companionResponse)) {
|
|
123
|
+
return {
|
|
124
|
+
success: false,
|
|
125
|
+
error: companionResponse.error,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
success: true,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
requestMessageSign = async (message: string): Promise<RequestMessageSignResponse> => {
|
|
135
|
+
const companionResponseRaw = await this.getZanoWallet().request('REQUEST_MESSAGE_SIGN', { message });
|
|
136
|
+
|
|
137
|
+
const companionResponseParsingResult = requestMessageSignCompanionResponseSchema.safeParse(companionResponseRaw);
|
|
138
|
+
if (!companionResponseParsingResult.success) {
|
|
139
|
+
throw new ZanoWebError({
|
|
140
|
+
message: 'Failed to parse companion response.',
|
|
141
|
+
code: 'INTERNAL_ERROR',
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const companionResponse = companionResponseParsingResult.data;
|
|
146
|
+
|
|
147
|
+
if (!('data' in companionResponse)) {
|
|
148
|
+
return {
|
|
149
|
+
success: false,
|
|
150
|
+
error: companionResponse.error,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
success: true,
|
|
156
|
+
data: companionResponse.data.result,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export default ZanoWallet;
|
package/web/dist/hooks.d.ts
DELETED
package/web/dist/hooks.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import ZanoWallet from './zanoWallet';
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
3
|
-
function useZanoWallet(params) {
|
|
4
|
-
const [zanoWallet, setZanoWallet] = useState(null);
|
|
5
|
-
useEffect(() => {
|
|
6
|
-
if (typeof window === 'undefined') {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
setZanoWallet(new ZanoWallet(params));
|
|
10
|
-
}, []);
|
|
11
|
-
return zanoWallet;
|
|
12
|
-
}
|
|
13
|
-
export { useZanoWallet };
|
|
14
|
-
//# sourceMappingURL=hooks.js.map
|
package/web/dist/hooks.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,UAAgC,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,SAAS,aAAa,CAAC,MAAwB;IAC3C,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAoB,IAAI,CAAC,CAAC;IAEtE,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAChC,OAAO;QACX,CAAC;QAED,aAAa,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1C,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,UAAU,CAAC;AACtB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
package/web/dist/types.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export interface Asset {
|
|
2
|
-
name: string;
|
|
3
|
-
ticker: string;
|
|
4
|
-
assetId: string;
|
|
5
|
-
decimalPoint: number;
|
|
6
|
-
balance: string;
|
|
7
|
-
unlockedBalance: string;
|
|
8
|
-
}
|
|
9
|
-
export interface Transfer {
|
|
10
|
-
amount: string;
|
|
11
|
-
assetId: string;
|
|
12
|
-
incoming: boolean;
|
|
13
|
-
}
|
|
14
|
-
export interface Transaction {
|
|
15
|
-
isConfirmed: boolean;
|
|
16
|
-
txHash: string;
|
|
17
|
-
blobSize: number;
|
|
18
|
-
timestamp: number;
|
|
19
|
-
height: number;
|
|
20
|
-
paymentId: string;
|
|
21
|
-
comment: string;
|
|
22
|
-
fee: string;
|
|
23
|
-
isInitiator: boolean;
|
|
24
|
-
transfers: Transfer[];
|
|
25
|
-
}
|
|
26
|
-
export interface Wallet {
|
|
27
|
-
address: string;
|
|
28
|
-
alias: string;
|
|
29
|
-
balance: string;
|
|
30
|
-
assets: Asset[];
|
|
31
|
-
transactions: Transaction[];
|
|
32
|
-
}
|
package/web/dist/types.js
DELETED
package/web/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/web/dist/zanoWallet.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Wallet } from './types';
|
|
2
|
-
export interface ZanoWalletParams {
|
|
3
|
-
authPath: string;
|
|
4
|
-
useLocalStorage?: boolean;
|
|
5
|
-
aliasRequired?: boolean;
|
|
6
|
-
customLocalStorageKey?: string;
|
|
7
|
-
customNonce?: string;
|
|
8
|
-
customServerPath?: string;
|
|
9
|
-
disableServerRequest?: boolean;
|
|
10
|
-
onConnectStart?: (...params: any) => any;
|
|
11
|
-
onConnectEnd?: (...params: any) => any;
|
|
12
|
-
onConnectError?: (...params: any) => any;
|
|
13
|
-
beforeConnect?: (...params: any) => any;
|
|
14
|
-
onLocalConnectEnd?: (...params: any) => any;
|
|
15
|
-
}
|
|
16
|
-
interface WalletCredentials {
|
|
17
|
-
nonce: string;
|
|
18
|
-
signature: string;
|
|
19
|
-
publicKey: string;
|
|
20
|
-
address: string;
|
|
21
|
-
}
|
|
22
|
-
type PermissionType = 'general' | 'balance' | 'history';
|
|
23
|
-
interface CompanionPermission {
|
|
24
|
-
type: PermissionType;
|
|
25
|
-
}
|
|
26
|
-
declare class ZanoWallet {
|
|
27
|
-
private DEFAULT_LOCAL_STORAGE_KEY;
|
|
28
|
-
private localStorageKey;
|
|
29
|
-
private params;
|
|
30
|
-
private zanoWallet;
|
|
31
|
-
constructor(params: ZanoWalletParams);
|
|
32
|
-
private handleError;
|
|
33
|
-
getSavedWalletCredentials(): WalletCredentials | undefined;
|
|
34
|
-
setWalletCredentials(credentials: WalletCredentials | undefined): void;
|
|
35
|
-
cleanWalletCredentials(): void;
|
|
36
|
-
requestPermissions(permissions: CompanionPermission[]): Promise<any>;
|
|
37
|
-
connect(): Promise<true | void>;
|
|
38
|
-
getWallet(): Promise<Wallet>;
|
|
39
|
-
getAddressByAlias(alias: string): Promise<string | undefined>;
|
|
40
|
-
createAlias(alias: string): Promise<any>;
|
|
41
|
-
}
|
|
42
|
-
export default ZanoWallet;
|