@cardano-sdk/wallet 0.1.4 → 0.1.5

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 (118) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +5 -0
  3. package/dist/Address.d.ts +11 -0
  4. package/dist/Address.d.ts.map +1 -0
  5. package/dist/Address.js +9 -0
  6. package/dist/Address.js.map +1 -0
  7. package/dist/BalanceTracker.d.ts +23 -0
  8. package/dist/BalanceTracker.d.ts.map +1 -0
  9. package/dist/BalanceTracker.js +48 -0
  10. package/dist/BalanceTracker.js.map +1 -0
  11. package/dist/InMemoryTransactionTracker.d.ts +16 -0
  12. package/dist/InMemoryTransactionTracker.d.ts.map +1 -0
  13. package/dist/InMemoryTransactionTracker.js +84 -0
  14. package/dist/InMemoryTransactionTracker.js.map +1 -0
  15. package/dist/InMemoryUtxoRepository.d.ts +25 -0
  16. package/dist/InMemoryUtxoRepository.d.ts.map +1 -0
  17. package/dist/InMemoryUtxoRepository.js +154 -0
  18. package/dist/InMemoryUtxoRepository.js.map +1 -0
  19. package/dist/KeyManagement/InMemoryKeyManager.d.ts +9 -0
  20. package/dist/KeyManagement/InMemoryKeyManager.d.ts.map +1 -0
  21. package/dist/KeyManagement/InMemoryKeyManager.js +68 -0
  22. package/dist/KeyManagement/InMemoryKeyManager.js.map +1 -0
  23. package/dist/KeyManagement/errors/InvalidMnemonic.d.ts +5 -0
  24. package/dist/KeyManagement/errors/InvalidMnemonic.d.ts.map +1 -0
  25. package/dist/KeyManagement/errors/InvalidMnemonic.js +13 -0
  26. package/dist/KeyManagement/errors/InvalidMnemonic.js.map +1 -0
  27. package/{src/KeyManagement/errors/index.ts → dist/KeyManagement/errors/index.d.ts} +1 -0
  28. package/dist/KeyManagement/errors/index.d.ts.map +1 -0
  29. package/dist/KeyManagement/errors/index.js +6 -0
  30. package/dist/KeyManagement/errors/index.js.map +1 -0
  31. package/{src/KeyManagement/index.ts → dist/KeyManagement/index.d.ts} +1 -0
  32. package/dist/KeyManagement/index.d.ts.map +1 -0
  33. package/dist/KeyManagement/index.js +30 -0
  34. package/dist/KeyManagement/index.js.map +1 -0
  35. package/dist/KeyManagement/types.d.ts +14 -0
  36. package/dist/KeyManagement/types.d.ts.map +1 -0
  37. package/dist/KeyManagement/types.js +3 -0
  38. package/dist/KeyManagement/types.js.map +1 -0
  39. package/dist/KeyManagement/util.d.ts +6 -0
  40. package/dist/KeyManagement/util.d.ts.map +1 -0
  41. package/dist/KeyManagement/util.js +31 -0
  42. package/dist/KeyManagement/util.js.map +1 -0
  43. package/dist/SingleAddressWallet.d.ts +30 -0
  44. package/dist/SingleAddressWallet.d.ts.map +1 -0
  45. package/dist/SingleAddressWallet.js +62 -0
  46. package/dist/SingleAddressWallet.js.map +1 -0
  47. package/dist/Transaction/CertificateFactory.d.ts +50 -0
  48. package/dist/Transaction/CertificateFactory.d.ts.map +1 -0
  49. package/dist/Transaction/CertificateFactory.js +72 -0
  50. package/dist/Transaction/CertificateFactory.js.map +1 -0
  51. package/dist/Transaction/computeImplicitCoin.d.ts +4 -0
  52. package/dist/Transaction/computeImplicitCoin.d.ts.map +1 -0
  53. package/dist/Transaction/computeImplicitCoin.js +21 -0
  54. package/dist/Transaction/computeImplicitCoin.js.map +1 -0
  55. package/dist/Transaction/createTransactionInternals.d.ts +16 -0
  56. package/dist/Transaction/createTransactionInternals.d.ts.map +1 -0
  57. package/dist/Transaction/createTransactionInternals.js +41 -0
  58. package/dist/Transaction/createTransactionInternals.js.map +1 -0
  59. package/{src/Transaction/index.ts → dist/Transaction/index.d.ts} +1 -0
  60. package/dist/Transaction/index.d.ts.map +1 -0
  61. package/dist/Transaction/index.js +18 -0
  62. package/dist/Transaction/index.js.map +1 -0
  63. package/dist/Transaction/types.d.ts +11 -0
  64. package/dist/Transaction/types.d.ts.map +1 -0
  65. package/dist/Transaction/types.js +3 -0
  66. package/dist/Transaction/types.js.map +1 -0
  67. package/dist/Transaction/withdrawal.d.ts +8 -0
  68. package/dist/Transaction/withdrawal.d.ts.map +1 -0
  69. package/dist/Transaction/withdrawal.js +10 -0
  70. package/dist/Transaction/withdrawal.js.map +1 -0
  71. package/dist/TransactionError.d.ts +15 -0
  72. package/dist/TransactionError.d.ts.map +1 -0
  73. package/dist/TransactionError.js +23 -0
  74. package/dist/TransactionError.js.map +1 -0
  75. package/{src/index.ts → dist/index.d.ts} +1 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +35 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/types.d.ts +37 -0
  80. package/dist/types.d.ts.map +1 -0
  81. package/dist/types.js +13 -0
  82. package/dist/types.js.map +1 -0
  83. package/package.json +13 -8
  84. package/jest.config.js +0 -1
  85. package/src/Address.ts +0 -12
  86. package/src/BalanceTracker.ts +0 -62
  87. package/src/InMemoryTransactionTracker.ts +0 -87
  88. package/src/InMemoryUtxoRepository.ts +0 -192
  89. package/src/KeyManagement/InMemoryKeyManager.ts +0 -67
  90. package/src/KeyManagement/errors/InvalidMnemonic.ts +0 -9
  91. package/src/KeyManagement/types.ts +0 -15
  92. package/src/KeyManagement/util.ts +0 -14
  93. package/src/SingleAddressWallet.ts +0 -120
  94. package/src/Transaction/CertificateFactory.ts +0 -154
  95. package/src/Transaction/computeImplicitCoin.ts +0 -36
  96. package/src/Transaction/createTransactionInternals.ts +0 -60
  97. package/src/Transaction/types.ts +0 -12
  98. package/src/Transaction/withdrawal.ts +0 -17
  99. package/src/TransactionError.ts +0 -17
  100. package/src/tsconfig.json +0 -11
  101. package/src/types.ts +0 -56
  102. package/test/.eslintrc.js +0 -7
  103. package/test/BalanceTracker.test.ts +0 -44
  104. package/test/InMemoryTransactionTracker.test.ts +0 -108
  105. package/test/InMemoryUtxoRepository.test.ts +0 -242
  106. package/test/KeyManagement/InMemoryKeyManager.test.ts +0 -39
  107. package/test/SingleAddressWallet.test.ts +0 -87
  108. package/test/Transaction/CertificateFactory.test.ts +0 -89
  109. package/test/Transaction/computeImplicitCoin.test.ts +0 -26
  110. package/test/Transaction/createTransactionInternals.test.ts +0 -84
  111. package/test/Transaction/withdrawal.test.ts +0 -13
  112. package/test/integration/withdrawal.test.ts +0 -108
  113. package/test/mocks/MockTransactionTracker.ts +0 -8
  114. package/test/mocks/MockUtxoRepository.ts +0 -13
  115. package/test/mocks/ProviderStub.ts +0 -151
  116. package/test/mocks/index.ts +0 -4
  117. package/test/mocks/testKeyManager.ts +0 -10
  118. package/test/tsconfig.json +0 -12
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTransactionInternals.js","sourceRoot":"","sources":["../../src/Transaction/createTransactionInternals.ts"],"names":[],"mappings":";;;AACA,4CAAiD;AAgB1C,MAAM,0BAA0B,GAAG,KAAK,EAAE,KAA6B,EAAwB,EAAE;IACtG,MAAM,MAAM,GAAG,UAAG,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC;IAC3C,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE;QAC9C,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;KAC1B;IACD,MAAM,OAAO,GAAG,UAAG,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC;IAC7C,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE;QACjD,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;KACrB;IACD,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE;QAC/C,OAAO,CAAC,GAAG,CAAC,UAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,UAAG,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;KAC7F;IACD,MAAM,IAAI,GAAG,UAAG,CAAC,eAAe,CAAC,GAAG,CAClC,MAAM,EACN,OAAO,EACP,KAAK,CAAC,cAAc,CAAC,GAAG,EACxB,KAAK,CAAC,gBAAgB,CAAC,gBAAgB,IAAI,SAAS,CACrD,CAAC;IACF,IAAI,KAAK,CAAC,gBAAgB,CAAC,aAAa,EAAE;QACxC,IAAI,CAAC,2BAA2B,CAAC,KAAK,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;KACxE;IACD,IAAI,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE;QAC9B,MAAM,KAAK,GAAG,UAAG,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;QACrC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,YAAY,EAAE;YACrC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;SACjB;QACD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;KACvB;IACD,IAAI,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE;QAC7B,MAAM,WAAW,GAAG,UAAG,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC;QAC1C,KAAK,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,KAAK,CAAC,WAAW,EAAE;YACrD,WAAW,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;SACvC;QACD,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;KACnC;IACD,OAAO;QACL,IAAI;QACJ,IAAI,EAAE,UAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC;AAvCW,QAAA,0BAA0B,8BAuCrC"}
@@ -3,3 +3,4 @@ export * from './withdrawal';
3
3
  export * from './computeImplicitCoin';
