@atomiqlabs/base 10.0.0-dev.2 → 10.0.0-dev.21

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 (131) hide show
  1. package/LICENSE +201 -201
  2. package/dist/btc/BitcoinNetwork.d.ts +6 -6
  3. package/dist/btc/BitcoinNetwork.js +10 -10
  4. package/dist/btc/rpc/BitcoinRpc.d.ts +68 -68
  5. package/dist/btc/rpc/BitcoinRpc.js +2 -2
  6. package/dist/btcrelay/BtcRelay.d.ts +61 -61
  7. package/dist/btcrelay/BtcRelay.js +2 -2
  8. package/dist/btcrelay/synchronizer/RelaySynchronizer.d.ts +18 -18
  9. package/dist/btcrelay/synchronizer/RelaySynchronizer.js +2 -2
  10. package/dist/btcrelay/types/BtcBlock.d.ts +13 -13
  11. package/dist/btcrelay/types/BtcBlock.js +2 -2
  12. package/dist/btcrelay/types/BtcHeader.d.ts +10 -10
  13. package/dist/btcrelay/types/BtcHeader.js +2 -2
  14. package/dist/btcrelay/types/BtcStoredHeader.d.ts +11 -11
  15. package/dist/btcrelay/types/BtcStoredHeader.js +2 -2
  16. package/dist/btcrelay/utils/StatePredictorUtils.d.ts +11 -11
  17. package/dist/btcrelay/utils/StatePredictorUtils.js +80 -80
  18. package/dist/chains/ChainData.d.ts +31 -31
  19. package/dist/chains/ChainData.js +2 -2
  20. package/dist/chains/ChainInterface.d.ts +133 -110
  21. package/dist/chains/ChainInterface.js +7 -2
  22. package/dist/chains/ChainType.d.ts +24 -23
  23. package/dist/chains/ChainType.js +2 -2
  24. package/dist/errors/CannotInitializeATAError.d.ts +3 -3
  25. package/dist/errors/CannotInitializeATAError.js +11 -11
  26. package/dist/errors/SignatureVerificationError.d.ts +3 -3
  27. package/dist/errors/SignatureVerificationError.js +11 -11
  28. package/dist/errors/SwapDataVerificationError.d.ts +3 -3
  29. package/dist/errors/SwapDataVerificationError.js +11 -11
  30. package/dist/errors/TransactionRevertedError.d.ts +3 -0
  31. package/dist/errors/TransactionRevertedError.js +11 -0
  32. package/dist/events/ChainEvents.d.ts +9 -9
  33. package/dist/events/ChainEvents.js +2 -2
  34. package/dist/events/types/ChainEvent.d.ts +7 -7
  35. package/dist/events/types/ChainEvent.js +6 -6
  36. package/dist/events/types/spv_vault/SpvVaultClaimEvent.d.ts +12 -12
  37. package/dist/events/types/spv_vault/SpvVaultClaimEvent.js +18 -18
  38. package/dist/events/types/spv_vault/SpvVaultCloseEvent.d.ts +7 -7
  39. package/dist/events/types/spv_vault/SpvVaultCloseEvent.js +13 -13
  40. package/dist/events/types/spv_vault/SpvVaultDepositEvent.d.ts +7 -7
  41. package/dist/events/types/spv_vault/SpvVaultDepositEvent.js +13 -13
  42. package/dist/events/types/spv_vault/SpvVaultEvent.d.ts +15 -15
  43. package/dist/events/types/spv_vault/SpvVaultEvent.js +20 -20
  44. package/dist/events/types/spv_vault/SpvVaultFrontEvent.d.ts +10 -10
  45. package/dist/events/types/spv_vault/SpvVaultFrontEvent.js +16 -16
  46. package/dist/events/types/spv_vault/SpvVaultOpenEvent.d.ts +7 -7
  47. package/dist/events/types/spv_vault/SpvVaultOpenEvent.js +13 -13
  48. package/dist/events/types/swap/ClaimEvent.d.ts +7 -7
  49. package/dist/events/types/swap/ClaimEvent.js +11 -11
  50. package/dist/events/types/swap/InitializeEvent.d.ts +9 -9
  51. package/dist/events/types/swap/InitializeEvent.js +12 -12
  52. package/dist/events/types/swap/RefundEvent.d.ts +5 -5
  53. package/dist/events/types/swap/RefundEvent.js +7 -7
  54. package/dist/events/types/swap/SwapEvent.d.ts +12 -12
  55. package/dist/events/types/swap/SwapEvent.js +17 -17
  56. package/dist/index.d.ts +42 -38
  57. package/dist/index.js +58 -54
  58. package/dist/lockable/Lockable.d.ts +6 -6
  59. package/dist/lockable/Lockable.js +28 -28
  60. package/dist/messaging/Messenger.d.ts +8 -0
  61. package/dist/messaging/Messenger.js +2 -0
  62. package/dist/messaging/messages/Message.d.ts +11 -0
  63. package/dist/messaging/messages/Message.js +22 -0
  64. package/dist/messaging/messages/SwapClaimWitnessMessage.d.ts +10 -0
  65. package/dist/messaging/messages/SwapClaimWitnessMessage.js +28 -0
  66. package/dist/spv_swap/SpvVaultContract.d.ts +258 -199
  67. package/dist/spv_swap/SpvVaultContract.js +2 -2
  68. package/dist/spv_swap/SpvVaultData.d.ts +35 -35
  69. package/dist/spv_swap/SpvVaultData.js +37 -37
  70. package/dist/spv_swap/SpvWithdrawalState.d.ts +31 -31
  71. package/dist/spv_swap/SpvWithdrawalState.js +10 -10
  72. package/dist/spv_swap/SpvWithdrawalTransactionData.d.ts +43 -43
  73. package/dist/spv_swap/SpvWithdrawalTransactionData.js +143 -143
  74. package/dist/storage/IStorageManager.d.ts +15 -15
  75. package/dist/storage/IStorageManager.js +2 -2
  76. package/dist/storage/StorageObject.d.ts +3 -3
  77. package/dist/storage/StorageObject.js +2 -2
  78. package/dist/swaps/ChainSwapType.d.ts +6 -6
  79. package/dist/swaps/ChainSwapType.js +10 -10
  80. package/dist/swaps/SwapCommitState.d.ts +39 -38
  81. package/dist/swaps/SwapCommitState.js +11 -11
  82. package/dist/swaps/SwapContract.d.ts +479 -467
  83. package/dist/swaps/SwapContract.js +2 -2
  84. package/dist/swaps/SwapData.d.ts +37 -36
  85. package/dist/swaps/SwapData.js +17 -14
  86. package/dist/utils/BigIntBufferUtils.d.ts +6 -6
  87. package/dist/utils/BigIntBufferUtils.js +31 -31
  88. package/package.json +31 -31
  89. package/src/btc/BitcoinNetwork.ts +6 -6
  90. package/src/btc/rpc/BitcoinRpc.ts +77 -77
  91. package/src/btcrelay/BtcRelay.ts +70 -70
  92. package/src/btcrelay/synchronizer/RelaySynchronizer.ts +17 -17
  93. package/src/btcrelay/types/BtcBlock.ts +15 -15
  94. package/src/btcrelay/types/BtcHeader.ts +11 -11
  95. package/src/btcrelay/types/BtcStoredHeader.ts +12 -12
  96. package/src/btcrelay/utils/StatePredictorUtils.ts +108 -108
  97. package/src/chains/ChainData.ts +40 -40
  98. package/src/chains/ChainInterface.ts +159 -132
  99. package/src/chains/ChainType.ts +40 -38
  100. package/src/errors/CannotInitializeATAError.ts +11 -11
  101. package/src/errors/SignatureVerificationError.ts +11 -11
  102. package/src/errors/SwapDataVerificationError.ts +11 -11
  103. package/src/errors/TransactionRevertedError.ts +11 -0
  104. package/src/events/ChainEvents.ts +13 -13
  105. package/src/events/types/ChainEvent.ts +10 -10
  106. package/src/events/types/spv_vault/SpvVaultClaimEvent.ts +31 -31
  107. package/src/events/types/spv_vault/SpvVaultCloseEvent.ts +17 -17
  108. package/src/events/types/spv_vault/SpvVaultDepositEvent.ts +17 -17
  109. package/src/events/types/spv_vault/SpvVaultEvent.ts +25 -25
  110. package/src/events/types/spv_vault/SpvVaultFrontEvent.ts +27 -27
  111. package/src/events/types/spv_vault/SpvVaultOpenEvent.ts +16 -16
  112. package/src/events/types/swap/ClaimEvent.ts +15 -15
  113. package/src/events/types/swap/InitializeEvent.ts +18 -18
  114. package/src/events/types/swap/RefundEvent.ts +6 -6
  115. package/src/events/types/swap/SwapEvent.ts +21 -21
  116. package/src/index.ts +51 -46
  117. package/src/lockable/Lockable.ts +30 -30
  118. package/src/messaging/Messenger.ts +11 -0
  119. package/src/messaging/messages/Message.ts +25 -0
  120. package/src/messaging/messages/SwapClaimWitnessMessage.ts +34 -0
  121. package/src/spv_swap/SpvVaultContract.ts +269 -230
  122. package/src/spv_swap/SpvVaultData.ts +70 -70
  123. package/src/spv_swap/SpvWithdrawalState.ts +40 -40
  124. package/src/spv_swap/SpvWithdrawalTransactionData.ts +169 -169
  125. package/src/storage/IStorageManager.ts +16 -16
  126. package/src/storage/StorageObject.ts +6 -6
  127. package/src/swaps/ChainSwapType.ts +6 -6
  128. package/src/swaps/SwapCommitState.ts +40 -39
  129. package/src/swaps/SwapContract.ts +564 -556
  130. package/src/swaps/SwapData.ts +69 -65
  131. package/src/utils/BigIntBufferUtils.ts +31 -31
