@pagopa/io-react-native-wallet 0.11.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. package/lib/commonjs/client/generated/wallet-provider.js +126 -0
  2. package/lib/commonjs/client/generated/wallet-provider.js.map +1 -0
  3. package/lib/commonjs/client/index.js +41 -0
  4. package/lib/commonjs/client/index.js.map +1 -0
  5. package/lib/commonjs/index.js +10 -1
  6. package/lib/commonjs/index.js.map +1 -1
  7. package/lib/commonjs/utils/errors.js +29 -1
  8. package/lib/commonjs/utils/errors.js.map +1 -1
  9. package/lib/commonjs/utils/integrity.js +2 -0
  10. package/lib/commonjs/utils/integrity.js.map +1 -0
  11. package/lib/commonjs/wallet-instance/index.js +29 -0
  12. package/lib/commonjs/wallet-instance/index.js.map +1 -0
  13. package/lib/commonjs/wallet-instance-attestation/issuing.js +48 -66
  14. package/lib/commonjs/wallet-instance-attestation/issuing.js.map +1 -1
  15. package/lib/commonjs/wallet-instance-attestation/types.js +1 -1
  16. package/lib/commonjs/wallet-instance-attestation/types.js.map +1 -1
  17. package/lib/module/client/generated/wallet-provider.js +105 -0
  18. package/lib/module/client/generated/wallet-provider.js.map +1 -0
  19. package/lib/module/client/index.js +34 -0
  20. package/lib/module/client/index.js.map +1 -0
  21. package/lib/module/index.js +3 -1
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/sd-jwt/verifier.js.map +1 -1
  24. package/lib/module/utils/errors.js +27 -0
  25. package/lib/module/utils/errors.js.map +1 -1
  26. package/lib/module/utils/integrity.js +2 -0
  27. package/lib/module/utils/integrity.js.map +1 -0
  28. package/lib/module/wallet-instance/index.js +23 -0
  29. package/lib/module/wallet-instance/index.js.map +1 -0
  30. package/lib/module/wallet-instance-attestation/issuing.js +48 -67
  31. package/lib/module/wallet-instance-attestation/issuing.js.map +1 -1
  32. package/lib/module/wallet-instance-attestation/types.js +1 -1
  33. package/lib/module/wallet-instance-attestation/types.js.map +1 -1
  34. package/lib/typescript/client/generated/wallet-provider.d.ts +242 -0
  35. package/lib/typescript/client/generated/wallet-provider.d.ts.map +1 -0
  36. package/lib/typescript/client/index.d.ts +7 -0
  37. package/lib/typescript/client/index.d.ts.map +1 -0
  38. package/lib/typescript/index.d.ts +5 -1
  39. package/lib/typescript/index.d.ts.map +1 -1
  40. package/lib/typescript/utils/errors.d.ts +13 -0
  41. package/lib/typescript/utils/errors.d.ts.map +1 -1
  42. package/lib/typescript/utils/integrity.d.ts +21 -0
  43. package/lib/typescript/utils/integrity.d.ts.map +1 -0
  44. package/lib/typescript/wallet-instance/index.d.ts +7 -0
  45. package/lib/typescript/wallet-instance/index.d.ts.map +1 -0
  46. package/lib/typescript/wallet-instance-attestation/issuing.d.ts +15 -3
  47. package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +1 -1
  48. package/lib/typescript/wallet-instance-attestation/types.d.ts +5 -5
  49. package/package.json +8 -5
  50. package/src/client/generated/wallet-provider.ts +170 -0
  51. package/src/client/index.ts +58 -0
  52. package/src/index.ts +7 -0
  53. package/src/sd-jwt/__test__/converters.test.js +24 -0
  54. package/src/sd-jwt/verifier.js +12 -0
  55. package/src/utils/errors.ts +28 -0
  56. package/src/utils/integrity.ts +23 -0
  57. package/src/wallet-instance/index.ts +29 -0
  58. package/src/wallet-instance-attestation/issuing.ts +68 -101
  59. package/src/wallet-instance-attestation/types.ts +1 -1