4
4
  export * from './createTransactionInternals';
5
5
  export * from './types';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Transaction/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,SAAS,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./CertificateFactory"), exports);
14
+ __exportStar(require("./withdrawal"), exports);
15
+ __exportStar(require("./computeImplicitCoin"), exports);
16
+ __exportStar(require("./createTransactionInternals"), exports);
17
+ __exportStar(require("./types"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Transaction/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAqC;AACrC,+CAA6B;AAC7B,wDAAsC;AACtC,+DAA6C;AAC7C,0CAAwB"}
@@ -0,0 +1,11 @@
1
+ import { CSL, Cardano } from '@cardano-sdk/core';
2
+ import { Withdrawal } from './withdrawal';
3
+ export declare type InitializeTxProps = {
4
+ outputs: Set<Cardano.TxOut>;
5
+ certificates?: CSL.Certificate[];
6
+ withdrawals?: Withdrawal[];
7
+ options?: {
8
+ validityInterval?: Cardano.ValidityInterval;
9
+ };
10
+ };
11
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/Transaction/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,oBAAY,iBAAiB,GAAG;IAC9B,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC5B,YAAY,CAAC,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC;IACjC,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,OAAO,CAAC,EAAE;QACR,gBAAgB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC;KAC7C,CAAC;CACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/Transaction/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { Cardano, CSL } from '@cardano-sdk/core';
2
+ import { KeyManager } from '../KeyManagement';
3
+ export declare type Withdrawal = {
4
+ address: CSL.RewardAddress;
5
+ quantity: CSL.BigNum;
6
+ };
7
+ export declare const withdrawal: (keyManager: KeyManager, quantity: Cardano.Lovelace, network?: number) => Withdrawal;
8
+ //# sourceMappingURL=withdrawal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../../src/Transaction/withdrawal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,oBAAY,UAAU,GAAG;IACvB,OAAO,EAAE,GAAG,CAAC,aAAa,CAAC;IAC3B,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,UAAU,eACT,UAAU,YACZ,QAAQ,QAAQ,YACjB,MAAM,KACd,UAGD,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withdrawal = void 0;
4
+ const core_1 = require("@cardano-sdk/core");
5
+ const withdrawal = (keyManager, quantity, network = core_1.Cardano.NetworkId.mainnet) => ({
6
+ address: core_1.CSL.RewardAddress.new(network, core_1.CSL.StakeCredential.from_keyhash(keyManager.stakeKey.hash())),
7
+ quantity: core_1.CSL.BigNum.from_str(quantity.toString())
8
+ });
9
+ exports.withdrawal = withdrawal;
10
+ //# sourceMappingURL=withdrawal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withdrawal.js","sourceRoot":"","sources":["../../src/Transaction/withdrawal.ts"],"names":[],"mappings":";;;AAAA,4CAAiD;AAQ1C,MAAM,UAAU,GAAG,CACxB,UAAsB,EACtB,QAA0B,EAC1B,UAAkB,cAAO,CAAC,SAAS,CAAC,OAAO,EAC/B,EAAE,CAAC,CAAC;IAChB,OAAO,EAAE,UAAG,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,UAAG,CAAC,eAAe,CAAC,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACrG,QAAQ,EAAE,UAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;CACnD,CAAC,CAAC;AAPU,QAAA,UAAU,cAOpB"}
@@ -0,0 +1,15 @@
1
+ import { CustomError } from 'ts-custom-error';
2
+ export declare enum TransactionFailure {
3
+ InvalidTransaction = "INVALID_TRANSACTION",
4
+ FailedToSubmit = "FAILED_TO_SUBMIT",
5
+ Unknown = "UNKNOWN",
6
+ CannotTrack = "CANNOT_TRACK",
7
+ Timeout = "TIMEOUT"
8
+ }
9
+ export declare class TransactionError extends CustomError {
10
+ reason: TransactionFailure;
11
+ innerError?: unknown;
12
+ detail?: string | undefined;
13
+ constructor(reason: TransactionFailure, innerError?: unknown, detail?: string | undefined);
14
+ }
15
+ //# sourceMappingURL=TransactionError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactionError.d.ts","sourceRoot":"","sources":["../src/TransactionError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,oBAAY,kBAAkB;IAC5B,kBAAkB,wBAAwB;IAC1C,cAAc,qBAAqB;IACnC,OAAO,YAAY;IACnB,WAAW,iBAAiB;IAC5B,OAAO,YAAY;CACpB;AAID,qBAAa,gBAAiB,SAAQ,WAAW;IAC5B,MAAM,EAAE,kBAAkB;IAAS,UAAU,CAAC;IAAkB,MAAM,CAAC;gBAAvE,MAAM,EAAE,kBAAkB,EAAS,UAAU,CAAC,SAAS,EAAS,MAAM,CAAC,oBAAQ;CAGnG"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionError = exports.TransactionFailure = void 0;
4
+ const ts_custom_error_1 = require("ts-custom-error");
5
+ var TransactionFailure;
6
+ (function (TransactionFailure) {
7
+ TransactionFailure["InvalidTransaction"] = "INVALID_TRANSACTION";
8
+ TransactionFailure["FailedToSubmit"] = "FAILED_TO_SUBMIT";
9
+ TransactionFailure["Unknown"] = "UNKNOWN";
10
+ TransactionFailure["CannotTrack"] = "CANNOT_TRACK";
11
+ TransactionFailure["Timeout"] = "TIMEOUT";
12
+ })(TransactionFailure = exports.TransactionFailure || (exports.TransactionFailure = {}));
13
+ const formatDetail = (detail) => (detail ? ` (${detail})` : '');
14
+ class TransactionError extends ts_custom_error_1.CustomError {
15
+ constructor(reason, innerError, detail) {
16
+ super(`Transaction failed: ${reason}${formatDetail(detail)}`);
17
+ this.reason = reason;
18
+ this.innerError = innerError;
19
+ this.detail = detail;
20
+ }
21
+ }
22
+ exports.TransactionError = TransactionError;
23
+ //# sourceMappingURL=TransactionError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactionError.js","sourceRoot":"","sources":["../src/TransactionError.ts"],"names":[],"mappings":";;;AAAA,qDAA8C;AAE9C,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,gEAA0C,CAAA;IAC1C,yDAAmC,CAAA;IACnC,yCAAmB,CAAA;IACnB,kDAA4B,CAAA;IAC5B,yCAAmB,CAAA;AACrB,CAAC,EANW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAM7B;AAED,MAAM,YAAY,GAAG,CAAC,MAAe,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAEzE,MAAa,gBAAiB,SAAQ,6BAAW;IAC/C,YAAmB,MAA0B,EAAS,UAAoB,EAAS,MAAe;QAChG,KAAK,CAAC,uBAAuB,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAD7C,WAAM,GAAN,MAAM,CAAoB;QAAS,eAAU,GAAV,UAAU,CAAU;QAAS,WAAM,GAAN,MAAM,CAAS;IAElG,CAAC;CACF;AAJD,4CAIC"}
@@ -7,3 +7,4 @@ export * from './SingleAddressWallet';
7
7
  export * from './types';
8
8
  export * from './TransactionError';
9
9
  export * from './BalanceTracker';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
22
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.KeyManagement = exports.Transaction = exports.Address = void 0;
26
+ exports.Address = __importStar(require("./Address"));
27
+ exports.Transaction = __importStar(require("./Transaction"));
28
+ __exportStar(require("./InMemoryUtxoRepository"), exports);
29
+ __exportStar(require("./InMemoryTransactionTracker"), exports);
30
+ exports.KeyManagement = __importStar(require("./KeyManagement"));
31
+ __exportStar(require("./SingleAddressWallet"), exports);
32
+ __exportStar(require("./types"), exports);
33
+ __exportStar(require("./TransactionError"), exports);
34
+ __exportStar(require("./BalanceTracker"), exports);
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAqC;AACrC,6DAA6C;AAC7C,2DAAyC;AACzC,+DAA6C;AAC7C,iEAAiD;AACjD,wDAAsC;AACtC,0CAAwB;AACxB,qDAAmC;AACnC,mDAAiC"}
@@ -0,0 +1,37 @@
1
+ import { SelectionConstraints, SelectionResult } from '@cardano-sdk/cip2';
2
+ import { Cardano, CSL } from '@cardano-sdk/core';
3
+ import Emittery from 'emittery';
4
+ export declare enum UtxoRepositoryEvent {
5
+ Changed = "changed",
6
+ OutOfSync = "out-of-sync"
7
+ }
8
+ export interface UtxoRepositoryFields {
9
+ allUtxos: Cardano.Utxo[];
10
+ availableUtxos: Cardano.Utxo[];
11
+ allRewards: Cardano.Lovelace | null;
12
+ availableRewards: Cardano.Lovelace | null;
13
+ delegation: Cardano.PoolId | null;
14
+ }
15
+ export declare type UtxoRepositoryEvents = {
16
+ changed: UtxoRepositoryFields;
17
+ 'out-of-sync': void;
18
+ 'transaction-untracked': CSL.Transaction;
19
+ };
20
+ export declare type UtxoRepository = {
21
+ sync: () => Promise<void>;
22
+ selectInputs: (outputs: Set<CSL.TransactionOutput>, constraints: SelectionConstraints, implicitCoin?: Cardano.ImplicitCoin) => Promise<SelectionResult>;
23
+ } & UtxoRepositoryFields & Emittery<UtxoRepositoryEvents>;
24
+ export interface OnTransactionArgs {
25
+ transaction: CSL.Transaction;
26
+ confirmed: Promise<void>;
27
+ }
28
+ export declare enum TransactionTrackerEvent {
29
+ NewTransaction = "new-transaction"
30
+ }
31
+ export declare type TransactionTrackerEvents = {
32
+ 'new-transaction': OnTransactionArgs;
33
+ };
34
+ export interface TransactionTracker extends Emittery<TransactionTrackerEvents> {
35
+ track(transaction: CSL.Transaction, submitted?: Promise<void>): Promise<void>;
36
+ }
37
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,oBAAY,mBAAmB;IAC7B,OAAO,YAAY;IACnB,SAAS,gBAAgB;CAC1B;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;IACzB,cAAc,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;IAC/B,UAAU,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IACpC,gBAAgB,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC1C,UAAU,EAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,oBAAY,oBAAoB,GAAG;IACjC,OAAO,EAAE,oBAAoB,CAAC;IAC9B,aAAa,EAAE,IAAI,CAAC;IACpB,uBAAuB,EAAE,GAAG,CAAC,WAAW,CAAC;CAC1C,CAAC;AACF,oBAAY,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,YAAY,EAAE,CACZ,OAAO,EAAE,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,EACnC,WAAW,EAAE,oBAAoB,EACjC,YAAY,CAAC,EAAE,OAAO,CAAC,YAAY,KAChC,OAAO,CAAC,eAAe,CAAC,CAAC;CAC/B,GAAG,oBAAoB,GACtB,QAAQ,CAAC,oBAAoB,CAAC,CAAC;AAEjC,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,GAAG,CAAC,WAAW,CAAC;IAK7B,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,oBAAY,uBAAuB;IACjC,cAAc,oBAAoB;CACnC;AAED,oBAAY,wBAAwB,GAAG;IAAE,iBAAiB,EAAE,iBAAiB,CAAA;CAAE,CAAC;AAChF,MAAM,WAAW,kBAAmB,SAAQ,QAAQ,CAAC,wBAAwB,CAAC;IAO5E,KAAK,CAAC,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/E"}
package/dist/types.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionTrackerEvent = exports.UtxoRepositoryEvent = void 0;
4
+ var UtxoRepositoryEvent;
5
+ (function (UtxoRepositoryEvent) {
6
+ UtxoRepositoryEvent["Changed"] = "changed";
7
+ UtxoRepositoryEvent["OutOfSync"] = "out-of-sync";
8
+ })(UtxoRepositoryEvent = exports.UtxoRepositoryEvent || (exports.UtxoRepositoryEvent = {}));
9
+ var TransactionTrackerEvent;
10
+ (function (TransactionTrackerEvent) {
11
+ TransactionTrackerEvent["NewTransaction"] = "new-transaction";
12
+ })(TransactionTrackerEvent = exports.TransactionTrackerEvent || (exports.TransactionTrackerEvent = {}));
13
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAIA,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC7B,0CAAmB,CAAA;IACnB,gDAAyB,CAAA;AAC3B,CAAC,EAHW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAG9B;AAkCD,IAAY,uBAEX;AAFD,WAAY,uBAAuB;IACjC,6DAAkC,CAAA;AACpC,CAAC,EAFW,uBAAuB,GAAvB,+BAAuB,KAAvB,+BAAuB,QAElC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cardano-sdk/wallet",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Wallet modules",
5
5
  "engines": {
6
6
  "node": "^14"
@@ -19,23 +19,28 @@
19
19
  "cleanup": "shx rm -rf dist node_modules",
20
20
  "coverage": "yarn test --coverage",
21
21
  "lint": "eslint --ignore-path ../../.eslintignore \"**/*.ts\"",
22
+ "prepack": "yarn build",
22
23
  "test": "jest -c ./jest.config.js",
23
24
  "test:debug": "DEBUG=true yarn test"
24
25
  },
25
26
  "devDependencies": {
26
- "@cardano-sdk/util-dev": "0.1.3",
27
+ "@cardano-sdk/util-dev": "0.1.5",
27
28
  "shx": "^0.3.3"
28
29
  },
29
30
  "dependencies": {
30
- "@cardano-ogmios/schema": "4.1.0",
31
- "@cardano-sdk/cip2": "0.1.4",
32
- "@cardano-sdk/core": "0.1.4",
33
- "buffer": "^6.0.3",
31
+ "@cardano-sdk/cip2": "0.1.5",
32
+ "@cardano-sdk/core": "0.1.5",
34
33
  "delay": "^5.0.0",
35
34
  "emittery": "^0.10.0",
36
- "isomorphic-bip39": "^3.0.5",
35
+ "bip39": "^3.0.4",
37
36
  "lodash-es": "^4.17.21",
38
37
  "ts-custom-error": "^3.2.0",
39
38
  "ts-log": "^2.2.3"
40
- }
39
+ },
40
+ "files": [
41
+ "dist/*",
42
+ "!dist/tsconfig.tsbuildinfo",
43
+ "LICENSE",
44
+ "NOTICE"
45
+ ]
41
46
  }