package/src/index.ts CHANGED
@@ -1,46 +1,51 @@
1
- export * from "./btcrelay/BtcRelay";
2
- export * from "./btc/rpc/BitcoinRpc";
3
- export * from "./btcrelay/synchronizer/RelaySynchronizer";
4
- export * from "./btcrelay/types/BtcBlock";
5
- export * from "./btcrelay/types/BtcHeader";
6
- export * from "./btcrelay/types/BtcStoredHeader";
7
- export * from "./btcrelay/utils/StatePredictorUtils";
8
- export * from "./events/ChainEvents";
9
- export * from "./events/types/swap/ClaimEvent";
10
- export * from "./events/types/swap/InitializeEvent";
11
- export * from "./events/types/swap/RefundEvent";
12
- export * from "./events/types/swap/SwapEvent";
13
- export * from "./lockable/Lockable";
14
- export * from "./storage/IStorageManager";
15
- export * from "./storage/StorageObject";
16
- export * from "./swaps/SwapContract";
17
- export * from "./swaps/SwapData";
18
- export * from "./swaps/ChainSwapType";
19
- export * from "./swaps/SwapCommitState";
20
-
21
- export * from "./errors/SignatureVerificationError";
22
- export * from "./errors/CannotInitializeATAError"
23
- export * from "./errors/SwapDataVerificationError";
24
-
25
- export * from "./chains/ChainType";
26
- export * from "./chains/ChainData";
27
-
28
- export * from "./utils/BigIntBufferUtils";
29
-
30
- export * from "./btc/BitcoinNetwork";
31
-
32
- export * from "./chains/ChainInterface";
33
-
34
- export * from "./spv_swap/SpvVaultContract";
35
- export * from "./spv_swap/SpvVaultData";
36
- export * from "./spv_swap/SpvWithdrawalState";
37
- export * from "./spv_swap/SpvWithdrawalTransactionData";
38
-
39
- export * from "./events/types/ChainEvent";
40
-
41
- export * from "./events/types/spv_vault/SpvVaultEvent";
42
- export * from "./events/types/spv_vault/SpvVaultCloseEvent";
43
- export * from "./events/types/spv_vault/SpvVaultClaimEvent";
44
- export * from "./events/types/spv_vault/SpvVaultDepositEvent";
45
- export * from "./events/types/spv_vault/SpvVaultOpenEvent";
46
- export * from "./events/types/spv_vault/SpvVaultFrontEvent";
1
+ export * from "./btcrelay/BtcRelay";
2
+ export * from "./btc/rpc/BitcoinRpc";
3
+ export * from "./btcrelay/synchronizer/RelaySynchronizer";
4
+ export * from "./btcrelay/types/BtcBlock";
5
+ export * from "./btcrelay/types/BtcHeader";
6
+ export * from "./btcrelay/types/BtcStoredHeader";
7
+ export * from "./btcrelay/utils/StatePredictorUtils";
8
+ export * from "./events/ChainEvents";
9
+ export * from "./events/types/swap/ClaimEvent";
10
+ export * from "./events/types/swap/InitializeEvent";
11
+ export * from "./events/types/swap/RefundEvent";
12
+ export * from "./events/types/swap/SwapEvent";
13
+ export * from "./lockable/Lockable";
14
+ export * from "./storage/IStorageManager";
15
+ export * from "./storage/StorageObject";
16
+ export * from "./swaps/SwapContract";
17
+ export * from "./swaps/SwapData";
18
+ export * from "./swaps/ChainSwapType";
19
+ export * from "./swaps/SwapCommitState";
20
+
21
+ export * from "./errors/SignatureVerificationError";
22
+ export * from "./errors/CannotInitializeATAError"
23
+ export * from "./errors/SwapDataVerificationError";
24
+ export * from "./errors/TransactionRevertedError";
25
+
26
+ export * from "./chains/ChainType";
27
+ export * from "./chains/ChainData";
28
+
29
+ export * from "./utils/BigIntBufferUtils";
30
+
31
+ export * from "./btc/BitcoinNetwork";
32
+
33
+ export * from "./chains/ChainInterface";
34
+
35
+ export * from "./spv_swap/SpvVaultContract";
36
+ export * from "./spv_swap/SpvVaultData";
37
+ export * from "./spv_swap/SpvWithdrawalState";
38
+ export * from "./spv_swap/SpvWithdrawalTransactionData";
39
+
40
+ export * from "./events/types/ChainEvent";
41
+
42
+ export * from "./events/types/spv_vault/SpvVaultEvent";
43
+ export * from "./events/types/spv_vault/SpvVaultCloseEvent";
44
+ export * from "./events/types/spv_vault/SpvVaultClaimEvent";
45
+ export * from "./events/types/spv_vault/SpvVaultDepositEvent";
46
+ export * from "./events/types/spv_vault/SpvVaultOpenEvent";
47
+ export * from "./events/types/spv_vault/SpvVaultFrontEvent";
48
+
49
+ export * from "./messaging/Messenger";
50
+ export * from "./messaging/messages/Message";
51
+ export * from "./messaging/messages/SwapClaimWitnessMessage";
@@ -1,30 +1,30 @@
1
-
2
-
3
- export class Lockable {
4
-
5
- private lockedTill = 0;
6
- private lockNonce = 0;
7
-
8
- lock(timeoutSeconds: number): (() => boolean) | null {
9
- if(this.isLocked()) {
10
- return null;
11
- }
12
-
13
- this.lockedTill = Date.now()+(timeoutSeconds*1000);
14
-
15
- this.lockNonce++;
16
- const lockNonce = this.lockNonce;
17
- return () => {
18
- if(this.lockNonce!==lockNonce) {
19
- return false;
20
- }
21
- this.lockedTill = 0;
22
- return true;
23
- };
24
- }
25
-
26
- isLocked(): boolean {
27
- return this.lockedTill>Date.now();
28
- }
29
-
30
- }
1
+
2
+
3
+ export class Lockable {
4
+
5
+ private lockedTill = 0;
6
+ private lockNonce = 0;
7
+
8
+ lock(timeoutSeconds: number): (() => boolean) | null {
9
+ if(this.isLocked()) {
10
+ return null;
11
+ }
12
+
13
+ this.lockedTill = Date.now()+(timeoutSeconds*1000);
14
+
15
+ this.lockNonce++;
16
+ const lockNonce = this.lockNonce;
17
+ return () => {
18
+ if(this.lockNonce!==lockNonce) {
19
+ return false;
20
+ }
21
+ this.lockedTill = 0;
22
+ return true;
23
+ };
24
+ }
25
+
26
+ isLocked(): boolean {
27
+ return this.lockedTill>Date.now();
28
+ }
29
+
30
+ }
@@ -0,0 +1,11 @@
1
+ import {Message} from "./messages/Message";
2
+
3
+ export interface Messenger {
4
+
5
+ init(): Promise<void>;
6
+ broadcast(msg: Message): Promise<void>;
7
+ subscribe(callback: (msg: Message) => void): Promise<void>;
8
+ unsubscribe(callback: (msg: Message) => void): Promise<boolean>;
9
+ stop(): Promise<void>;
10
+
11
+ }
@@ -0,0 +1,25 @@
1
+
2
+ export enum MessageType {
3
+ SWAP_CLAIM_WITNESS = 0,
4
+
5
+ }
6
+
7
+ export abstract class Message {
8
+
9
+ abstract type: MessageType;
10
+
11
+ static deserializers: {[type: number]: (obj: any) => Message} = {};
12
+
13
+ serialize(): any {
14
+ return {
15
+ type: this.type
16
+ }
17
+ }
18
+
19
+ static deserialize(message: any): Message {
20
+ const deserializer = Message.deserializers[message.type];
21
+ if(deserializer==null) throw new Error("Unknown message type " + message.type);
22
+ return deserializer(message);
23
+ }
24
+
25
+ }
@@ -0,0 +1,34 @@
1
+ import {SwapData} from "../../swaps/SwapData";
2
+ import {Message, MessageType} from "./Message";
3
+
4
+
5
+ export class SwapClaimWitnessMessage<T extends SwapData> extends Message {
6
+
7
+ type = MessageType.SWAP_CLAIM_WITNESS;
8
+ swapData: T;
9
+ witness: string;
10
+
11
+ constructor(swapData: T, witness: string) {
12
+ super();
13
+ this.swapData = swapData;
14
+ this.witness = witness;
15
+ }
16
+
17
+ serialize() {
18
+ return {
19
+ ...super.serialize(),
20
+ swapData: this.swapData.serialize(),
21
+ witness: this.witness
22
+ }
23
+ }
24
+
25
+ static deserialize(obj: any) {
26
+ if(obj==null || typeof(obj.witness)!=="string" || typeof(obj.swapData)!=="object") {
27
+ throw new Error("Invalid format!");
28
+ }
29
+ return new SwapClaimWitnessMessage(SwapData.deserialize(obj.swapData), obj.witness);
30
+ }
31
+
32
+ }
33
+
34
+ Message.deserializers[MessageType.SWAP_CLAIM_WITNESS] = SwapClaimWitnessMessage.deserialize;