diff --git a/package-lock.json b/package-lock.json index 5fa8a3f..32d1880 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "stellar-plus", - "version": "0.7.0", + "version": "0.8.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "stellar-plus", - "version": "0.7.0", + "version": "0.8.1", "license": "ISC", "dependencies": { "@stellar/freighter-api": "^1.7.1", @@ -2151,39 +2151,37 @@ "integrity": "sha512-XvPO+XgEbkeP0VhP0U1edOkds+rGS28+y8GRGbCVXeZ9ZslbWqRFQoETAdX8IXGuykk2ib/aPokiLc5ZaWYP7w==" }, "node_modules/@stellar/js-xdr": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@stellar/js-xdr/-/js-xdr-3.1.0.tgz", - "integrity": "sha512-mYTyFnhgyQgyvpAYZRO1LurUn2MxcIZRj74zZz/BxKEk7zrL4axhQ1ez0HL2BRi0wlG6cHn5BeD/t9Xcyp7CSQ==" + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@stellar/js-xdr/-/js-xdr-3.1.1.tgz", + "integrity": "sha512-3gnPjAz78htgqsNEDkEsKHKosV2BF2iZkoHCNxpmZwUxiPsw+2VaXMed8RRMe0rGk3d5GZe7RrSba8zV80J3Ag==" }, "node_modules/@stellar/stellar-base": { - "version": "11.0.0", - "resolved": "https://registry.npmjs.org/@stellar/stellar-base/-/stellar-base-11.0.0.tgz", - "integrity": "sha512-KPTjaWJCG2m7hMCPRWFGGPaG5qOkgPLWvFVOhe1HUy7dlE4MxxPfdusz0mcLkf6VT7doqhLB1rIt0D9M2GgQcQ==", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/@stellar/stellar-base/-/stellar-base-11.1.0.tgz", + "integrity": "sha512-nMg7QSpFqCZFq3Je/lG12+DY18y01QHRNyCxvjM8i4myS9tPRMDq7zqGcd215BGbCJxenckiOW45YJjQjzdcMQ==", "dependencies": { - "@stellar/js-xdr": "^3.1.0", + "@stellar/js-xdr": "^3.1.1", "base32.js": "^0.1.0", "bignumber.js": "^9.1.2", "buffer": "^6.0.3", "sha.js": "^2.3.6", - "tweetnacl": "^1.0.3", - "typescript": "^5.3.3" + "tweetnacl": "^1.0.3" }, "optionalDependencies": { - "sodium-native": "^4.0.8" + "sodium-native": "^4.1.1" } }, "node_modules/@stellar/stellar-sdk": { - "version": "11.2.2", - "resolved": "https://registry.npmjs.org/@stellar/stellar-sdk/-/stellar-sdk-11.2.2.tgz", - "integrity": "sha512-50dpxpZE2e87LjIln1EZnBh7r+JFWwyGs+NiGPOZ+LzJd2YRf54+YxzDX6ELVOrUqp2TRTLnzthXXTNFeVobFw==", + "version": "11.3.0", + "resolved": "https://registry.npmjs.org/@stellar/stellar-sdk/-/stellar-sdk-11.3.0.tgz", + "integrity": "sha512-i+heopibJNRA7iM8rEPz0AXphBPYvy2HDo8rxbDwWpozwCfw8kglP9cLkkhgJe8YicgLrdExz/iQZaLpqLC+6w==", "dependencies": { - "@stellar/stellar-base": "^11.0.0", - "axios": "^1.6.7", + "@stellar/stellar-base": "^11.0.1", + "axios": "^1.6.8", "bignumber.js": "^9.1.2", "eventsource": "^2.0.2", "randombytes": "^2.1.0", "toml": "^3.0.0", - "typescript": "^5.3.3", "urijs": "^1.19.1" } }, @@ -2828,11 +2826,11 @@ } }, "node_modules/axios": { - "version": "1.6.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.7.tgz", - "integrity": "sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==", + "version": "1.6.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", + "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", "dependencies": { - "follow-redirects": "^1.15.4", + "follow-redirects": "^1.15.6", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -8457,13 +8455,13 @@ } }, "node_modules/sodium-native": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-4.0.8.tgz", - "integrity": "sha512-2MOwB92RlCF0Y+teiTOgRMaKvcgXbXvwmSlyHaY5Gy8d4W3Bm++9cMv+hB/gf8INdMUxo69DbmGcvJ7HzLSL9w==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-4.1.1.tgz", + "integrity": "sha512-LXkAfRd4FHtkQS4X6g+nRcVaN7mWVNepV06phIsC6+IZFvGh1voW5TNQiQp2twVaMf05gZqQjuS+uWLM6gHhNQ==", "hasInstallScript": true, "optional": true, "dependencies": { - "node-gyp-build": "^4.6.0" + "node-gyp-build": "^4.8.0" } }, "node_modules/source-map": { @@ -9082,6 +9080,7 @@ "version": "5.3.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -10932,37 +10931,35 @@ "integrity": "sha512-XvPO+XgEbkeP0VhP0U1edOkds+rGS28+y8GRGbCVXeZ9ZslbWqRFQoETAdX8IXGuykk2ib/aPokiLc5ZaWYP7w==" }, "@stellar/js-xdr": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@stellar/js-xdr/-/js-xdr-3.1.0.tgz", - "integrity": "sha512-mYTyFnhgyQgyvpAYZRO1LurUn2MxcIZRj74zZz/BxKEk7zrL4axhQ1ez0HL2BRi0wlG6cHn5BeD/t9Xcyp7CSQ==" + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@stellar/js-xdr/-/js-xdr-3.1.1.tgz", + "integrity": "sha512-3gnPjAz78htgqsNEDkEsKHKosV2BF2iZkoHCNxpmZwUxiPsw+2VaXMed8RRMe0rGk3d5GZe7RrSba8zV80J3Ag==" }, "@stellar/stellar-base": { - "version": "11.0.0", - "resolved": "https://registry.npmjs.org/@stellar/stellar-base/-/stellar-base-11.0.0.tgz", - "integrity": "sha512-KPTjaWJCG2m7hMCPRWFGGPaG5qOkgPLWvFVOhe1HUy7dlE4MxxPfdusz0mcLkf6VT7doqhLB1rIt0D9M2GgQcQ==", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/@stellar/stellar-base/-/stellar-base-11.1.0.tgz", + "integrity": "sha512-nMg7QSpFqCZFq3Je/lG12+DY18y01QHRNyCxvjM8i4myS9tPRMDq7zqGcd215BGbCJxenckiOW45YJjQjzdcMQ==", "requires": { - "@stellar/js-xdr": "^3.1.0", + "@stellar/js-xdr": "^3.1.1", "base32.js": "^0.1.0", "bignumber.js": "^9.1.2", "buffer": "^6.0.3", "sha.js": "^2.3.6", - "sodium-native": "^4.0.8", - "tweetnacl": "^1.0.3", - "typescript": "^5.3.3" + "sodium-native": "^4.1.1", + "tweetnacl": "^1.0.3" } }, "@stellar/stellar-sdk": { - "version": "11.2.2", - "resolved": "https://registry.npmjs.org/@stellar/stellar-sdk/-/stellar-sdk-11.2.2.tgz", - "integrity": "sha512-50dpxpZE2e87LjIln1EZnBh7r+JFWwyGs+NiGPOZ+LzJd2YRf54+YxzDX6ELVOrUqp2TRTLnzthXXTNFeVobFw==", + "version": "11.3.0", + "resolved": "https://registry.npmjs.org/@stellar/stellar-sdk/-/stellar-sdk-11.3.0.tgz", + "integrity": "sha512-i+heopibJNRA7iM8rEPz0AXphBPYvy2HDo8rxbDwWpozwCfw8kglP9cLkkhgJe8YicgLrdExz/iQZaLpqLC+6w==", "requires": { - "@stellar/stellar-base": "^11.0.0", - "axios": "^1.6.7", + "@stellar/stellar-base": "^11.0.1", + "axios": "^1.6.8", "bignumber.js": "^9.1.2", "eventsource": "^2.0.2", "randombytes": "^2.1.0", "toml": "^3.0.0", - "typescript": "^5.3.3", "urijs": "^1.19.1" } }, @@ -11439,11 +11436,11 @@ "dev": true }, "axios": { - "version": "1.6.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.7.tgz", - "integrity": "sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==", + "version": "1.6.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", + "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", "requires": { - "follow-redirects": "^1.15.4", + "follow-redirects": "^1.15.6", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -15359,12 +15356,12 @@ } }, "sodium-native": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-4.0.8.tgz", - "integrity": "sha512-2MOwB92RlCF0Y+teiTOgRMaKvcgXbXvwmSlyHaY5Gy8d4W3Bm++9cMv+hB/gf8INdMUxo69DbmGcvJ7HzLSL9w==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-4.1.1.tgz", + "integrity": "sha512-LXkAfRd4FHtkQS4X6g+nRcVaN7mWVNepV06phIsC6+IZFvGh1voW5TNQiQp2twVaMf05gZqQjuS+uWLM6gHhNQ==", "optional": true, "requires": { - "node-gyp-build": "^4.6.0" + "node-gyp-build": "^4.8.0" } }, "source-map": { @@ -15800,7 +15797,8 @@ "typescript": { "version": "5.3.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", - "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==" + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "dev": true }, "unbox-primitive": { "version": "1.0.2", diff --git a/package.json b/package.json index 31dcd14..2307e6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stellar-plus", - "version": "0.8.0", + "version": "0.8.1", "description": "beta version of stellar-plus, an all-in-one sdk for the Stellar blockchain", "main": "./lib/index.js", "types": "./lib/index.d.ts", diff --git a/src/stellar-plus/account/account-handler/default/index.ts b/src/stellar-plus/account/account-handler/default/index.ts index 4bc4666..0d49b7b 100644 --- a/src/stellar-plus/account/account-handler/default/index.ts +++ b/src/stellar-plus/account/account-handler/default/index.ts @@ -5,6 +5,12 @@ import { DefaultAccountHandler, DefaultAccountHandlerPayload } from 'stellar-plu import { AccountBase } from 'stellar-plus/account/base' import { TransactionXdr } from 'stellar-plus/types' +/** + * @class DefaultAccountHandlerClient + * @extends AccountBase + * @implements DefaultAccountHandler + * @description - The default account handler is used for handling and creating new accounts by directly manipulating the secret key. Avoid using this handler in production environments. + */ export class DefaultAccountHandlerClient extends AccountBase implements DefaultAccountHandler { protected secretKey: string @@ -41,6 +47,15 @@ export class DefaultAccountHandlerClient extends AccountBase implements DefaultA } } + /** + * @description - Returns the secret key of the account. + * + * @returns {string} The secret key of the account. + */ + public getSecretKey(): string { + return this.secretKey + } + /** * * @param {Transaction} tx - The transaction to sign. diff --git a/src/stellar-plus/account/account-handler/default/index.unit.test.ts b/src/stellar-plus/account/account-handler/default/index.unit.test.ts index 3272f70..8f01031 100644 --- a/src/stellar-plus/account/account-handler/default/index.unit.test.ts +++ b/src/stellar-plus/account/account-handler/default/index.unit.test.ts @@ -48,6 +48,9 @@ describe('DefaultAccountHandler', () => { expect(dah.getPublicKey()).toBe(Keypair.fromSecret(secretKey).publicKey()) }) + }) + + describe('Core features', () => { it('should sign a transaction with its secret key', () => { const keypair = Keypair.random() @@ -102,6 +105,22 @@ describe('DefaultAccountHandler', () => { }) }) + describe('Getters', () => { + it('should return the public key of the account', () => { + const keypair = Keypair.random() + const dah = new DefaultAccountHandlerClient({ networkConfig: TESTNET_CONFIG, secretKey: keypair.secret() }) + + expect(dah.getPublicKey()).toBe(keypair.publicKey()) + }) + + it('should return the secret key of the account', () => { + const keypair = Keypair.random() + const dah = new DefaultAccountHandlerClient({ networkConfig: TESTNET_CONFIG, secretKey: keypair.secret() }) + + expect(dah.getSecretKey()).toBe(keypair.secret()) + }) + }) + describe('Error Handling', () => { beforeEach(() => { jest.clearAllMocks() diff --git a/src/stellar-plus/account/account-handler/default/types.ts b/src/stellar-plus/account/account-handler/default/types.ts index d3a5853..f5676c8 100644 --- a/src/stellar-plus/account/account-handler/default/types.ts +++ b/src/stellar-plus/account/account-handler/default/types.ts @@ -5,6 +5,7 @@ import { TransactionXdr } from 'stellar-plus/types' export type DefaultAccountHandler = AccountHandler & { sign(tx: Transaction): TransactionXdr + getSecretKey(): string } //