package/jest.config.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('../../test/jest.config');
package/src/Address.ts DELETED
@@ -1,12 +0,0 @@
1
- /** internal = change address & external = receipt address */
2
- export enum AddressType {
3
- internal = 'Internal',
4
- external = 'External'
5
- }
6
-
7
- export interface Address {
8
- address: string;
9
- index: number;
10
- type: AddressType;
11
- accountIndex: number;
12
- }
@@ -1,62 +0,0 @@
1
- import { Utxo } from '@cardano-ogmios/schema';
2
- import { Ogmios } from '@cardano-sdk/core';
3
- import Emittery from 'emittery';
4
- import { dummyLogger } from 'ts-log';
5
- import { UtxoRepository, UtxoRepositoryEvent, UtxoRepositoryFields } from './types';
6
-
7
- export interface Balance extends Ogmios.Value {
8
- rewards: Ogmios.Lovelace;
9
- }
10
-
11
- export interface Balances {
12
- total: Balance;
13
- available: Balance;
14
- }
15
-
16
- export enum BalanceTrackerEvent {
17
- Changed = 'changed'
18
- }
19
-
20
- export interface BalanceTrackerEvents {
21
- changed: Balances;
22
- }
23
-
24
- export class BalanceTracker extends Emittery<BalanceTrackerEvents> implements Balances {
25
- total!: Balance;
26
- available!: Balance;
27
-
28
- constructor(utxoRepository: UtxoRepository, logger = dummyLogger) {
29
- super();
30
- this.#updateBalances(utxoRepository);
31
- utxoRepository.on(UtxoRepositoryEvent.Changed, (fields) => {
32
- this.#updateBalances(fields);
33
- this.emit(BalanceTrackerEvent.Changed, {
34
- available: this.available,
35
- total: this.total
36
- }).catch(logger.error);
37
- });
38
- }
39
-
40
- #updateBalances(utxoRepository: UtxoRepositoryFields) {
41
- this.total = {
42
- ...this.#getBalance(utxoRepository.allUtxos),
43
- rewards: utxoRepository.allRewards || 0n
44
- };
45
- this.available = {
46
- ...this.#getBalance(utxoRepository.availableUtxos),
47
- rewards: utxoRepository.availableRewards || 0n
48
- };
49
- }
50
-
51
- #getBalance(utxo: Utxo): Ogmios.Value {
52
- return Ogmios.util.coalesceValueQuantities(
53
- utxo.map(([_, txOut]) => {
54
- const { coins, assets } = txOut.value;
55
- return {
56
- coins: BigInt(coins),
57
- assets
58
- };
59
- })
60
- );
61
- }
62
- }
@@ -1,87 +0,0 @@
1
- import { TransactionTracker, TransactionTrackerEvents } from './types';
2
- import Emittery from 'emittery';
3
- import { Hash16, Slot, Tip } from '@cardano-ogmios/schema';
4
- import { CardanoProvider, ProviderError, CardanoSerializationLib, CSL, ProviderFailure } from '@cardano-sdk/core';
5
- import { TransactionError, TransactionFailure } from './TransactionError';
6
- import { dummyLogger, Logger } from 'ts-log';
7
- import delay from 'delay';
8
- import { TransactionTrackerEvent } from '.';
9
-
10
- export type Milliseconds = number;
11
-
12
- export interface InMemoryTransactionTrackerProps {
13
- provider: CardanoProvider;
14
- csl: CardanoSerializationLib;
15
- logger?: Logger;
16
- pollInterval?: Milliseconds;
17
- }
18
-
19
- export class InMemoryTransactionTracker extends Emittery<TransactionTrackerEvents> implements TransactionTracker {
20
- readonly #provider: CardanoProvider;
21
- readonly #pendingTransactions = new Map<string, Promise<void>>();
22
- readonly #csl: CardanoSerializationLib;
23
- readonly #logger: Logger;
24
- readonly #pollInterval: number;
25
-
26
- constructor({ provider, csl, logger = dummyLogger, pollInterval = 2000 }: InMemoryTransactionTrackerProps) {
27
- super();
28
- this.#provider = provider;
29
- this.#csl = csl;
30
- this.#logger = logger;
31
- this.#pollInterval = pollInterval;
32
- }
33
-
34
- async track(transaction: CSL.Transaction, submitted: Promise<void> = Promise.resolve()): Promise<void> {
35
- await submitted;
36
- const body = transaction.body();
37
- const hash = Buffer.from(this.#csl.hash_transaction(body).to_bytes()).toString('hex');
38
- this.#logger.debug('InMemoryTransactionTracker.trackTransaction', hash);
39
-
40
- if (this.#pendingTransactions.has(hash)) {
41
- return this.#pendingTransactions.get(hash)!;
42
- }
43
-
44
- const invalidHereafter = body.ttl();
45
- if (!invalidHereafter) {
46
- throw new TransactionError(TransactionFailure.CannotTrack, undefined, 'no TTL');
47
- }
48
-
49
- const promise = this.#checkTransactionViaProvider(hash, invalidHereafter);
50
- this.#pendingTransactions.set(hash, promise);
51
- this.emit(TransactionTrackerEvent.NewTransaction, { transaction, confirmed: promise }).catch(this.#logger.error);
52
- void promise.catch(() => void 0).then(() => this.#pendingTransactions.delete(hash));
53
-
54
- return promise;
55
- }
56
-
57
- async #checkTransactionViaProvider(hash: Hash16, invalidHereafter: Slot): Promise<void> {
58
- await delay(this.#pollInterval);
59
- try {
60
- const tx = await this.#provider.queryTransactionsByHashes([hash]);
61
- if (tx.length > 0) return; // done
62
- return this.#onTransactionNotFound(hash, invalidHereafter);
63
- } catch (error: unknown) {
64
- if (error instanceof ProviderError && error.reason === ProviderFailure.NotFound) {
65
- return this.#onTransactionNotFound(hash, invalidHereafter);
66
- }
67
- throw new TransactionError(TransactionFailure.CannotTrack, error);
68
- }
69
- }
70
-
71
- async #onTransactionNotFound(hash: string, invalidHereafter: number) {
72
- let tip: Tip | undefined;
73
- try {
74
- tip = await this.#provider.ledgerTip();
75
- } catch (error: unknown) {
76
- throw new TransactionError(
77
- TransactionFailure.CannotTrack,
78
- error,
79
- "can't query tip to check for transaction timeout"
80
- );
81
- }
82
- if (tip && tip.slot > invalidHereafter) {
83
- throw new TransactionError(TransactionFailure.Timeout);
84
- }
85
- return this.#checkTransactionViaProvider(hash, invalidHereafter);
86
- }
87
- }
@@ -1,192 +0,0 @@
1
- import Schema, { TxIn, TxOut } from '@cardano-ogmios/schema';
2
- import { Buffer } from 'buffer';
3
- import { CardanoProvider, Ogmios, CardanoSerializationLib, CSL, cslUtil } from '@cardano-sdk/core';
4
- import { dummyLogger, Logger } from 'ts-log';
5
- import { ImplicitCoin, InputSelector, SelectionConstraints, SelectionResult } from '@cardano-sdk/cip2';
6
- import { KeyManager } from './KeyManagement';
7
- import {
8
- UtxoRepository,
9
- OnTransactionArgs,
10
- TransactionTracker,
11
- TransactionTrackerEvent,
12
- UtxoRepositoryEvent,
13
- UtxoRepositoryEvents
14
- } from './types';
15
- import { cslToOgmios } from '@cardano-sdk/core/src/Ogmios';
16
- import Emittery from 'emittery';
17
-
18
- export interface InMemoryUtxoRepositoryProps {
19
- csl: CardanoSerializationLib;
20
- provider: CardanoProvider;
21
- keyManager: KeyManager;
22
- inputSelector: InputSelector;
23
- txTracker: TransactionTracker;
24
- logger?: Logger;
25
- }
26
-
27
- const utxoEquals = ([txIn1]: [Schema.TxIn, Schema.TxOut], [txIn2]: [Schema.TxIn, Schema.TxOut]): boolean =>
28
- txIn1.txId === txIn2.txId && txIn1.index === txIn2.index;
29
-
30
- export class InMemoryUtxoRepository extends Emittery<UtxoRepositoryEvents> implements UtxoRepository {
31
- #csl: CardanoSerializationLib;
32
- #delegationAndRewards: Ogmios.DelegationsAndRewards;
33
- #inputSelector: InputSelector;
34
- #keyManager: KeyManager;
35
- #logger: Logger;
36
- #provider: CardanoProvider;
37
- #utxoSet: Set<[TxIn, TxOut]>;
38
- #lockedUtxoSet: Set<[TxIn, TxOut]> = new Set();
39
- #lockedRewards = 0n;
40
-
41
- constructor({
42
- csl,
43
- logger = dummyLogger,
44
- provider,
45
- inputSelector,
46
- keyManager,
47
- txTracker
48
- }: InMemoryUtxoRepositoryProps) {
49
- super();
50
- this.#csl = csl;
51
- this.#logger = logger;
52
- this.#provider = provider;
53
- this.#utxoSet = new Set();
54
- this.#delegationAndRewards = { rewards: undefined, delegate: undefined };
55
- this.#inputSelector = inputSelector;
56
- this.#keyManager = keyManager;
57
- txTracker.on(TransactionTrackerEvent.NewTransaction, (args) => {
58
- // not blocking to make it testable easier
59
- this.#onTransaction(args).catch(this.#logger.error);
60
- });
61
- }
62
-
63
- public async sync(): Promise<void> {
64
- this.#logger.debug('Syncing InMemoryUtxoRepository');
65
- const result = await this.#provider.utxoDelegationAndRewards(
66
- [this.#keyManager.deriveAddress(1, 0)],
67
- Buffer.from(this.#keyManager.stakeKey.hash().to_bytes()).toString('hex')
68
- );
69
- this.#logger.trace(result);
70
- for (const utxo of result.utxo) {
71
- if (!this.allUtxos.some((oldUtxo) => utxoEquals(utxo, oldUtxo))) {
72
- this.#utxoSet.add(utxo);
73
- this.#logger.debug('New UTxO', utxo);
74
- }
75
- }
76
- for (const utxo of this.#utxoSet) {
77
- if (!result.utxo.some((newUtxo) => utxoEquals(utxo, newUtxo))) {
78
- this.#utxoSet.delete(utxo);
79
- this.#logger.debug('UTxO is gone', utxo);
80
- }
81
- }
82
- if (this.#delegationAndRewards.delegate !== result.delegationAndRewards.delegate) {
83
- this.#delegationAndRewards.delegate = result.delegationAndRewards.delegate;
84
- this.#logger.debug('Delegation stored', result.delegationAndRewards.delegate);
85
- }
86
- if (this.#delegationAndRewards.rewards !== result.delegationAndRewards.rewards) {
87
- this.#delegationAndRewards.rewards = result.delegationAndRewards.rewards
88
- ? BigInt(result.delegationAndRewards.rewards)
89
- : undefined;
90
- this.#logger.debug('Rewards balance stored', result.delegationAndRewards.rewards);
91
- }
92
- this.#emitSynced();
93
- }
94
-
95
- public async selectInputs(
96
- outputs: Set<CSL.TransactionOutput>,
97
- constraints: SelectionConstraints,
98
- implicitCoin?: ImplicitCoin
99
- ): Promise<SelectionResult> {
100
- if (this.#utxoSet.size === 0) {
101
- this.#logger.debug('Local UTxO set is empty. Syncing...');
102
- await this.sync();
103
- }
104
- return this.#inputSelector.select({
105
- utxo: new Set(Ogmios.ogmiosToCsl(this.#csl).utxo(this.availableUtxos)),
106
- outputs,
107
- constraints,
108
- implicitCoin
109
- });
110
- }
111
-
112
- public get allUtxos(): Schema.Utxo {
113
- return [...this.#utxoSet.values()];
114
- }
115
-
116
- public get availableUtxos(): Schema.Utxo {
117
- return this.allUtxos.filter((utxo) => !this.#lockedUtxoSet.has(utxo));
118
- }
119
-
120
- public get allRewards(): Ogmios.Lovelace | null {
121
- return this.#delegationAndRewards.rewards ?? null;
122
- }
123
-
124
- public get availableRewards(): Ogmios.Lovelace | null {
125
- if (!this.allRewards) return null;
126
- return this.allRewards - this.#lockedRewards;
127
- }
128
-
129
- public get delegation(): Schema.PoolId | null {
130
- return this.#delegationAndRewards.delegate ?? null;
131
- }
132
-
133
- #emitSynced() {
134
- this.emit(UtxoRepositoryEvent.Changed, {
135
- allUtxos: this.allUtxos,
136
- availableUtxos: this.availableUtxos,
137
- allRewards: this.allRewards,
138
- availableRewards: this.availableRewards,
139
- delegation: this.delegation
140
- }).catch(this.#logger.error);
141
- }
142
-
143
- async #onTransaction({ transaction, confirmed }: OnTransactionArgs) {
144
- // Lock reward
145
- const rewardsLockedByTx = this.#getOwnTransactionWithdrawalQty(transaction);
146
- this.#lockedRewards += rewardsLockedByTx;
147
- // Lock utxo
148
- const utxoLockedByTx: Schema.Utxo = [];
149
- const inputs = transaction.body().inputs();
150
- for (let inputIdx = 0; inputIdx < inputs.len(); inputIdx++) {
151
- const { txId, index } = cslToOgmios.txIn(inputs.get(inputIdx));
152
- const utxo = this.allUtxos.find(([txIn]) => txIn.txId === txId && txIn.index === index)!;
153
- this.#lockedUtxoSet.add(utxo);
154
- utxoLockedByTx.push(utxo);
155
- }
156
- this.#emitSynced();
157
- // Await confirmation. Rejection should be handled by the user after submitting transaction.
158
- await confirmed.catch(() => void 0);
159
- // Unlock utxo
160
- for (const utxo of utxoLockedByTx) {
161
- this.#lockedUtxoSet.delete(utxo);
162
- }
163
- // Unlock rewards
164
- this.#lockedRewards -= rewardsLockedByTx;
165
- // Sync utxo and rewards with the provider
166
- await this.#trySync();
167
- }
168
-
169
- async #trySync() {
170
- try {
171
- await this.sync();
172
- } catch (error) {
173
- this.#logger.debug('InMemoryUtxoRepository.#trySync failed:', error);
174
- this.emit(UtxoRepositoryEvent.OutOfSync, void 0).catch(this.#logger.error);
175
- }
176
- }
177
-
178
- #getOwnTransactionWithdrawalQty(transaction: CSL.Transaction) {
179
- const withdrawals = transaction.body().withdrawals();
180
- if (!withdrawals) return 0n;
181
- const ownStakeCredential = this.#csl.StakeCredential.from_keyhash(this.#keyManager.stakeKey.hash());
182
- const withdrawalKeys = withdrawals.keys();
183
- let withdrawalTotal = 0n;
184
- for (let withdrawalKeyIdx = 0; withdrawalKeyIdx < withdrawalKeys.len(); withdrawalKeyIdx++) {
185
- const rewardAddress = withdrawalKeys.get(withdrawalKeyIdx);
186
- if (cslUtil.bytewiseEquals(rewardAddress.payment_cred(), ownStakeCredential)) {
187
- withdrawalTotal += BigInt(withdrawals.get(rewardAddress)!.to_str());
188
- }
189
- }
190
- return withdrawalTotal;
191
- }
192
- }