@@ -0,0 +1,242 @@
1
+ import z from "zod";
2
+ export type ProblemDetail = z.infer<typeof ProblemDetail>;
3
+ export declare const ProblemDetail: z.ZodObject<{
4
+ type: z.ZodOptional<z.ZodString>;
5
+ title: z.ZodOptional<z.ZodString>;
6
+ status: z.ZodOptional<z.ZodNumber>;
7
+ detail: z.ZodOptional<z.ZodString>;
8
+ instance: z.ZodOptional<z.ZodString>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ type?: string | undefined;
11
+ title?: string | undefined;
12
+ status?: number | undefined;
13
+ detail?: string | undefined;
14
+ instance?: string | undefined;
15
+ }, {
16
+ type?: string | undefined;
17
+ title?: string | undefined;
18
+ status?: number | undefined;
19
+ detail?: string | undefined;
20
+ instance?: string | undefined;
21
+ }>;
22
+ export type FiscalCode = z.infer<typeof FiscalCode>;
23
+ export declare const FiscalCode: z.ZodString;
24
+ export type Id = z.infer<typeof Id>;
25
+ export declare const Id: z.ZodString;
26
+ export type get_GetEntityConfiguration = typeof get_GetEntityConfiguration;
27
+ export declare const get_GetEntityConfiguration: {
28
+ method: z.ZodLiteral<"GET">;
29
+ path: z.ZodLiteral<"/.well-known/openid-federation">;
30
+ parameters: z.ZodNever;
31
+ response: z.ZodUnknown;
32
+ };
33
+ export type get_GetNonce = typeof get_GetNonce;
34
+ export declare const get_GetNonce: {
35
+ method: z.ZodLiteral<"GET">;
36
+ path: z.ZodLiteral<"/nonce">;
37
+ parameters: z.ZodNever;
38
+ response: z.ZodObject<{
39
+ nonce: z.ZodString;
40
+ }, "strip", z.ZodTypeAny, {
41
+ nonce: string;
42
+ }, {
43
+ nonce: string;
44
+ }>;
45
+ };
46
+ export type post_CreateWalletInstance = typeof post_CreateWalletInstance;
47
+ export declare const post_CreateWalletInstance: {
48
+ method: z.ZodLiteral<"POST">;
49
+ path: z.ZodLiteral<"/wallet-instances">;
50
+ parameters: z.ZodObject<{
51
+ body: z.ZodObject<{
52
+ challenge: z.ZodString;
53
+ key_attestation: z.ZodString;
54
+ hardware_key_tag: z.ZodString;
55
+ }, "strip", z.ZodTypeAny, {
56
+ challenge: string;
57
+ key_attestation: string;
58
+ hardware_key_tag: string;
59
+ }, {
60
+ challenge: string;
61
+ key_attestation: string;
62
+ hardware_key_tag: string;
63
+ }>;
64
+ }, "strip", z.ZodTypeAny, {
65
+ body: {
66
+ challenge: string;
67
+ key_attestation: string;
68
+ hardware_key_tag: string;
69
+ };
70
+ }, {
71
+ body: {
72
+ challenge: string;
73
+ key_attestation: string;
74
+ hardware_key_tag: string;
75
+ };
76
+ }>;
77
+ response: z.ZodUnknown;
78
+ };
79
+ export type post_CreateWalletAttestation = typeof post_CreateWalletAttestation;
80
+ export declare const post_CreateWalletAttestation: {
81
+ method: z.ZodLiteral<"POST">;
82
+ path: z.ZodLiteral<"/token">;
83
+ parameters: z.ZodObject<{
84
+ body: z.ZodObject<{
85
+ grant_type: z.ZodLiteral<"urn:ietf:params:oauth:grant-type:jwt-bearer">;
86
+ assertion: z.ZodString;
87
+ }, "strip", z.ZodTypeAny, {
88
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer";
89
+ assertion: string;
90
+ }, {
91
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer";
92
+ assertion: string;
93
+ }>;
94
+ }, "strip", z.ZodTypeAny, {
95
+ body: {
96
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer";
97
+ assertion: string;
98
+ };
99
+ }, {
100
+ body: {
101
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer";
102
+ assertion: string;
103
+ };
104
+ }>;
105
+ response: z.ZodUnknown;
106
+ };
107
+ export declare const EndpointByMethod: {
108
+ get: {
109
+ "/.well-known/openid-federation": {
110
+ method: z.ZodLiteral<"GET">;
111
+ path: z.ZodLiteral<"/.well-known/openid-federation">;
112
+ parameters: z.ZodNever;
113
+ response: z.ZodUnknown;
114
+ };
115
+ "/nonce": {
116
+ method: z.ZodLiteral<"GET">;
117
+ path: z.ZodLiteral<"/nonce">;
118
+ parameters: z.ZodNever;
119
+ response: z.ZodObject<{
120
+ nonce: z.ZodString;
121
+ }, "strip", z.ZodTypeAny, {
122
+ nonce: string;
123
+ }, {
124
+ nonce: string;
125
+ }>;
126
+ };
127
+ };
128
+ post: {
129
+ "/wallet-instances": {
130
+ method: z.ZodLiteral<"POST">;
131
+ path: z.ZodLiteral<"/wallet-instances">;
132
+ parameters: z.ZodObject<{
133
+ body: z.ZodObject<{
134
+ challenge: z.ZodString;
135
+ key_attestation: z.ZodString;
136
+ hardware_key_tag: z.ZodString;
137
+ }, "strip", z.ZodTypeAny, {
138
+ challenge: string;
139
+ key_attestation: string;
140
+ hardware_key_tag: string;
141
+ }, {
142
+ challenge: string;
143
+ key_attestation: string;
144
+ hardware_key_tag: string;
145
+ }>;
146
+ }, "strip", z.ZodTypeAny, {
147
+ body: {
148
+ challenge: string;
149
+ key_attestation: string;
150
+ hardware_key_tag: string;
151
+ };
152
+ }, {
153
+ body: {
154
+ challenge: string;
155
+ key_attestation: string;
156
+ hardware_key_tag: string;
157
+ };
158
+ }>;
159
+ response: z.ZodUnknown;
160
+ };
161
+ "/token": {
162
+ method: z.ZodLiteral<"POST">;
163
+ path: z.ZodLiteral<"/token">;
164
+ parameters: z.ZodObject<{
165
+ body: z.ZodObject<{
166
+ grant_type: z.ZodLiteral<"urn:ietf:params:oauth:grant-type:jwt-bearer">;
167
+ assertion: z.ZodString;
168
+ }, "strip", z.ZodTypeAny, {
169
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer";
170
+ assertion: string;
171
+ }, {
172
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer";
173
+ assertion: string;
174
+ }>;
175
+ }, "strip", z.ZodTypeAny, {
176
+ body: {
177
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer";
178
+ assertion: string;
179
+ };
180
+ }, {
181
+ body: {
182
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer";
183
+ assertion: string;
184
+ };
185
+ }>;
186
+ response: z.ZodUnknown;
187
+ };
188
+ };
189
+ };
190
+ export type EndpointByMethod = typeof EndpointByMethod;
191
+ export type GetEndpoints = EndpointByMethod["get"];
192
+ export type PostEndpoints = EndpointByMethod["post"];
193
+ export type AllEndpoints = EndpointByMethod[keyof EndpointByMethod];
194
+ export type EndpointParameters = {
195
+ body?: unknown;
196
+ query?: Record<string, unknown>;
197
+ header?: Record<string, unknown>;
198
+ path?: Record<string, unknown>;
199
+ };
200
+ export type MutationMethod = "post" | "put" | "patch" | "delete";
201
+ export type Method = "get" | "head" | MutationMethod;
202
+ export type DefaultEndpoint = {
203
+ parameters?: EndpointParameters | undefined;
204
+ response: unknown;
205
+ };
206
+ export type Endpoint<TConfig extends DefaultEndpoint = DefaultEndpoint> = {
207
+ operationId: string;
208
+ method: Method;
209
+ path: string;
210
+ parameters?: TConfig["parameters"];
211
+ meta: {
212
+ alias: string;
213
+ hasParameters: boolean;
214
+ areParametersRequired: boolean;
215
+ };
216
+ response: TConfig["response"];
217
+ };
218
+ type Fetcher = (method: Method, url: string, parameters?: EndpointParameters | undefined) => Promise<Endpoint["response"]>;
219
+ type RequiredKeys<T> = {
220
+ [P in keyof T]-?: undefined extends T[P] ? never : P;
221
+ }[keyof T];
222
+ type MaybeOptionalArg<T> = RequiredKeys<T> extends never ? [config?: T] : [config: T];
223
+ export declare class ApiClient {
224
+ fetcher: Fetcher;
225
+ baseUrl: string;
226
+ constructor(fetcher: Fetcher);
227
+ setBaseUrl(baseUrl: string): this;
228
+ get<Path extends keyof GetEndpoints, TEndpoint extends GetEndpoints[Path]>(path: Path, ...params: MaybeOptionalArg<z.infer<TEndpoint["parameters"]>>): Promise<z.infer<TEndpoint["response"]>>;
229
+ post<Path extends keyof PostEndpoints, TEndpoint extends PostEndpoints[Path]>(path: Path, ...params: MaybeOptionalArg<z.infer<TEndpoint["parameters"]>>): Promise<z.infer<TEndpoint["response"]>>;
230
+ }
231
+ export declare function createApiClient(fetcher: Fetcher, baseUrl?: string): ApiClient;
232
+ export {};
233
+ /**
234
+ Example usage:
235
+ const api = createApiClient((method, url, params) =>
236
+ fetch(url, { method, body: JSON.stringify(params) }).then((res) => res.json()),
237
+ );
238
+ api.get("/users").then((users) => console.log(users));
239
+ api.post("/users", { body: { name: "John" } }).then((user) => console.log(user));
240
+ api.put("/users/:id", { path: { id: 1 }, body: { name: "John" } }).then((user) => console.log(user));
241
+ */
242
+ //# sourceMappingURL=wallet-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-provider.d.ts","sourceRoot":"","sources":["../../../../src/client/generated/wallet-provider.ts"],"names":[],"mappings":"AAAA,OAAO,CAA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,KAAK,GAAG,CAAC;CACrD,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX,KAAK,gBAAgB,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAKtF,qBAAa,SAAS;IAGD,OAAO,EAAE,OAAO;IAFnC,OAAO,EAAE,MAAM,CAAM;gBAEF,OAAO,EAAE,OAAO;IAEnC,UAAU,CAAC,OAAO,EAAE,MAAM;IAM1B,GAAG,CAAC,IAAI,SAAS,MAAM,YAAY,EAAE,SAAS,SAAS,YAAY,CAAC,IAAI,CAAC,EACvE,IAAI,EAAE,IAAI,EACV,GAAG,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,GAC5D,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IAM1C,IAAI,CAAC,IAAI,SAAS,MAAM,aAAa,EAAE,SAAS,SAAS,aAAa,CAAC,IAAI,CAAC,EAC1E,IAAI,EAAE,IAAI,EACV,GAAG,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,GAC5D,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;CAI3C;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,aAEjE;;AAED;;;;;;;;EAQE"}
@@ -0,0 +1,7 @@
1
+ import { ApiClient as WalletProviderApiClient } from "./generated/wallet-provider";
2
+ export type WalletProviderClient = WalletProviderApiClient;
3
+ export declare const getWalletProviderClient: (context: {
4
+ walletProviderBaseUrl: string;
5
+ appFetch?: GlobalFetch["fetch"];
6
+ }) => WalletProviderApiClient;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,IAAI,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEnF,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AA4B3D,eAAO,MAAM,uBAAuB,YAAa;IAC/C,qBAAqB,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CACjC,4BAmBA,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { fixBase64EncodingOnKey } from "./utils/jwk";
1
2
  import "react-native-url-polyfill/auto";
