@monerium/sdk 1.0.20 → 2.0.0-alpha
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 +21 -0
- package/README.md +14 -79
- package/esm/_dnt.shims.js +76 -0
- package/esm/deps/deno.land/std@0.159.0/encoding/base64.js +123 -0
- package/esm/deps/deno.land/std@0.159.0/encoding/base64url.js +49 -0
- package/esm/mod.js +1 -0
- package/esm/package.json +3 -0
- package/esm/src/client.js +139 -0
- package/esm/src/config.js +13 -0
- package/esm/src/types.js +73 -0
- package/package.json +39 -46
- package/script/_dnt.shims.js +88 -0
- package/script/deps/deno.land/std@0.159.0/encoding/base64.js +151 -0
- package/script/deps/deno.land/std@0.159.0/encoding/base64url.js +77 -0
- package/script/mod.js +5 -0
- package/script/package.json +3 -0
- package/script/src/client.js +166 -0
- package/script/src/config.js +16 -0
- package/script/src/types.js +76 -0
- package/types/_dnt.shims.d.ts +18 -0
- package/types/deps/deno.land/std@0.159.0/encoding/base64.d.ts +11 -0
- package/types/deps/deno.land/std@0.159.0/encoding/base64url.d.ts +10 -0
- package/types/mod.d.ts +1 -0
- package/types/src/client.d.ts +19 -0
- package/types/src/config.d.ts +3 -0
- package/types/src/types.d.ts +266 -0
- package/.eslintignore +0 -13
- package/.eslintrc.cjs +0 -20
- package/.github/workflows/release-please.yml +0 -34
- package/.prettierignore +0 -13
- package/.prettierrc +0 -6
- package/CHANGELOG.md +0 -151
- package/src/app.d.ts +0 -11
- package/src/app.html +0 -12
- package/src/lib/client.ts +0 -341
- package/src/lib/config.ts +0 -59
- package/src/lib/index.ts +0 -1
- package/src/routes/index.svelte +0 -32
- package/src/routes/integration.svelte +0 -45
- package/static/favicon.png +0 -0
- package/svelte.config.js +0 -19
- package/test/index.test.ts +0 -20
- package/tsconfig.json +0 -19
- package/vite.config.js +0 -14
- package/vitest.config.ts +0 -7
package/src/lib/client.ts
DELETED
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
import { MONERIUM_CONFIG } from './config';
|
|
2
|
-
import type { ethers } from 'ethers';
|
|
3
|
-
import { providers } from '@0xsequence/multicall';
|
|
4
|
-
import getPkce from 'oauth-pkce';
|
|
5
|
-
import pjson from './../../package.json';
|
|
6
|
-
|
|
7
|
-
type SupportedProvider = ethers.providers.Web3Provider | ethers.providers.JsonRpcProvider;
|
|
8
|
-
|
|
9
|
-
type CurrencyCode = 'eur' | 'gbp' | 'usd' | 'isk';
|
|
10
|
-
|
|
11
|
-
type Network = 'mainnet' | 'ropsten' | 'rinkeby' | 'kovan' | 'goerli' | 'mumbai';
|
|
12
|
-
|
|
13
|
-
type Chain = 'ethereum' | 'polygon';
|
|
14
|
-
interface BasicRedeem {
|
|
15
|
-
email: string;
|
|
16
|
-
password: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface PKCERequest {
|
|
20
|
-
client_id: string;
|
|
21
|
-
code_challenge?: string;
|
|
22
|
-
code_challenge_method?: string;
|
|
23
|
-
response_type?: string;
|
|
24
|
-
redirect_uri?: string;
|
|
25
|
-
state?: string;
|
|
26
|
-
address?: string;
|
|
27
|
-
scope?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface PKCERedeem {
|
|
31
|
-
client_id: string;
|
|
32
|
-
code: string;
|
|
33
|
-
code_verifier: string;
|
|
34
|
-
grant_type?: string;
|
|
35
|
-
redirect_uri?: string;
|
|
36
|
-
scope?: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface ClientRedeem {
|
|
40
|
-
client_id: string;
|
|
41
|
-
client_secret: string;
|
|
42
|
-
scope?: string;
|
|
43
|
-
grant_type?: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface BearerProfile {
|
|
47
|
-
access_token: string;
|
|
48
|
-
token_type: string;
|
|
49
|
-
expires_in: number;
|
|
50
|
-
refresh_token: string;
|
|
51
|
-
profile: string;
|
|
52
|
-
userId: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
interface AuthContext {
|
|
56
|
-
userId: string;
|
|
57
|
-
email: string;
|
|
58
|
-
name: string;
|
|
59
|
-
roles: [string];
|
|
60
|
-
auth: { method: string; subject: string; verified: boolean };
|
|
61
|
-
defaultProfile: string;
|
|
62
|
-
profiles: [{ id: string; type: string; name: string; perms: [string] }];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
interface CurrencyAccounts {
|
|
66
|
-
network: Network;
|
|
67
|
-
chain: Chain;
|
|
68
|
-
currency: CurrencyCode;
|
|
69
|
-
}
|
|
70
|
-
interface ConnectWalletPayload {
|
|
71
|
-
address: string;
|
|
72
|
-
message: string;
|
|
73
|
-
signature: string;
|
|
74
|
-
accounts: CurrencyAccounts[];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
interface PlaceOrderPayloadByAccount {
|
|
78
|
-
accountId: string;
|
|
79
|
-
}
|
|
80
|
-
interface PlaceOrderPayloadByAddress {
|
|
81
|
-
address: string;
|
|
82
|
-
currency: CurrencyCode;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
interface CounterpartDetailsIndividual {
|
|
86
|
-
firstName: string;
|
|
87
|
-
lastName: string;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
interface CounterpartDetailsCorporation {
|
|
91
|
-
companyName: string;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
interface CounterpartIdentifierBase {
|
|
95
|
-
standard: 'iban' | 'scan';
|
|
96
|
-
}
|
|
97
|
-
interface CounterpartIdentifierIban extends CounterpartIdentifierBase {
|
|
98
|
-
standard: 'iban';
|
|
99
|
-
iban: string;
|
|
100
|
-
}
|
|
101
|
-
interface CounterpartIdentifierScan extends CounterpartIdentifierBase {
|
|
102
|
-
standard: 'scan';
|
|
103
|
-
sortCode: string;
|
|
104
|
-
accountNumber: string;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
type CounterpartIdentifier = CounterpartIdentifierIban | CounterpartIdentifierScan;
|
|
108
|
-
|
|
109
|
-
type CounterpartDetails = CounterpartDetailsIndividual | CounterpartDetailsCorporation;
|
|
110
|
-
interface Counterpart {
|
|
111
|
-
identifier: CounterpartIdentifier;
|
|
112
|
-
details: CounterpartDetails;
|
|
113
|
-
}
|
|
114
|
-
interface PlaceOrderPayloadBase {
|
|
115
|
-
kind: 'redeem' | 'issue';
|
|
116
|
-
amount: string;
|
|
117
|
-
signature: string;
|
|
118
|
-
counterpart: Counterpart;
|
|
119
|
-
message: string;
|
|
120
|
-
memo?: string;
|
|
121
|
-
supportingDocumentId?: string;
|
|
122
|
-
chain?: string;
|
|
123
|
-
network?: string;
|
|
124
|
-
|
|
125
|
-
// TODO: https://monerium.dev/api-docs#operation/post-profile-orders
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
type PlaceOrderPayload = PlaceOrderPayloadBase &
|
|
129
|
-
(PlaceOrderPayloadByAccount | PlaceOrderPayloadByAddress);
|
|
130
|
-
|
|
131
|
-
interface SupportingDocumentPayload {
|
|
132
|
-
file: File;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export class MoneriumClient {
|
|
136
|
-
#env!: { base: string; web: string };
|
|
137
|
-
#provider?: ethers.providers.Provider;
|
|
138
|
-
#signer?: ethers.Signer;
|
|
139
|
-
#authPayload?: string;
|
|
140
|
-
codeVerifier?: string;
|
|
141
|
-
|
|
142
|
-
bearerProfile?: BearerProfile;
|
|
143
|
-
authContext?: AuthContext;
|
|
144
|
-
|
|
145
|
-
// --- Constructor --- //
|
|
146
|
-
|
|
147
|
-
static async create(env: 'production' | 'sandbox' = 'sandbox', provider?: SupportedProvider) {
|
|
148
|
-
const client = new MoneriumClient();
|
|
149
|
-
|
|
150
|
-
await client.#initialize(env, provider);
|
|
151
|
-
|
|
152
|
-
return client;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
async #initialize(env: 'production' | 'sandbox', provider?: SupportedProvider) {
|
|
156
|
-
this.#env = MONERIUM_CONFIG.environments[env];
|
|
157
|
-
|
|
158
|
-
if (provider) {
|
|
159
|
-
this.#provider = new providers.MulticallProvider(provider);
|
|
160
|
-
this.#signer = provider.getSigner();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// --- Private Helper Methods --- //
|
|
165
|
-
|
|
166
|
-
async #api(
|
|
167
|
-
method: string,
|
|
168
|
-
resource: string,
|
|
169
|
-
data?:
|
|
170
|
-
| PKCERequest
|
|
171
|
-
| PKCERedeem
|
|
172
|
-
| ClientRedeem
|
|
173
|
-
| ConnectWalletPayload
|
|
174
|
-
| PlaceOrderPayload
|
|
175
|
-
| SupportingDocumentPayload,
|
|
176
|
-
isFormEncoded?: boolean
|
|
177
|
-
) {
|
|
178
|
-
const res = await fetch(`${this.#env.base}/${resource}`, {
|
|
179
|
-
method,
|
|
180
|
-
headers: {
|
|
181
|
-
// To understand SDK adoption and correlate issues to specific versions.
|
|
182
|
-
'User-Agent': 'monerium-sdk/' + pjson.version,
|
|
183
|
-
'content-type': isFormEncoded ? 'application/x-www-form-urlencoded' : 'application/json',
|
|
184
|
-
Authorization: this.#authPayload || ''
|
|
185
|
-
},
|
|
186
|
-
body:
|
|
187
|
-
data && isFormEncoded
|
|
188
|
-
? new URLSearchParams(data as unknown as Record<string, string>)
|
|
189
|
-
: JSON.stringify(data)
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
if (res.status >= 200 && res.status <= 299) {
|
|
193
|
-
return await res.json();
|
|
194
|
-
} else {
|
|
195
|
-
return new Error(res.statusText);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
#isPKCERequest(
|
|
200
|
-
args: PKCERequest | BearerProfile | BasicRedeem | PKCERedeem | ClientRedeem
|
|
201
|
-
): args is PKCERequest {
|
|
202
|
-
return (args as PKCERequest).client_id != undefined && (args as PKCERedeem)?.code === undefined;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
#isBearerProfileAuth(
|
|
206
|
-
args: BearerProfile | BasicRedeem | PKCERedeem | ClientRedeem
|
|
207
|
-
): args is BearerProfile {
|
|
208
|
-
return (args as BearerProfile).access_token != undefined;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
#isBasicAuth(args: BasicRedeem | PKCERedeem | ClientRedeem): args is BasicRedeem {
|
|
212
|
-
return (args as BasicRedeem).password != undefined;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
#isPKCEAuth(args: PKCERedeem | ClientRedeem): args is PKCERedeem {
|
|
216
|
-
return (args as PKCERedeem).code != undefined;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
#isClientAuth(args: ClientRedeem): args is ClientRedeem {
|
|
220
|
-
return (args as ClientRedeem).client_secret != undefined;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// --- Public Methods --- //
|
|
224
|
-
|
|
225
|
-
async auth(args: PKCERequest | BearerProfile | BasicRedeem | PKCERedeem | ClientRedeem) {
|
|
226
|
-
if (this.#isPKCERequest(args)) {
|
|
227
|
-
const { verifier, challenge } = await new Promise<{ verifier: string; challenge: string }>(
|
|
228
|
-
(resolve) => {
|
|
229
|
-
getPkce(43, (error, { verifier, challenge }) => {
|
|
230
|
-
if (error) throw error;
|
|
231
|
-
resolve({ verifier, challenge });
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
const requestData = {
|
|
237
|
-
client_id: args?.client_id,
|
|
238
|
-
code_challenge: challenge,
|
|
239
|
-
code_challenge_method: 'S256',
|
|
240
|
-
response_type: 'code',
|
|
241
|
-
redirect_uri: args.redirect_uri || '',
|
|
242
|
-
scope: args.scope || 'orders:read',
|
|
243
|
-
state: args.state || '',
|
|
244
|
-
address: args.address || ''
|
|
245
|
-
};
|
|
246
|
-
this.codeVerifier = verifier;
|
|
247
|
-
this.#authPayload = ' ';
|
|
248
|
-
|
|
249
|
-
if (typeof window !== 'undefined') {
|
|
250
|
-
return window.location.replace(
|
|
251
|
-
`${this.#env.base}/auth?${new URLSearchParams(requestData).toString()}`
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
return new Error('Something went wrong. Please contact the Monerium Support team.');
|
|
255
|
-
} else {
|
|
256
|
-
if (this.#isBearerProfileAuth(args)) {
|
|
257
|
-
this.bearerProfile = args;
|
|
258
|
-
this.#authPayload = this.bearerProfile && `Bearer ${this.bearerProfile.access_token}`;
|
|
259
|
-
} else if (this.#isBasicAuth(args)) {
|
|
260
|
-
const bufferObj = Buffer.from(`${args.email}:${args.password}`, 'utf8');
|
|
261
|
-
this.#authPayload = `Basic ${bufferObj.toString('base64')}`;
|
|
262
|
-
} else if (this.#isPKCEAuth(args)) {
|
|
263
|
-
const redeemData: PKCERedeem = {
|
|
264
|
-
client_id: args.client_id,
|
|
265
|
-
code: args.code,
|
|
266
|
-
redirect_uri: args.redirect_uri,
|
|
267
|
-
grant_type: 'authorization_code',
|
|
268
|
-
code_verifier: args.code_verifier,
|
|
269
|
-
scope: args.scope || 'orders:read'
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
this.bearerProfile = await this.#api('post', 'auth/token', redeemData, true);
|
|
273
|
-
this.#authPayload = this.bearerProfile && `Bearer ${this.bearerProfile.access_token}`;
|
|
274
|
-
} else if (this.#isClientAuth(args)) {
|
|
275
|
-
const redeemData: ClientRedeem = {
|
|
276
|
-
client_id: args.client_id,
|
|
277
|
-
client_secret: args.client_secret,
|
|
278
|
-
grant_type: 'client_credentials',
|
|
279
|
-
scope: args.scope || 'orders:read'
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
this.bearerProfile = await this.#api('post', 'auth/token', redeemData, true);
|
|
283
|
-
this.#authPayload = this.bearerProfile && `Bearer ${this.bearerProfile.access_token}`;
|
|
284
|
-
} else {
|
|
285
|
-
return new Error('Something went wrong. Please contact the Monerium Support team.');
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
this.authContext = await this.getAuthContext();
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
async getAuthContext() {
|
|
293
|
-
return await this.#api('get', 'auth/context');
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
async getProfile(profileId: string) {
|
|
297
|
-
return await this.#api('get', `profiles/${profileId}`);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
async getOrders(profileId?: string) {
|
|
301
|
-
if (profileId) {
|
|
302
|
-
return await this.#api('get', `profiles/${profileId}/orders`);
|
|
303
|
-
} else {
|
|
304
|
-
return await this.#api('get', `orders`);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
async getOrder(orderId: string) {
|
|
309
|
-
return await this.#api('get', `orders/${orderId}`);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
async getBalances(profileId?: string) {
|
|
313
|
-
if (profileId) {
|
|
314
|
-
return await this.#api('get', `profiles/${profileId}/balances`);
|
|
315
|
-
} else {
|
|
316
|
-
return await this.#api('get', 'balances');
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
async getTokens() {
|
|
320
|
-
return await this.#api('get', 'tokens');
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
async connectWallet(profileId: string, body: ConnectWalletPayload) {
|
|
324
|
-
return await this.#api('post', `profiles/${profileId}/address`, body);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
async placeOrder(body?: PlaceOrderPayload, profileId?: string) {
|
|
328
|
-
if (profileId) {
|
|
329
|
-
return await this.#api('post', `profiles/${profileId}/orders`, body);
|
|
330
|
-
} else {
|
|
331
|
-
return await this.#api('post', `orders`, body);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
async uploadSupportingDocument(body: SupportingDocumentPayload) {
|
|
336
|
-
return await this.#api('post', `files/supporting-document`, body, true);
|
|
337
|
-
}
|
|
338
|
-
// orderNotifications websockets?
|
|
339
|
-
// https://monerium.dev/api-docs#operation/profile-orders-notifications
|
|
340
|
-
// https://monerium.dev/api-docs#operation/orders-notifications
|
|
341
|
-
}
|
package/src/lib/config.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
type Tokens = {
|
|
2
|
-
EUR: string;
|
|
3
|
-
GBP: string;
|
|
4
|
-
USD: string;
|
|
5
|
-
ISK: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
type TokenConfig = {
|
|
9
|
-
contract: string;
|
|
10
|
-
ens?: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
type MoneriumConfig = {
|
|
14
|
-
deployments: { [chainId: number]: { [Property in keyof Tokens]: TokenConfig } };
|
|
15
|
-
environments: {
|
|
16
|
-
[env: string]: { base: string; web: string };
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const MONERIUM_CONFIG: MoneriumConfig = {
|
|
21
|
-
deployments: {
|
|
22
|
-
1: {
|
|
23
|
-
EUR: {
|
|
24
|
-
contract: '0x3231cb76718cdef2155fc47b5286d82e6eda273f',
|
|
25
|
-
ens: 'eur.monerium.eth'
|
|
26
|
-
},
|
|
27
|
-
GBP: {
|
|
28
|
-
contract: '0x7ba92741bf2a568abc6f1d3413c58c6e0244f8fd',
|
|
29
|
-
ens: 'gbp.monerium.eth'
|
|
30
|
-
},
|
|
31
|
-
USD: {
|
|
32
|
-
contract: '0xbc5142e0cc5eb16b47c63b0f033d4c2480853a52',
|
|
33
|
-
ens: 'usd.monerium.eth'
|
|
34
|
-
},
|
|
35
|
-
ISK: {
|
|
36
|
-
contract: '0xc642549743a93674cf38d6431f75d6443f88e3e2',
|
|
37
|
-
ens: 'isk.monerium.eth'
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
4: {
|
|
41
|
-
EUR: {
|
|
42
|
-
contract: '0x25c13fc529dc4afe4d488bd1f2ee5e1ec4918e0b'
|
|
43
|
-
},
|
|
44
|
-
GBP: {
|
|
45
|
-
contract: '0x01df10e345d0364d3a5b8422a66af6305803bd1e'
|
|
46
|
-
},
|
|
47
|
-
USD: {
|
|
48
|
-
contract: '0x09c0a236e1227500f495cb0731c4af69b49639a5'
|
|
49
|
-
},
|
|
50
|
-
ISK: {
|
|
51
|
-
contract: '0x0c9d7a0d8bf4bc9d15f577bbf650ebc8044a71db'
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
environments: {
|
|
56
|
-
production: { base: 'https://api.monerium.app', web: 'https://monerium.app' },
|
|
57
|
-
sandbox: { base: 'https://api.monerium.dev', web: 'https://sandbox.monerium.dev' }
|
|
58
|
-
}
|
|
59
|
-
};
|
package/src/lib/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { MoneriumClient } from './client';
|
package/src/routes/index.svelte
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { onMount } from 'svelte';
|
|
3
|
-
import { MoneriumClient } from 'monerium-js';
|
|
4
|
-
|
|
5
|
-
let client: MoneriumClient;
|
|
6
|
-
|
|
7
|
-
onMount(async () => {
|
|
8
|
-
client = await MoneriumClient.create();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
// client Credential:
|
|
12
|
-
// id: 654c9c30-44d3-11ed-adac-b2efc0e6677d
|
|
13
|
-
// secret: ac474b7cdc111973aa080b0428ba3a824e82119bee8f65875b4aba0d42416dff
|
|
14
|
-
|
|
15
|
-
async function authenticate() {
|
|
16
|
-
await client.auth({
|
|
17
|
-
client_id: '654c9c30-44d3-11ed-adac-b2efc0e6677d',
|
|
18
|
-
// partner_name: 'piedpiper',
|
|
19
|
-
redirect_uri: 'http://localhost:5173/integration'
|
|
20
|
-
}).then(() => {
|
|
21
|
-
if (typeof window !== "undefined" && client?.codeVerifier) {
|
|
22
|
-
sessionStorage.setItem("code_verifier", client.codeVerifier)
|
|
23
|
-
console.log('%cadding codeVerifier to session storage', 'color:white; padding: 30px; background-color: darkgreen', client.codeVerifier)
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
</script>
|
|
30
|
-
|
|
31
|
-
<h1>This is a demo of the Monerium JavaScript SDK.</h1>
|
|
32
|
-
<button on:click={authenticate}>Login</button>
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { afterUpdate, onMount } from 'svelte';
|
|
3
|
-
import { MoneriumClient } from 'monerium-js';
|
|
4
|
-
|
|
5
|
-
let client: MoneriumClient;
|
|
6
|
-
let codeVerifier: string;
|
|
7
|
-
let authContext = undefined;
|
|
8
|
-
const urlParams = typeof window !== "undefined" ? new URLSearchParams(window.location.search) : undefined;
|
|
9
|
-
|
|
10
|
-
console.log('%curlParams', 'color:white; padding: 30px; background-color: darkgreen', urlParams?.get('code'))
|
|
11
|
-
|
|
12
|
-
onMount(async () => {
|
|
13
|
-
client = await MoneriumClient.create();
|
|
14
|
-
codeVerifier = sessionStorage?.getItem("code_verifier") || '' ;
|
|
15
|
-
console.log('%ccodeVerifier from session storage', 'color:white; padding: 30px; background-color: darkgreen', codeVerifier)
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
afterUpdate(() => authContext = client?.authContext)
|
|
19
|
-
|
|
20
|
-
// client Credential:
|
|
21
|
-
// id: 654c9c30-44d3-11ed-adac-b2efc0e6677d
|
|
22
|
-
// secret: ac474b7cdc111973aa080b0428ba3a824e82119bee8f65875b4aba0d42416dff
|
|
23
|
-
async function authenticate() {
|
|
24
|
-
client.auth({
|
|
25
|
-
code: urlParams?.get('code') || '',
|
|
26
|
-
grant_type: 'authorization_code',
|
|
27
|
-
code_verifier: codeVerifier,
|
|
28
|
-
client_id: '654c9c30-44d3-11ed-adac-b2efc0e6677d',
|
|
29
|
-
// partner_name: 'piedpiper',
|
|
30
|
-
redirect_uri: 'http://localhost:5173/integration'
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function getBalances() {
|
|
35
|
-
client.getBalances();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
</script>
|
|
39
|
-
|
|
40
|
-
<h1>Partner redirect demo page</h1>
|
|
41
|
-
<p>{authContext}</p>
|
|
42
|
-
<button on:click={authenticate}>authenticate</button>
|
|
43
|
-
<button on:click={getBalances}>get balances</button>
|
|
44
|
-
|
|
45
|
-
|
package/static/favicon.png
DELETED
|
Binary file
|
package/svelte.config.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import adapter from '@sveltejs/adapter-auto';
|
|
2
|
-
import preprocess from 'svelte-preprocess';
|
|
3
|
-
|
|
4
|
-
/** @type {import('@sveltejs/kit').Config} */
|
|
5
|
-
const config = {
|
|
6
|
-
// Consult https://github.com/sveltejs/svelte-preprocess
|
|
7
|
-
// for more information about preprocessors
|
|
8
|
-
preprocess: preprocess(),
|
|
9
|
-
|
|
10
|
-
kit: {
|
|
11
|
-
adapter: adapter(),
|
|
12
|
-
package: {
|
|
13
|
-
files: (file) => !file.startsWith('demo'),
|
|
14
|
-
exports: (file) => file === 'index.js'
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export default config;
|
package/test/index.test.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { MoneriumClient } from '../src/lib/index';
|
|
3
|
-
|
|
4
|
-
const bearerClientArgs = {
|
|
5
|
-
client_id: '1234567890abcdef',
|
|
6
|
-
client_secret: '1234567890abcdef1234567890abcdef'
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
describe('Monerium Client Tests', () => {
|
|
10
|
-
it('should authenticate with client secret', async () => {
|
|
11
|
-
const client = await MoneriumClient.create();
|
|
12
|
-
|
|
13
|
-
await client.auth(bearerClientArgs);
|
|
14
|
-
|
|
15
|
-
expect(client.authContext).toHaveProperty('email', 'simon.ibars@request.network');
|
|
16
|
-
}, 100000);
|
|
17
|
-
|
|
18
|
-
it.todo('should authenticate with PKCE flow');
|
|
19
|
-
it.todo('should authenticate with user credentials');
|
|
20
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./.svelte-kit/tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"allowJs": true,
|
|
5
|
-
"checkJs": true,
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"forceConsistentCasingInFileNames": true,
|
|
8
|
-
"resolveJsonModule": true,
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"sourceMap": true,
|
|
11
|
-
"strict": true,
|
|
12
|
-
"paths": {
|
|
13
|
-
"$lib": ["src/lib"],
|
|
14
|
-
"$lib/*": ["src/lib/*"],
|
|
15
|
-
"monerium-js": ["src/lib/index.ts"],
|
|
16
|
-
"monerium-js/*": ["src/lib/*"]
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
package/vite.config.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { sveltekit } from '@sveltejs/kit/vite';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
/** @type {import('vite').UserConfig} */
|
|
5
|
-
const config = {
|
|
6
|
-
plugins: [sveltekit()],
|
|
7
|
-
resolve: {
|
|
8
|
-
alias: {
|
|
9
|
-
'monerium-js': path.resolve('src/lib')
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default config;
|