@blockchyp/blockchyp-ts 1.0.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.
Files changed (207) hide show
  1. package/.eslintrc.json +20 -0
  2. package/LICENSE +21 -0
  3. package/README.md +4314 -0
  4. package/index.js +24 -0
  5. package/index.ts +3 -0
  6. package/itest/ActivateTerminalITestSpec.js +87 -0
  7. package/itest/ActivateTerminalITestSpec.ts +58 -0
  8. package/itest/AddTestMerchantITestSpec.js +89 -0
  9. package/itest/AddTestMerchantITestSpec.ts +60 -0
  10. package/itest/BatchHistoryITestSpec.js +101 -0
  11. package/itest/BatchHistoryITestSpec.ts +73 -0
  12. package/itest/BooleanPromptITestSpec.js +104 -0
  13. package/itest/BooleanPromptITestSpec.ts +76 -0
  14. package/itest/CancelPaymentLinkITestSpec.js +116 -0
  15. package/itest/CancelPaymentLinkITestSpec.ts +93 -0
  16. package/itest/CaptureSignatureITestSpec.js +101 -0
  17. package/itest/CaptureSignatureITestSpec.ts +73 -0
  18. package/itest/DeactivateTerminalITestSpec.js +82 -0
  19. package/itest/DeactivateTerminalITestSpec.ts +52 -0
  20. package/itest/DeleteBrandingAssetITestSpec.js +96 -0
  21. package/itest/DeleteBrandingAssetITestSpec.ts +69 -0
  22. package/itest/DeleteCustomerITestSpec.js +102 -0
  23. package/itest/DeleteCustomerITestSpec.ts +75 -0
  24. package/itest/DeleteMediaAssetITestSpec.js +100 -0
  25. package/itest/DeleteMediaAssetITestSpec.ts +71 -0
  26. package/itest/DeleteQueuedTransactionITestSpec.js +117 -0
  27. package/itest/DeleteQueuedTransactionITestSpec.ts +89 -0
  28. package/itest/DeleteSlideShowITestSpec.js +96 -0
  29. package/itest/DeleteSlideShowITestSpec.ts +69 -0
  30. package/itest/DeleteSurveyQuestionITestSpec.js +97 -0
  31. package/itest/DeleteSurveyQuestionITestSpec.ts +70 -0
  32. package/itest/DeleteTestMerchantITestSpec.js +96 -0
  33. package/itest/DeleteTestMerchantITestSpec.ts +69 -0
  34. package/itest/DeleteTokenITestSpec.js +102 -0
  35. package/itest/DeleteTokenITestSpec.ts +75 -0
  36. package/itest/EmptyBrandingAssetITestSpec.js +85 -0
  37. package/itest/EmptyBrandingAssetITestSpec.ts +57 -0
  38. package/itest/EmptySlideShowITestSpec.js +87 -0
  39. package/itest/EmptySlideShowITestSpec.ts +58 -0
  40. package/itest/GatewayTimeoutITestSpec.js +103 -0
  41. package/itest/GatewayTimeoutITestSpec.ts +73 -0
  42. package/itest/GetCustomerITestSpec.js +102 -0
  43. package/itest/GetCustomerITestSpec.ts +75 -0
  44. package/itest/GetMerchantsITestSpec.js +84 -0
  45. package/itest/GetMerchantsITestSpec.ts +56 -0
  46. package/itest/InviteMerchantUserITestSpec.js +86 -0
  47. package/itest/InviteMerchantUserITestSpec.ts +58 -0
  48. package/itest/LinkTokenITestSpec.js +103 -0
  49. package/itest/LinkTokenITestSpec.ts +76 -0
  50. package/itest/ListQueuedTransactionsITestSpec.js +116 -0
  51. package/itest/ListQueuedTransactionsITestSpec.ts +88 -0
  52. package/itest/ListTerminalsITestSpec.js +83 -0
  53. package/itest/ListTerminalsITestSpec.ts +56 -0
  54. package/itest/MediaAssetITestSpec.js +105 -0
  55. package/itest/MediaAssetITestSpec.ts +75 -0
  56. package/itest/MediaITestSpec.js +83 -0
  57. package/itest/MediaITestSpec.ts +56 -0
  58. package/itest/MediaUploadITestSpec.js +94 -0
  59. package/itest/MediaUploadITestSpec.ts +63 -0
  60. package/itest/MerchantCredentialGenerationITestSpec.js +85 -0
  61. package/itest/MerchantCredentialGenerationITestSpec.ts +57 -0
  62. package/itest/MerchantInvoiceDetailITestSpec.js +84 -0
  63. package/itest/MerchantInvoiceDetailITestSpec.ts +56 -0
  64. package/itest/MerchantInvoicesITestSpec.js +84 -0
  65. package/itest/MerchantInvoicesITestSpec.ts +56 -0
  66. package/itest/MerchantPlatformsITestSpec.js +96 -0
  67. package/itest/MerchantPlatformsITestSpec.ts +69 -0
  68. package/itest/MerchantProfileITestSpec.js +84 -0
  69. package/itest/MerchantProfileITestSpec.ts +56 -0
  70. package/itest/MerchantUsersITestSpec.js +83 -0
  71. package/itest/MerchantUsersITestSpec.ts +56 -0
  72. package/itest/NewTransactionDisplayITestSpec.js +115 -0
  73. package/itest/NewTransactionDisplayITestSpec.ts +92 -0
  74. package/itest/PANChargeITestSpec.js +118 -0
  75. package/itest/PANChargeITestSpec.ts +88 -0
  76. package/itest/PANEnrollITestSpec.js +118 -0
  77. package/itest/PANEnrollITestSpec.ts +90 -0
  78. package/itest/PANPreauthITestSpec.js +116 -0
  79. package/itest/PANPreauthITestSpec.ts +87 -0
  80. package/itest/PartialRefundITestSpec.js +119 -0
  81. package/itest/PartialRefundITestSpec.ts +91 -0
  82. package/itest/PartnerCommissionBreakdownITestSpec.js +84 -0
  83. package/itest/PartnerCommissionBreakdownITestSpec.ts +56 -0
  84. package/itest/PartnerStatementDetailITestSpec.js +84 -0
  85. package/itest/PartnerStatementDetailITestSpec.ts +56 -0
  86. package/itest/PartnerStatementsITestSpec.js +84 -0
  87. package/itest/PartnerStatementsITestSpec.ts +56 -0
  88. package/itest/PaymentLinkStatusITestSpec.js +116 -0
  89. package/itest/PaymentLinkStatusITestSpec.ts +93 -0
  90. package/itest/PricingPolicyITestSpec.js +85 -0
  91. package/itest/PricingPolicyITestSpec.ts +57 -0
  92. package/itest/ResendPaymentLinkITestSpec.js +116 -0
  93. package/itest/ResendPaymentLinkITestSpec.ts +93 -0
  94. package/itest/SearchCustomerITestSpec.js +101 -0
  95. package/itest/SearchCustomerITestSpec.ts +75 -0
  96. package/itest/SendPaymentLinkITestSpec.js +107 -0
  97. package/itest/SendPaymentLinkITestSpec.ts +82 -0
  98. package/itest/SimpleBatchCloseITestSpec.js +101 -0
  99. package/itest/SimpleBatchCloseITestSpec.ts +73 -0
  100. package/itest/SimpleCaptureITestSpec.js +101 -0
  101. package/itest/SimpleCaptureITestSpec.ts +74 -0
  102. package/itest/SimpleGiftActivateITestSpec.js +104 -0
  103. package/itest/SimpleGiftActivateITestSpec.ts +75 -0
  104. package/itest/SimpleLocateITestSpec.js +85 -0
  105. package/itest/SimpleLocateITestSpec.ts +57 -0
  106. package/itest/SimpleMessageITestSpec.js +101 -0
  107. package/itest/SimpleMessageITestSpec.ts +73 -0
  108. package/itest/SimplePingITestSpec.js +100 -0
  109. package/itest/SimplePingITestSpec.ts +72 -0
  110. package/itest/SimpleRefundITestSpec.js +118 -0
  111. package/itest/SimpleRefundITestSpec.ts +90 -0
  112. package/itest/SimpleReversalITestSpec.js +103 -0
  113. package/itest/SimpleReversalITestSpec.ts +75 -0
  114. package/itest/SimpleVoidITestSpec.js +103 -0
  115. package/itest/SimpleVoidITestSpec.ts +75 -0
  116. package/itest/SlideShowITestSpec.js +98 -0
  117. package/itest/SlideShowITestSpec.ts +70 -0
  118. package/itest/SlideShowsITestSpec.js +95 -0
  119. package/itest/SlideShowsITestSpec.ts +69 -0
  120. package/itest/SurveyQuestionITestSpec.js +95 -0
  121. package/itest/SurveyQuestionITestSpec.ts +68 -0
  122. package/itest/SurveyQuestionsITestSpec.js +96 -0
  123. package/itest/SurveyQuestionsITestSpec.ts +70 -0
  124. package/itest/SurveyResultsITestSpec.js +95 -0
  125. package/itest/SurveyResultsITestSpec.ts +68 -0
  126. package/itest/TCDeleteTemplateITestSpec.js +98 -0
  127. package/itest/TCDeleteTemplateITestSpec.ts +70 -0
  128. package/itest/TCEntryITestSpec.js +103 -0
  129. package/itest/TCEntryITestSpec.ts +76 -0
  130. package/itest/TCLogITestSpec.js +83 -0
  131. package/itest/TCLogITestSpec.ts +56 -0
  132. package/itest/TCTemplateITestSpec.js +101 -0
  133. package/itest/TCTemplateITestSpec.ts +72 -0
  134. package/itest/TCTemplateUpdateITestSpec.js +91 -0
  135. package/itest/TCTemplateUpdateITestSpec.ts +61 -0
  136. package/itest/TCTemplatesITestSpec.js +83 -0
  137. package/itest/TCTemplatesITestSpec.ts +56 -0
  138. package/itest/TerminalBrandingITestSpec.js +83 -0
  139. package/itest/TerminalBrandingITestSpec.ts +56 -0
  140. package/itest/TerminalChargeITestSpec.js +113 -0
  141. package/itest/TerminalChargeITestSpec.ts +84 -0
  142. package/itest/TerminalClearITestSpec.js +100 -0
  143. package/itest/TerminalClearITestSpec.ts +72 -0
  144. package/itest/TerminalEBTBalanceITestSpec.js +103 -0
  145. package/itest/TerminalEBTBalanceITestSpec.ts +74 -0
  146. package/itest/TerminalEBTChargeITestSpec.js +115 -0
  147. package/itest/TerminalEBTChargeITestSpec.ts +86 -0
  148. package/itest/TerminalEnrollITestSpec.js +112 -0
  149. package/itest/TerminalEnrollITestSpec.ts +83 -0
  150. package/itest/TerminalGiftCardBalanceITestSpec.js +102 -0
  151. package/itest/TerminalGiftCardBalanceITestSpec.ts +73 -0
  152. package/itest/TerminalKeyedChargeITestSpec.js +114 -0
  153. package/itest/TerminalKeyedChargeITestSpec.ts +85 -0
  154. package/itest/TerminalManualEBTChargeITestSpec.js +116 -0
  155. package/itest/TerminalManualEBTChargeITestSpec.ts +87 -0
  156. package/itest/TerminalPreauthITestSpec.js +113 -0
  157. package/itest/TerminalPreauthITestSpec.ts +84 -0
  158. package/itest/TerminalQueuedTransactionITestSpec.js +108 -0
  159. package/itest/TerminalQueuedTransactionITestSpec.ts +78 -0
  160. package/itest/TerminalStatusITestSpec.js +100 -0
  161. package/itest/TerminalStatusITestSpec.ts +72 -0
  162. package/itest/TerminalTimeoutITestSpec.js +99 -0
  163. package/itest/TerminalTimeoutITestSpec.ts +70 -0
  164. package/itest/TermsAndConditionsITestSpec.js +105 -0
  165. package/itest/TermsAndConditionsITestSpec.ts +77 -0
  166. package/itest/TextPromptITestSpec.js +103 -0
  167. package/itest/TextPromptITestSpec.ts +74 -0
  168. package/itest/TokenMetadataITestSpec.js +102 -0
  169. package/itest/TokenMetadataITestSpec.ts +75 -0
  170. package/itest/TransactionHistoryITestSpec.js +101 -0
  171. package/itest/TransactionHistoryITestSpec.ts +73 -0
  172. package/itest/UnlinkTokenITestSpec.js +103 -0
  173. package/itest/UnlinkTokenITestSpec.ts +76 -0
  174. package/itest/UpdateBrandingAssetITestSpec.js +109 -0
  175. package/itest/UpdateBrandingAssetITestSpec.ts +80 -0
  176. package/itest/UpdateCustomerITestSpec.js +90 -0
  177. package/itest/UpdateCustomerITestSpec.ts +63 -0
  178. package/itest/UpdateMerchantITestSpec.js +92 -0
  179. package/itest/UpdateMerchantITestSpec.ts +65 -0
  180. package/itest/UpdateMerchantPlatformsITestSpec.js +98 -0
  181. package/itest/UpdateMerchantPlatformsITestSpec.ts +71 -0
  182. package/itest/UpdateSlideShowITestSpec.js +106 -0
  183. package/itest/UpdateSlideShowITestSpec.ts +78 -0
  184. package/itest/UpdateSurveyQuestionITestSpec.js +89 -0
  185. package/itest/UpdateSurveyQuestionITestSpec.ts +60 -0
  186. package/itest/UpdateTransactionDisplayITestSpec.js +115 -0
  187. package/itest/UpdateTransactionDisplayITestSpec.ts +92 -0
  188. package/itest/UploadStatusITestSpec.js +100 -0
  189. package/itest/UploadStatusITestSpec.ts +71 -0
  190. package/itest/support/aviato.png +0 -0
  191. package/itest/support/config.js +67 -0
  192. package/itest/support/config.ts +106 -0
  193. package/itest/support/jasmine.json +11 -0
  194. package/package.json +73 -0
  195. package/spec/CryptoSpec.js +35 -0
  196. package/spec/CryptoSpec.ts +35 -0
  197. package/spec/SanitySpec.js +26 -0
  198. package/spec/SanitySpec.ts +23 -0
  199. package/spec/support/jasmine.json +11 -0
  200. package/src/client.js +941 -0
  201. package/src/client.ts +1012 -0
  202. package/src/cryptoutils.js +89 -0
  203. package/src/cryptoutils.ts +80 -0
  204. package/src/global.js +9 -0
  205. package/src/global.ts +5 -0
  206. package/src/models.js +9382 -0
  207. package/src/models.ts +16509 -0
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.BlockChypCrypto = void 0;
27
+ const createHmac = require('create-hmac');
28
+ const randomBytes = require('randombytes');
29
+ const moment = require('moment');
30
+ const base32 = require('base32');
31
+ const shajs = require('sha.js');
32
+ const EC = __importStar(require("elliptic"));
33
+ const aesjs = __importStar(require("aes-js"));
34
+ class BlockChypCrypto {
35
+ generateGatewayHeaders(creds) {
36
+ const nonce = this.generateNonce();
37
+ const ts = this.generateIsoTimestamp();
38
+ const toSign = creds.apiKey + creds.bearerToken + ts + nonce;
39
+ const key = Buffer.from(creds.signingKey, 'hex');
40
+ const hmac = createHmac('sha256', key);
41
+ hmac.update(toSign);
42
+ const sig = hmac.digest('hex');
43
+ const results = {
44
+ 'Nonce': nonce,
45
+ 'Timestamp': ts,
46
+ 'Authorization': 'Dual ' + creds.bearerToken + ':' + creds.apiKey + ':' + sig
47
+ };
48
+ return results;
49
+ }
50
+ encrypt(hexKey, plainText) {
51
+ const key = Buffer.from(hexKey, 'hex').slice(0, 32);
52
+ const keyArr = [...key];
53
+ const iv = randomBytes(16);
54
+ const ivArr = [...iv];
55
+ const aesCbc = new aesjs.ModeOfOperation.cbc(keyArr, ivArr);
56
+ const plainBytes = aesjs.padding.pkcs7.pad(aesjs.utils.utf8.toBytes(plainText));
57
+ const encryptedBytes = aesCbc.encrypt(plainBytes);
58
+ return iv.toString('hex') + aesjs.utils.hex.fromBytes(encryptedBytes);
59
+ }
60
+ sha256Hash(msg) {
61
+ return shajs('sha256').update(msg, 'hex').digest('hex');
62
+ }
63
+ validateSignature(publicKey, msg, sig) {
64
+ const ec = new EC.ec('p256');
65
+ const key = ec.keyFromPublic({ x: publicKey.x, y: publicKey.y });
66
+ const msgHash = this.sha256Hash(msg);
67
+ return key.verify(msgHash, { r: sig.r, s: sig.s });
68
+ }
69
+ decrypt(hexKey, cipherText) {
70
+ const key = Buffer.from(hexKey, 'hex').slice(0, 32);
71
+ const keyArr = [...key];
72
+ const cipherBytes = Buffer.from(cipherText, 'hex');
73
+ const iv = cipherBytes.slice(0, 16);
74
+ const aesCbc = new aesjs.ModeOfOperation.cbc(keyArr, iv);
75
+ const cipher = cipherBytes.slice(16, cipherBytes.length);
76
+ const cipherArr = [...cipher];
77
+ const decryptedBytes = aesjs.padding.pkcs7.strip(aesCbc.decrypt(cipherArr));
78
+ return aesjs.utils.utf8.fromBytes(decryptedBytes);
79
+ }
80
+ generateNonce() {
81
+ return base32.encode(randomBytes(32), "Crockford").toUpperCase();
82
+ }
83
+ generateIsoTimestamp() {
84
+ return moment().utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z';
85
+ }
86
+ }
87
+ exports.BlockChypCrypto = BlockChypCrypto;
88
+ const CryptoUtils = new BlockChypCrypto();
89
+ exports.default = CryptoUtils;
@@ -0,0 +1,80 @@
1
+ const createHmac = require('create-hmac')
2
+ const randomBytes = require('randombytes')
3
+ const moment = require('moment')
4
+ const base32 = require('base32')
5
+ const shajs = require('sha.js')
6
+ import * as EC from 'elliptic'
7
+ import * as aesjs from 'aes-js'
8
+ import { BlockChypCredentials } from './client'
9
+
10
+ export class BlockChypCrypto {
11
+ generateGatewayHeaders (creds: BlockChypCredentials) {
12
+ const nonce = this.generateNonce()
13
+ const ts = this.generateIsoTimestamp()
14
+ const toSign = creds.apiKey + creds.bearerToken + ts + nonce
15
+ const key = Buffer.from(creds.signingKey, 'hex')
16
+ const hmac = createHmac('sha256', key)
17
+ hmac.update(toSign)
18
+ const sig = hmac.digest('hex')
19
+
20
+ const results = {
21
+ 'Nonce': nonce,
22
+ 'Timestamp': ts,
23
+ 'Authorization': 'Dual ' + creds.bearerToken + ':' + creds.apiKey + ':' + sig
24
+ }
25
+
26
+ return results
27
+ }
28
+
29
+ encrypt (hexKey: string, plainText: string) {
30
+ const key = Buffer.from(hexKey, 'hex').slice(0, 32)
31
+ const keyArr = [...key]
32
+
33
+ const iv = randomBytes(16)
34
+ const ivArr = [...iv]
35
+
36
+ const aesCbc = new aesjs.ModeOfOperation.cbc(keyArr, ivArr)
37
+ const plainBytes = aesjs.padding.pkcs7.pad(aesjs.utils.utf8.toBytes(plainText))
38
+ const encryptedBytes = aesCbc.encrypt(plainBytes)
39
+
40
+ return iv.toString('hex') + aesjs.utils.hex.fromBytes(encryptedBytes)
41
+ }
42
+
43
+ sha256Hash (msg: string) {
44
+ return shajs('sha256').update(msg, 'hex').digest('hex')
45
+ }
46
+
47
+ validateSignature (publicKey: any, msg: string, sig: any) {
48
+ const ec = new EC.ec('p256')
49
+ const key = ec.keyFromPublic({x: publicKey.x, y: publicKey.y})
50
+ const msgHash = this.sha256Hash(msg)
51
+ return key.verify(msgHash, {r: sig.r, s: sig.s})
52
+ }
53
+
54
+ decrypt (hexKey: string, cipherText: string) {
55
+ const key = Buffer.from(hexKey, 'hex').slice(0, 32)
56
+ const keyArr = [...key]
57
+
58
+ const cipherBytes = Buffer.from(cipherText, 'hex')
59
+ const iv = cipherBytes.slice(0, 16)
60
+
61
+ const aesCbc = new aesjs.ModeOfOperation.cbc(keyArr, iv)
62
+
63
+ const cipher = cipherBytes.slice(16, cipherBytes.length)
64
+ const cipherArr = [...cipher]
65
+ const decryptedBytes = aesjs.padding.pkcs7.strip(aesCbc.decrypt(cipherArr))
66
+
67
+ return aesjs.utils.utf8.fromBytes(decryptedBytes)
68
+ }
69
+
70
+ generateNonce () {
71
+ return base32.encode(randomBytes(32), "Crockford").toUpperCase()
72
+ }
73
+
74
+ generateIsoTimestamp () {
75
+ return moment().utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z'
76
+ }
77
+ }
78
+
79
+ const CryptoUtils = new BlockChypCrypto()
80
+ export default CryptoUtils
package/src/global.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const client_1 = __importDefault(require("./client"));
7
+ if (typeof window !== 'undefined') {
8
+ window.blockchyp = client_1.default;
9
+ }
package/src/global.ts ADDED
@@ -0,0 +1,5 @@
1
+ import BlockChyp from './client'
2
+
3
+ if (typeof window !== 'undefined') {
4
+ (window as any).blockchyp = BlockChyp;
5
+ }