2
3
  import * as Credential from "./credential";
3
4
  import * as PID from "./pid";
@@ -5,7 +6,10 @@ import * as SdJwt from "./sd-jwt";
5
6
  import * as Errors from "./utils/errors";
6
7
  import * as WalletInstanceAttestation from "./wallet-instance-attestation";
7
8
  import * as Trust from "./trust";
9
+ import * as WalletInstance from "./wallet-instance";
8
10
  import { AuthorizationDetail, AuthorizationDetails } from "./utils/par";
9
11
  import { createCryptoContextFor } from "./utils/crypto";
10
- export { SdJwt, PID, Credential, WalletInstanceAttestation, Errors, Trust, createCryptoContextFor, AuthorizationDetail, AuthorizationDetails, };
12
+ import type { IntegrityContext } from "./utils/integrity";
13
+ export { SdJwt, PID, Credential, WalletInstanceAttestation, WalletInstance, Errors, Trust, createCryptoContextFor, AuthorizationDetail, AuthorizationDetails, fixBase64EncodingOnKey, };
14
+ export type { IntegrityContext };
11
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,gCAAgC,CAAC;AAExC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,KAAK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CAAC"}
@@ -109,4 +109,17 @@ export declare class PidMetadataError extends Error {
109
109
  static get code(): "PID_METADATA_ERROR";
110
110
  constructor(message: string);
111
111
  }
