diff --git a/package-lock.json b/package-lock.json index 5d2630b..ed8f99c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "stellar-plus", - "version": "0.10.2", + "version": "0.12.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "stellar-plus", - "version": "0.10.2", + "version": "0.12.0", "license": "ISC", "dependencies": { "@hyperledger/cactus-test-tooling": "^2.0.0-rc.2", @@ -5126,13 +5126,6 @@ } } }, - "node_modules/engine.io-parser": { - "version": "5.0.7", - "license": "MIT", - "engines": { - "node": ">=10.0.0" - } - }, "node_modules/enhanced-resolve": { "version": "5.17.1", "dev": true, @@ -14439,25 +14432,6 @@ "dev": true, "license": "ISC" }, - "node_modules/ws": { - "version": "8.11.0", - "license": "MIT", - "engines": { - "node": ">=10.0.0" - }, - "peerDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" - }, - "peerDependenciesMeta": { - "bufferutil": { - "optional": true - }, - "utf-8-validate": { - "optional": true - } - } - }, "node_modules/xhr": { "version": "2.6.0", "license": "MIT", diff --git a/package.json b/package.json index 642447d..e836db8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stellar-plus", - "version": "0.11.0", + "version": "0.12.0", "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/asset/classic/index.ts b/src/stellar-plus/asset/classic/index.ts index c70ff55..0673f6b 100644 --- a/src/stellar-plus/asset/classic/index.ts +++ b/src/stellar-plus/asset/classic/index.ts @@ -1,8 +1,18 @@ -import { Horizon as HorizonNamespace, Operation, Asset as StellarAsset } from '@stellar/stellar-sdk' +import { + AuthClawbackEnabledFlag, + AuthFlag, + AuthImmutableFlag, + AuthRequiredFlag, + AuthRevocableFlag, + Horizon as HorizonNamespace, + Operation, + Asset as StellarAsset, +} from '@stellar/stellar-sdk' import { AccountHandler } from 'stellar-plus/account/account-handler/types' import { ClassicAssetHandlerConstructorArgs, + ControlFlags, ClassicAssetHandler as IClassicAssetHandler, } from 'stellar-plus/asset/classic/types' import { AssetTypes } from 'stellar-plus/asset/types' @@ -242,6 +252,40 @@ export class ClassicAssetHandler implements IClassicAssetHandler { return result.response } + public async setFlags( + args: { + controlFlags: ControlFlags + } & TransactionInvocation + ): Promise { + this.requireIssuerAccount() // Enforces the issuer account to be set. + + const { controlFlags } = args + + const txInvocation = args as TransactionInvocation + const updatedTxInvocation = { + ...txInvocation, + signers: [...txInvocation.signers, this.issuerAccount!], // Adds the issuer account as a signer. Issue account initialization is already verified by requireIssuerAccount(). + } + + let flags = 0 + if (controlFlags.authorizationRequired) flags |= AuthRequiredFlag + if (controlFlags.authorizationRevocable) flags |= AuthRevocableFlag + if (controlFlags.authorizationImmutable) flags |= AuthImmutableFlag + if (controlFlags.clawbackEnabled) flags |= AuthClawbackEnabledFlag + + const setFlags = Operation.setOptions({ + setFlags: flags as AuthFlag, + source: this.asset.getIssuer(), + }) + + const result = (await this.classicTransactionPipeline.execute({ + txInvocation: updatedTxInvocation, + operations: [setFlags], + })) as ClassicTransactionPipelineOutputSimple + + return result.response + } + public async clawback(): Promise { throw new Error('Method not implemented.') } diff --git a/src/stellar-plus/asset/classic/types.ts b/src/stellar-plus/asset/classic/types.ts index 8b9f4de..1eb7487 100644 --- a/src/stellar-plus/asset/classic/types.ts +++ b/src/stellar-plus/asset/classic/types.ts @@ -33,6 +33,10 @@ export type ClassicTokenInterfaceManagement = { amount: number } & TransactionInvocation ) => Promise + + setFlags: ( + args: { controlFlags: ControlFlags } & TransactionInvocation + ) => Promise } export type ClassicTokenInterfaceUser = { @@ -49,3 +53,10 @@ export type ClassicUtils = { args: { to: string; amount: number } & TransactionInvocation ) => Promise } + +export type ControlFlags = { + authorizationRequired?: boolean + authorizationRevocable?: boolean + clawbackEnabled?: boolean + authorizationImmutable?: boolean +}