@coinflowlabs/angular 0.3.1 → 0.3.2

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.
@@ -1,10 +1,8 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { EventEmitter, Component, Input, Output, ViewChild, HostListener, Injectable, inject } from '@angular/core';
3
3
  import * as SolanaWeb3Js from '@solana/web3.js';
4
- import { Keypair, Transaction } from '@solana/web3.js';
5
4
  import base58Imported from 'bs58';
6
5
  import LZString from 'lz-string';
7
- import { sign } from 'tweetnacl';
8
6
  import * as i1 from '@angular/platform-browser';
9
7
 
10
8
  var SettlementType;
@@ -66,17 +64,6 @@ class CoinflowUtils {
66
64
  return undefined;
67
65
  });
68
66
  }
69
- async getCreditBalance(publicKey, merchantId, blockchain) {
70
- const response = await fetch(this.url + `/api/customer/balances/${merchantId}`, {
71
- method: 'GET',
72
- headers: {
73
- 'x-coinflow-auth-wallet': publicKey,
74
- 'x-coinflow-auth-blockchain': blockchain,
75
- },
76
- });
77
- const { credits } = await response.json();
78
- return credits;
79
- }
80
67
  static getCoinflowBaseUrl(env) {
81
68
  if (!env || env === 'prod')
82
69
  return 'https://coinflow.cash';
@@ -91,7 +78,7 @@ class CoinflowUtils {
91
78
  return 'http://localhost:5000';
92
79
  return `https://api-${env}.coinflow.cash`;
93
80
  }
94
- static getCoinflowUrl({ walletPubkey, sessionKey, route, routePrefix, env, amount, transaction, blockchain = 'solana', webhookInfo, email, loaderBackground, handleHeightChange, bankAccountLinkRedirect, additionalWallets, nearDeposit, chargebackProtectionData, merchantCss, color, rent, lockDefaultToken, token, tokens, planCode, disableApplePay, disableGooglePay, customerInfo, settlementType, lockAmount, nativeSolToConvert, theme, usePermit, transactionSigner, authOnly, deviceId, jwtToken, origins, threeDsChallengePreference, supportEmail, }) {
81
+ static getCoinflowUrl({ walletPubkey, sessionKey, route, routePrefix, env, amount, transaction, blockchain = 'solana', webhookInfo, email, loaderBackground, handleHeightChange, bankAccountLinkRedirect, additionalWallets, nearDeposit, chargebackProtectionData, merchantCss, color, rent, lockDefaultToken, token, tokens, planCode, disableApplePay, disableGooglePay, customerInfo, settlementType, lockAmount, nativeSolToConvert, theme, usePermit, transactionSigner, authOnly, deviceId, jwtToken, origins, threeDsChallengePreference, supportEmail, destinationAuthKey, }) {
95
82
  const prefix = routePrefix
96
83
  ? `/${routePrefix}/${blockchain}`
97
84
  : `/${blockchain}`;
@@ -185,6 +172,8 @@ class CoinflowUtils {
185
172
  url.searchParams.append('origins', LZString.compressToEncodedURIComponent(JSON.stringify(origins)));
186
173
  if (threeDsChallengePreference)
187
174
  url.searchParams.append('threeDsChallengePreference', threeDsChallengePreference);
175
+ if (destinationAuthKey)
176
+ url.searchParams.append('destinationAuthKey', destinationAuthKey);
188
177
  return url.toString();
189
178
  }
190
179
  static getTransaction(props) {
@@ -261,57 +250,6 @@ class CoinflowUtils {
261
250
  throw new Error('blockchain not supported!');
262
251
  }
263
252
  }
264
- static async getWalletFromUserId({ userId, merchantId, env, }) {
265
- return this.getWalletFromEmail({
266
- email: userId,
267
- merchantId,
268
- env,
269
- });
270
- }
271
- static async getWalletFromEmail({ email, merchantId, env, }) {
272
- const buffer = new TextEncoder().encode(email);
273
- const crypto = window.crypto.subtle;
274
- const hash = await crypto.digest('SHA-256', buffer);
275
- const seed = new Uint8Array(hash);
276
- const keypair = Keypair.fromSeed(seed);
277
- return {
278
- publicKey: keypair.publicKey,
279
- signMessage: (message) => Promise.resolve(sign.detached(message, keypair.secretKey)),
280
- signTransaction: async (transaction) => {
281
- if (transaction instanceof Transaction) {
282
- transaction.sign(keypair);
283
- return transaction;
284
- }
285
- else {
286
- transaction.sign([keypair]);
287
- return transaction;
288
- }
289
- },
290
- sendTransaction: async (transaction) => {
291
- if (transaction instanceof Transaction) {
292
- transaction.sign(keypair);
293
- }
294
- else {
295
- transaction.sign([keypair]);
296
- }
297
- const coinflowBaseUrl = this.getCoinflowApiUrl(env);
298
- const options = {
299
- method: 'POST',
300
- headers: {
301
- 'content-type': 'application/json',
302
- 'x-coinflow-auth-wallet': keypair.publicKey.toString(),
303
- 'x-coinflow-auth-blockchain': 'solana',
304
- },
305
- body: JSON.stringify({
306
- merchantId,
307
- signedTransaction: base58?.encode(transaction.serialize()),
308
- }),
309
- };
310
- const { signature } = await fetch(coinflowBaseUrl + '/api/utils/send-coinflow-tx', options).then(res => res.json());
311
- return signature;
312
- },
313
- };
314
- }
315
253
  }
316
254
 
317
255
  var IFrameMessageMethods;
@@ -929,12 +867,22 @@ class CoinflowCardNumberInput {
929
867
  .then(iframe => (this.iframe = iframe))
930
868
  .catch(e => console.error(e));
931
869
  }
932
- ngOnInit() {
870
+ initializeTokenEx() {
933
871
  setTokenExScriptTag({
934
872
  env: this.args.env,
935
873
  setTokenExScriptLoaded: this.onScriptLoaded.bind(this),
936
874
  });
937
875
  }
876
+ reinitialize() {
877
+ this.iframe = undefined;
878
+ this.initializeTokenEx();
879
+ }
880
+ ngOnInit() {
881
+ this.initializeTokenEx();
882
+ }
883
+ ngOnDestroy() {
884
+ this.iframe = undefined;
885
+ }
938
886
  tokenize() {
939
887
  return this.iframe.tokenize();
940
888
  }
@@ -971,12 +919,22 @@ class CoinflowCardNumberOnlyInput {
971
919
  .then(iframe => (this.iframe = iframe))
972
920
  .catch(e => console.error(e));
973
921
  }
974
- ngOnInit() {
922
+ initializeTokenEx() {
975
923
  setTokenExScriptTag({
976
924
  env: this.args.env,
977
925
  setTokenExScriptLoaded: this.onScriptLoaded.bind(this),
978
926
  });
979
927
  }
928
+ reinitialize() {
929
+ this.iframe = undefined;
930
+ this.initializeTokenEx();
931
+ }
932
+ ngOnInit() {
933
+ this.initializeTokenEx();
934
+ }
935
+ ngOnDestroy() {
936
+ this.iframe = undefined;
937
+ }
980
938
  tokenize() {
981
939
  return this.iframe.tokenize();
982
940
  }
@@ -1031,12 +989,22 @@ class CoinflowCvvOnlyInputComponent {
1031
989
  .then(iframe => (this.iframe = iframe))
1032
990
  .catch(e => console.error(e));
1033
991
  }
1034
- ngOnInit() {
992
+ initializeTokenEx() {
1035
993
  setTokenExScriptTag({
1036
994
  env: this.args.env,
1037
995
  setTokenExScriptLoaded: this.onScriptLoaded.bind(this),
1038
996
  });
1039
997
  }
998
+ reinitialize() {
999
+ this.iframe = undefined;
1000
+ this.initializeTokenEx();
1001
+ }
1002
+ ngOnInit() {
1003
+ this.initializeTokenEx();
1004
+ }
1005
+ ngOnDestroy() {
1006
+ this.iframe = undefined;
1007
+ }
1040
1008
  tokenize() {
1041
1009
  return this.iframe.tokenize();
1042
1010
  }