112
+ /**
113
+ * An error subclass thrown when a Wallet Provider http request fail
114
+ *
115
+ */
116
+ export declare class WalletProviderResponseError extends IoWalletError {
117
+ static get code(): "ERR_IO_WALLET_PROVIDER_RESPONSE_FAILED";
118
+ code: string;
119
+ /** The Claim for which the validation failed. */
120
+ claim: string;
121
+ /** Reason code for the validation failure. */
122
+ reason: string;
123
+ constructor(message: string, claim?: string, reason?: string);
124
+ }
112
125
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/utils/errors.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;GAUG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,6DAA6D;IAC7D,MAAM,KAAK,IAAI,IAAI,MAAM,CAExB;IAED,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAA2B;gBAE3B,OAAO,CAAC,EAAE,MAAM;CAM7B;AACD;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,aAAa;IACjD,MAAM,KAAK,IAAI,IAAI,iCAAiC,CAEnD;IAED,IAAI,SAAqC;IAEzC,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;IAEd,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;gBAGb,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,MAAsB,EAC7B,MAAM,GAAE,MAAsB;CAMjC;AAED;;;GAGG;AACH,qBAAa,qCAAsC,SAAQ,aAAa;IACtE,MAAM,KAAK,IAAI,IAAI,mDAAmD,CAErE;IAED,IAAI,SAAuD;IAE3D,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;IAEd,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;gBAGb,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,MAAsB,EAC7B,MAAM,GAAE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C"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Interface for the integrity context which provides the necessary functions to interact with the integrity service.
3
+ * The functions are platform specific and must be implemented in the platform specific code.
4
+ * getHardwareKeyTag: returns the hardware key tag.
5
+ * getAttestation: requests the attestation from the integrity service.
6
+ * getHardwareSignatureWithAuthData: signs the clientData and returns the signature with the authenticator data.
7
+ */
8
+ export interface IntegrityContext {
9
+ getHardwareKeyTag: () => string;
10
+ getAttestation: (nonce: string) => Promise<string>;
11
+ getHardwareSignatureWithAuthData: (clientData: string) => Promise<HardwareSignatureWithAuthData>;
12
+ }
13
+ /**
14
+ * Type returned by the getHardwareSignatureWithAuthData function of {@link IntegrityContext}.
15
+ * It contains the signature and the authenticator data.
16
+ */
17
+ export type HardwareSignatureWithAuthData = {
18
+ signature: string;
19
+ authenticatorData: string;
20
+ };
21
+ //# sourceMappingURL=integrity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integrity.d.ts","sourceRoot":"","sources":["../../../src/utils/integrity.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,EAAE,MAAM,MAAM,CAAC;IAChC,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACnD,gCAAgC,EAAE,CAChC,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,6BAA6B,CAAC,CAAC;CAC7C;AAED;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { IntegrityContext } from "..";
2
+ export declare function createWalletInstance(context: {
3
+ integrityContext: IntegrityContext;
4
+ walletProviderBaseUrl: string;
5
+ appFetch?: GlobalFetch["fetch"];
6
+ }): Promise<string>;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/wallet-instance/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,IAAI,CAAC;AAE3C,wBAAsB,oBAAoB,CAAC,OAAO,EAAE;IAClD,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CACjC,mBAqBA"}
@@ -1,6 +1,16 @@
1
1
  /// <reference types="react-native" />
