Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature. DASH-628 Auth permission param in sign/push transaction #150

Merged
merged 4 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ This is the expected Private Key:
This is the expected Public Key:
"FIO5kJKNHwctcfUM5XZyiWSqSTM5HTzznJP9F3ZdbhaQAHEVq575o"

## Version 1.9.0
### Breaking changes:
- Set new parameter `authPermission` for sign and push transactions
- `pushTransaction` receives object params instead of multiple arguments

## Version 1.0.2
Bug Fix to method: addPublicAddresses - TechnologyProviderId (i.e. TPID), was not being set correctly for this method.

Expand Down
22 changes: 20 additions & 2 deletions documentation/classes/fiosdk.html
Original file line number Diff line number Diff line change
Expand Up @@ -1063,13 +1063,13 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</
<a name="pushtransaction" class="tsd-anchor"></a>
<h3>push<wbr>Transaction</h3>
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class">
<li class="tsd-signature tsd-kind-icon">push<wbr>Transaction<span class="tsd-signature-symbol">(</span>account<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, action<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, data<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">&gt;</span></li>
<li class="tsd-signature tsd-kind-icon">push<wbr>Transaction<span class="tsd-signature-symbol">({</span>account<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, action<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, authPermission<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string | undefined</span>, data<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span>, encryptOptions<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">EncryptOptions</span><span class="tsd-signature-symbol">, signingAccount<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string | undefined</span>})</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">&gt;</span></li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/fioprotocol/fiosdk_typescript/blob/650dec4/src/FIOSDK.ts#L828">FIOSDK.ts:828</a></li>
<li>Defined in <a href="https://github.com/fioprotocol/fiosdk_typescript/blob/6acaa206ed8d0ccd402665088d142ef6b92f60fd/src/FIOSDK.ts#L1393">FIOSDK.ts:L1393</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -1091,12 +1091,30 @@ <h5>action: <span class="tsd-signature-type">string</span></h5>
<p>Name of action</p>
</div>
</li>
<li>
<h5>authPermission: <span class="tsd-signature-type">string | undefined</span></h5>
<div class="tsd-comment tsd-typography">
<p>Auth permision parameter</p>
</div>
</li>
<li>
<h5>data: <span class="tsd-signature-type">any</span></h5>
<div class="tsd-comment tsd-typography">
<p>JSON object with params for action</p>
</div>
</li>
<li>
<h5>encryptOptions: <span class="tsd-signature-type">EncryptOptions</span></h5>
<div class="tsd-comment tsd-typography">
<p>Parameters for encryption</p>
</div>
</li>
<li>
<h5>signingAccount: <span class="tsd-signature-type">string | undefined</span></h5>
<div class="tsd-comment tsd-typography">
<p>Sign transaction account</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">&gt;</span></h4>
</li>
Expand Down
48 changes: 35 additions & 13 deletions lib/FIOSDK.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,11 +949,15 @@ class FIOSDK {
const { fee: stakeFee } = yield this.getFee(EndPoint_1.EndPoint.stakeFioTokens, fioAddress);
fee = stakeFee;
}
return this.pushTransaction('fio.staking', 'stakefio', {
amount,
fio_address: fioAddress,
max_fee: fee,
tpid: technologyProviderId,
return this.pushTransaction({
account: 'fio.staking',
action: 'stakefio',
data: {
amount,
fio_address: fioAddress,
max_fee: fee,
tpid: technologyProviderId,
},
});
});
}
Expand All @@ -971,11 +975,15 @@ class FIOSDK {
const { fee: stakeFee } = yield this.getFee(EndPoint_1.EndPoint.unStakeFioTokens, fioAddress);
fee = stakeFee;
}
return this.pushTransaction('fio.staking', 'unstakefio', {
amount,
fio_address: fioAddress,
max_fee: fee,
tpid: technologyProviderId,
return this.pushTransaction({
account: 'fio.staking',
action: 'unstakefio',
data: {
amount,
fio_address: fioAddress,
max_fee: fee,
tpid: technologyProviderId,
},
});
});
}
Expand All @@ -993,7 +1001,7 @@ class FIOSDK {
* @param data JSON object with params for action
* @param encryptOptions JSON object with params for encryption
*/
pushTransaction(account, action, data, encryptOptions = {}) {
pushTransaction({ account, action, data, authPermission, encryptOptions = {}, signingAccount, }) {
return __awaiter(this, void 0, void 0, function* () {
data.tpid = this.getTechnologyProviderId(data.tpid);
if (data.content && !encryptOptions.key) {
Expand All @@ -1014,7 +1022,14 @@ class FIOSDK {
//
}
}
const pushTransaction = new SignedTransactions.PushTransaction(action, account, data, encryptOptions);
const pushTransaction = new SignedTransactions.PushTransaction({
action,
account,
authPermission,
data,
encryptOptions,
signingAccount,
});
return pushTransaction.execute(this.privateKey, this.publicKey, this.returnPreparedTrx);
});
}
Expand Down Expand Up @@ -1161,7 +1176,14 @@ class FIOSDK {
case 'getMultiplier':
return this.getMultiplier();
case 'pushTransaction':
return this.pushTransaction(params.account, params.action, params.data, params.encryptOptions);
return this.pushTransaction({
account: params.account,
action: params.action,
data: params.data,
authPermission: params.authPermission,
encryptOptions: params.encryptOptions,
signingAccount: params.signingAccount,
});
case 'getAccountPubKey':
return this.getAccountPubKey(params.account);
case 'getEncryptKey':
Expand Down
5 changes: 3 additions & 2 deletions lib/transactions/Transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class Transactions {
textEncoder,
});
}
createRawTransaction({ account, action, data, publicKey, chainData }) {
createRawTransaction({ account, action, authPermission, data, publicKey, chainData, signingAccount }) {
return __awaiter(this, void 0, void 0, function* () {
const rawTransaction = new RawTransaction_1.RawTransaction();
const rawaction = new RawAction_1.RawAction();
Expand All @@ -178,10 +178,11 @@ class Transactions {
if (!data.actor) {
data.actor = actor;
}
rawaction.authorization.push(new Autorization_1.Autorization(data.actor, data.permission));
rawaction.authorization.push(new Autorization_1.Autorization(data.actor, authPermission));
rawaction.account = account;
rawaction.name = action;
rawaction.data = data;
rawaction.actor = signingAccount;
rawTransaction.actions.push(rawaction);
if (chainData && chainData.ref_block_num) {
this.setRawTransactionExp(rawTransaction, chainData);
Expand Down
6 changes: 4 additions & 2 deletions lib/transactions/signed/PushTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports.PushTransaction = void 0;
const constants_1 = require("../../utils/constants");
const SignedTransaction_1 = require("./SignedTransaction");
class PushTransaction extends SignedTransaction_1.SignedTransaction {
constructor(action, account, data, encryptOptions = {}) {
constructor({ action, account, authPermission, data, encryptOptions = {}, signingAccount, }) {
super();
this.ENDPOINT = 'chain/push_transaction';
this.ACTION = '';
Expand All @@ -15,13 +15,15 @@ class PushTransaction extends SignedTransaction_1.SignedTransaction {
}
this.data = data;
this.encryptOptions = encryptOptions;
this.authPermission = authPermission;
this.signingAccount = signingAccount;
}
getData() {
const data = Object.assign({}, this.data);
if (data.content && this.encryptOptions && this.encryptOptions.key && this.encryptOptions.contentType) {
data.content = this.getCipherContent(this.encryptOptions.contentType, data.content, this.privateKey, this.encryptOptions.key);
}
return Object.assign(Object.assign({}, data), { actor: this.data.actor != null && this.data.actor !== '' ? this.data.actor : this.getActor(), permission: this.data.permission || 'active' });
return Object.assign(Object.assign({}, data), { actor: this.data.actor != null && this.data.actor !== '' ? this.data.actor : this.getActor() });
}
}
exports.PushTransaction = PushTransaction;
8 changes: 8 additions & 0 deletions lib/transactions/signed/SignedTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class SignedTransaction extends Transactions_1.Transactions {
const rawTransaction = yield this.createRawTransaction({
account: this.getAccount(),
action: this.getAction(),
authPermission: this.getAuthPermission(),
data: this.getData(),
signingAccount: this.getSigningAccount(),
});
const result = yield this.pushToServer(rawTransaction, this.getEndPoint(), dryRun);
return this.prepareResponse(result);
Expand All @@ -53,6 +55,12 @@ class SignedTransaction extends Transactions_1.Transactions {
getAccount() {
return this.ACCOUNT;
}
getAuthPermission() {
return this.authPermission;
}
getSigningAccount() {
return this.signingAccount;
}
getEndPoint() {
return this.ENDPOINT;
}
Expand Down
50 changes: 34 additions & 16 deletions src/FIOSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1403,16 +1403,16 @@ export class FIOSDK {
const { fee: stakeFee } = await this.getFee(EndPoint.stakeFioTokens, fioAddress)
fee = stakeFee
}
return this.pushTransaction(
'fio.staking',
'stakefio',
{
return this.pushTransaction({
account: 'fio.staking',
action: 'stakefio',
data: {
amount,
fio_address: fioAddress,
max_fee: fee,
tpid: technologyProviderId,
},
)
})
}

/**
Expand All @@ -1433,16 +1433,16 @@ export class FIOSDK {
const { fee: stakeFee } = await this.getFee(EndPoint.unStakeFioTokens, fioAddress)
fee = stakeFee
}
return this.pushTransaction(
'fio.staking',
'unstakefio',
{
return this.pushTransaction({
account: 'fio.staking',
action: 'unstakefio',
data: {
amount,
fio_address: fioAddress,
max_fee: fee,
tpid: technologyProviderId,
},
)
})
}

/**
Expand All @@ -1460,12 +1460,21 @@ export class FIOSDK {
* @param data JSON object with params for action
* @param encryptOptions JSON object with params for encryption
*/
public async pushTransaction(
public async pushTransaction({
account,
action,
data,
authPermission,
encryptOptions = {},
signingAccount,
}: {
account: string,
action: string,
data: any,
encryptOptions: EncryptOptions = {},
): Promise<any> {
authPermission?: string,
encryptOptions?: EncryptOptions,
signingAccount?: string,
}): Promise<any> {
data.tpid = this.getTechnologyProviderId(data.tpid)
if (data.content && !encryptOptions.key) {
switch (action) {
Expand All @@ -1485,12 +1494,14 @@ export class FIOSDK {
//
}
}
const pushTransaction = new SignedTransactions.PushTransaction(
const pushTransaction = new SignedTransactions.PushTransaction({
action,
account,
authPermission,
data,
encryptOptions,
)
signingAccount,
})
return pushTransaction.execute(this.privateKey, this.publicKey, this.returnPreparedTrx)
}

Expand Down Expand Up @@ -1774,7 +1785,14 @@ export class FIOSDK {
case 'getMultiplier':
return this.getMultiplier()
case 'pushTransaction':
return this.pushTransaction(params.account, params.action, params.data, params.encryptOptions)
return this.pushTransaction({
account: params.account,
action: params.action,
data: params.data,
authPermission: params.authPermission,
encryptOptions: params.encryptOptions,
signingAccount: params.signingAccount,
})
case 'getAccountPubKey':
return this.getAccountPubKey(params.account)
case 'getEncryptKey':
Expand Down
2 changes: 1 addition & 1 deletion src/entities/Autorization.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export class Autorization {
public actor: string
public permission: string
public permission?: string

constructor(actor: string, permission = 'active') {
this.actor = actor
Expand Down
1 change: 1 addition & 0 deletions src/entities/RawAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export class RawAction {
public name: string = '' // 'transfer',
public authorization: Autorization[] = new Array<Autorization>()
public data: any
public actor: string | undefined
}
15 changes: 10 additions & 5 deletions src/transactions/Transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export class Transactions {
public validationRules: any | null = null

public expirationOffset: number = Constants.defaultExpirationOffset
public authPermission: string | undefined
public signingAccount: string | undefined

public getActor(publicKey: string = ''): string {
return Transactions.FioProvider.accountHash((publicKey === '' || !publicKey) ? this.publicKey : publicKey)
Expand Down Expand Up @@ -223,16 +225,18 @@ export class Transactions {
}

public async createRawTransaction(
{ account, action, data, publicKey, chainData }: {
{ account, action, authPermission, data, publicKey, chainData, signingAccount }: {
account: string;
action: string;
data: any,
publicKey?: string,
authPermission?: string;
data: any;
publicKey?: string;
chainData?: {
ref_block_num: number,
ref_block_prefix: number,
expiration: string,
}
};
signingAccount?: string;
},
): Promise<RawTransaction> {
const rawTransaction = new RawTransaction()
Expand All @@ -244,10 +248,11 @@ export class Transactions {
data.actor = actor
}

rawaction.authorization.push(new Autorization(data.actor, data.permission))
rawaction.authorization.push(new Autorization(data.actor, authPermission))
rawaction.account = account
rawaction.name = action
rawaction.data = data
rawaction.actor = signingAccount
rawTransaction.actions.push(rawaction)

if (chainData && chainData.ref_block_num) {
Expand Down
Loading