2
2
  import { type CryptoContext } from "@pagopa/io-react-native-jwt";
3
- import type { WalletProviderEntityConfiguration } from "../trust/types";
3
+ import type { IntegrityContext } from "..";
4
+ /**
5
+ * Getter for an attestation request. The attestation request is a JWT that will be sent to the Wallet Provider to request a Wallet Instance Attestation.
6
+ *
7
+ * @param challenge - The nonce received from the Wallet Provider which is part of the signed clientData
8
+ * @param wiaCryptoContext - The key pair associated with the WIA. Will be use to prove the ownership of the attestation
9
+ * @param integrityContext - The integrity context which exposes a set of functions to interact with the device integrity service
10
+ * @param walletProviderBaseUrl - Base url for the Wallet Provider
11
+ * @returns A JWT containing the attestation request
12
+ */
13
+ export declare function getAttestationRequest(challenge: string, wiaCryptoContext: CryptoContext, integrityContext: IntegrityContext, walletProviderBaseUrl: string): Promise<string>;
4
14
  /**
5
15
  * Request a Wallet Instance Attestation (WIA) to the Wallet provider
6
16
  *
@@ -9,11 +19,13 @@ import type { WalletProviderEntityConfiguration } from "../trust/types";
9
19
  * @param walletProviderBaseUrl Base url for the Wallet Provider
10
20
  * @returns The retrieved Wallet Instance Attestation token
11
21
  */
12
- export declare const getAttestation: ({ wiaCryptoContext, appFetch, }: {
22
+ export declare const getAttestation: ({ wiaCryptoContext, integrityContext, walletProviderBaseUrl, appFetch, }: {
13
23
  wiaCryptoContext: CryptoContext;
24
+ integrityContext: IntegrityContext;
25
+ walletProviderBaseUrl: string;
14
26
  appFetch?: {
15
27
  (input: RequestInfo, init?: RequestInit | undefined): Promise<Response>;
16
28
  (input: RequestInfo, init?: RequestInit | undefined): Promise<Response>;
17
29
  } | undefined;
18
- }) => (walletProviderEntityConfiguration: WalletProviderEntityConfiguration) => Promise<string>;
30
+ }) => Promise<string>;
19
31
  //# sourceMappingURL=issuing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"issuing.d.ts","sourceRoot":"","sources":["../../../src/wallet-instance-attestation/issuing.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,KAAK,aAAa,EAEnB,MAAM,6BAA6B,CAAC;AAOrC,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAgExE;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;sBAKL,aAAa;;;;;0CAII,iCAAiC,KACnE,QAAQ,MAAM,CA8ChB,CAAC"}
1
+ {"version":3,"file":"issuing.d.ts","sourceRoot":"","sources":["../../../src/wallet-instance-attestation/issuing.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAIjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,IAAI,CAAC;AAG3C;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CACzC,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,aAAa,EAC/B,gBAAgB,EAAE,gBAAgB,EAClC,qBAAqB,EAAE,MAAM,GAC5B,OAAO,CAAC,MAAM,CAAC,CAoCjB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;sBAMP,aAAa;sBACb,gBAAgB;2BACX,MAAM;;;;;MAE3B,QAAQ,MAAM,CA4BjB,CAAC"}
@@ -20,11 +20,11 @@ export declare const WalletInstanceAttestationRequestJwt: z.ZodObject<{
20
20
  x5c?: string[] | undefined;
21
21
  trust_chain?: string[] | undefined;
22
22
  }>, z.ZodObject<{
23
- typ: z.ZodLiteral<"wiar+jwt">;
23
+ typ: z.ZodLiteral<"war+jwt">;
24
24
  }, "strip", z.ZodTypeAny, {
25
- typ: "wiar+jwt";
25
+ typ: "war+jwt";
26
26
  }, {
27
- typ: "wiar+jwt";
27
+ typ: "war+jwt";
28
28
  }>>;
29
29
  payload: z.ZodIntersection<z.ZodObject<{
30
30
  iss: z.ZodString;
@@ -247,7 +247,7 @@ export declare const WalletInstanceAttestationRequestJwt: z.ZodObject<{
247
247
  x5c?: string[] | undefined;
248
248
  trust_chain?: string[] | undefined;
249
249
  } & {
250
- typ: "wiar+jwt";
250
+ typ: "war+jwt";
251
251
  };
252
252
  payload: {
253
253
  iss: string;
@@ -294,7 +294,7 @@ export declare const WalletInstanceAttestationRequestJwt: z.ZodObject<{
294
294
  x5c?: string[] | undefined;
295
295
  trust_chain?: string[] | undefined;
296
296
  } & {
297
- typ: "wiar+jwt";
297
+ typ: "war+jwt";
298
298
  };
299
299
  payload: {
300
300
  iss: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/io-react-native-wallet",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "description": "Provide data structures, helpers and API for IO Wallet",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -34,7 +34,9 @@
34
34
  "release": "release-it",
35
35
  "example": "yarn --cwd example",
36
36
  "bootstrap": "yarn example && yarn install",
37
- "code-review": "yarn lint && yarn typecheck && yarn test"
37
+ "code-review": "yarn generate && yarn lint && yarn typecheck && yarn test",
38
+ "generate-wallet-provider-client": "typed-openapi openapi/wallet-provider.yaml -o src/client/generated/wallet-provider.ts -r zod",
39
+ "generate": "yarn generate-wallet-provider-client"
38
40
  },
39
41
  "keywords": [
40
42
  "react-native",
@@ -53,8 +55,8 @@
53
55
  "devDependencies": {
54
56
  "@pagopa/eslint-config": "^3.0.0",
55
57
  "@pagopa/io-react-native-crypto": "^0.2.3",
56
- "@pagopa/io-react-native-jwt": "^1.0.0",
57
- "@react-native-community/eslint-config": "^3.2.0",
58
+ "@pagopa/io-react-native-jwt": "^1.2.0",
59
+ "@react-native/eslint-config": "^0.72.2",
58
60
  "@rushstack/eslint-patch": "^1.3.2",
59
61
  "@types/jest": "^28.1.2",
60
62
  "@types/react": "~17.0.21",
@@ -66,8 +68,9 @@
66
68
  "pod-install": "^0.1.0",
67
69
  "prettier": "^2.0.5",
68
70
  "react": "18.2.0",
69
- "react-native": "0.71.8",
71
+ "react-native": "0.72.14",
70
72
  "react-native-builder-bob": "^0.20.0",
73
+ "typed-openapi": "^0.4.1",
71
74
  "typescript": "^5.0.2"
72
75
  },
73
76
  "resolutions": {
@@ -0,0 +1,170 @@
1
+ import z from "zod";
2
+
3
+ export type ProblemDetail = z.infer<typeof ProblemDetail>;
4
+ export const ProblemDetail = z.object({
5
+ type: z.string().optional(),
6
+ title: z.string().optional(),
7
+ status: z.number().optional(),
8
+ detail: z.string().optional(),
9
+ instance: z.string().optional(),
10
+ });
11
+
12
+ export type FiscalCode = z.infer<typeof FiscalCode>;
13
+ export const FiscalCode = z.string();
14
+
15
+ export type Id = z.infer<typeof Id>;
16
+ export const Id = z.string();
17
+
18
+ export type get_GetEntityConfiguration = typeof get_GetEntityConfiguration;
19
+ export const get_GetEntityConfiguration = {
20
+ method: z.literal("GET"),
21
+ path: z.literal("/.well-known/openid-federation"),
22
+ parameters: z.never(),
23
+ response: z.unknown(),
24
+ };
25
+
26
+ export type get_GetNonce = typeof get_GetNonce;
27
+ export const get_GetNonce = {
28
+ method: z.literal("GET"),
29
+ path: z.literal("/nonce"),
30
+ parameters: z.never(),
31
+ response: z.object({
32
+ nonce: z.string(),
33
+ }),
34
+ };
35
+
36
+ export type post_CreateWalletInstance = typeof post_CreateWalletInstance;
37
+ export const post_CreateWalletInstance = {
38
+ method: z.literal("POST"),
39
+ path: z.literal("/wallet-instances"),
40
+ parameters: z.object({
41
+ body: z.object({
42
+ challenge: z.string(),
43
+ key_attestation: z.string(),
44
+ hardware_key_tag: z.string(),
45
+ }),
46
+ }),
47
+ response: z.unknown(),
48
+ };
49
+
50
+ export type post_CreateWalletAttestation = typeof post_CreateWalletAttestation;
51
+ export const post_CreateWalletAttestation = {
52
+ method: z.literal("POST"),
53
+ path: z.literal("/token"),
54
+ parameters: z.object({
55
+ body: z.object({
56
+ grant_type: z.literal("urn:ietf:params:oauth:grant-type:jwt-bearer"),
57
+ assertion: z.string(),
58
+ }),
59
+ }),
60
+ response: z.unknown(),
61
+ };
62
+
63
+ // <EndpointByMethod>
64
+ export const EndpointByMethod = {
65
+ get: {
66
+ "/.well-known/openid-federation": get_GetEntityConfiguration,
67
+ "/nonce": get_GetNonce,
68
+ },
69
+ post: {
70
+ "/wallet-instances": post_CreateWalletInstance,
71
+ "/token": post_CreateWalletAttestation,
72
+ },
73
+ };
74
+ export type EndpointByMethod = typeof EndpointByMethod;
75
+ // </EndpointByMethod>
76
+
77
+ // <EndpointByMethod.Shorthands>
78
+ export type GetEndpoints = EndpointByMethod["get"];
79
+ export type PostEndpoints = EndpointByMethod["post"];
80
+ export type AllEndpoints = EndpointByMethod[keyof EndpointByMethod];
81
+ // </EndpointByMethod.Shorthands>
82
+
83
+ // <ApiClientTypes>
84
+ export type EndpointParameters = {
85
+ body?: unknown;
86
+ query?: Record<string, unknown>;
87
+ header?: Record<string, unknown>;
88
+ path?: Record<string, unknown>;
89
+ };
90
+
91
+ export type MutationMethod = "post" | "put" | "patch" | "delete";
92
+ export type Method = "get" | "head" | MutationMethod;
93
+
94
+ export type DefaultEndpoint = {
95
+ parameters?: EndpointParameters | undefined;
96
+ response: unknown;
97
+ };
98
+
99
+ export type Endpoint<TConfig extends DefaultEndpoint = DefaultEndpoint> = {
100
+ operationId: string;
101
+ method: Method;
102
+ path: string;
103
+ parameters?: TConfig["parameters"];
104
+ meta: {
105
+ alias: string;
106
+ hasParameters: boolean;
107
+ areParametersRequired: boolean;
108
+ };
109
+ response: TConfig["response"];
110
+ };
111
+
112
+ type Fetcher = (
113
+ method: Method,
114
+ url: string,
115
+ parameters?: EndpointParameters | undefined,
116
+ ) => Promise<Endpoint["response"]>;
117
+
118
+ type RequiredKeys<T> = {
119
+ [P in keyof T]-?: undefined extends T[P] ? never : P;
120
+ }[keyof T];
121
+
122
+ type MaybeOptionalArg<T> = RequiredKeys<T> extends never ? [config?: T] : [config: T];
123
+
124
+ // </ApiClientTypes>
125
+
126
+ // <ApiClient>
127
+ export class ApiClient {
128
+ baseUrl: string = "";
129
+
130
+ constructor(public fetcher: Fetcher) {}
131
+
132
+ setBaseUrl(baseUrl: string) {
133
+ this.baseUrl = baseUrl;
134
+ return this;
135
+ }
136
+
137
+ // <ApiClient.get>
138
+ get<Path extends keyof GetEndpoints, TEndpoint extends GetEndpoints[Path]>(
139
+ path: Path,
140
+ ...params: MaybeOptionalArg<z.infer<TEndpoint["parameters"]>>
141
+ ): Promise<z.infer<TEndpoint["response"]>> {
142
+ return this.fetcher("get", this.baseUrl + path, params[0]) as Promise<z.infer<TEndpoint["response"]>>;
143
+ }
144
+ // </ApiClient.get>
145
+
146
+ // <ApiClient.post>
147
+ post<Path extends keyof PostEndpoints, TEndpoint extends PostEndpoints[Path]>(
148
+ path: Path,
149
+ ...params: MaybeOptionalArg<z.infer<TEndpoint["parameters"]>>
150
+ ): Promise<z.infer<TEndpoint["response"]>> {
151
+ return this.fetcher("post", this.baseUrl + path, params[0]) as Promise<z.infer<TEndpoint["response"]>>;
152
+ }
153
+ // </ApiClient.post>
154
+ }
155
+
156
+ export function createApiClient(fetcher: Fetcher, baseUrl?: string) {
157
+ return new ApiClient(fetcher).setBaseUrl(baseUrl ?? "");
158
+ }
159
+
160
+ /**
161
+ Example usage:
162
+ const api = createApiClient((method, url, params) =>
163
+ fetch(url, { method, body: JSON.stringify(params) }).then((res) => res.json()),
164
+ );
165
+ api.get("/users").then((users) => console.log(users));
166
+ api.post("/users", { body: { name: "John" } }).then((user) => console.log(user));
167
+ api.put("/users/:id", { path: { id: 1 }, body: { name: "John" } }).then((user) => console.log(user));
168
+ */
169
+
170
+ // </ApiClient