Skip to content

Commit

Permalink
refactor!: remove signOracleQueryDelegationToContract
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `signOracleQueryDelegationToContract` removed
Use `signDelegation` instead.
  • Loading branch information
davidyuk committed Jun 8, 2024
1 parent c4d62b0 commit f948492
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 135 deletions.
12 changes: 0 additions & 12 deletions examples/browser/wallet-iframe/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,6 @@ export default {
return super.signAllNamesDelegationToContract(contractAddress, options);
}
async signOracleQueryDelegationToContract(
contractAddress,
oracleQueryId,
{ aeppRpcClientId: id, aeppOrigin, ...options },
) {
if (id != null) {
const opt = { ...options, contractAddress, oracleQueryId };
genConfirmCallback('sign delegation of oracle query to contract')(id, opt, aeppOrigin);
}
return super.signOracleQueryDelegationToContract(contractAddress, oracleQueryId, options);
}
async sign(data, { aeppRpcClientId: id, aeppOrigin, ...options } = {}) {
if (id != null) {
genConfirmCallback(`sign raw data ${data}`)(id, options, aeppOrigin);
Expand Down
12 changes: 0 additions & 12 deletions examples/browser/wallet-web-extension/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,6 @@ class AccountMemoryProtected extends MemoryAccount {
return super.signAllNamesDelegationToContract(contractAddress, options);
}

async signOracleQueryDelegationToContract(
contractAddress,
oracleQueryId,
{ aeppRpcClientId: id, aeppOrigin, ...options },
) {
if (id != null) {
const opt = { ...options, contractAddress, oracleQueryId };
await genConfirmCallback('sign delegation of oracle query to contract')(id, opt, aeppOrigin);
}
return super.signOracleQueryDelegationToContract(contractAddress, oracleQueryId, options);
}

async sign(data, { aeppRpcClientId: id, aeppOrigin, ...options } = {}) {
if (id != null) {
await genConfirmCallback(`sign raw data ${data}`)(id, options, aeppOrigin);
Expand Down
20 changes: 0 additions & 20 deletions src/AeSdkBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,26 +263,6 @@ export default class AeSdkBase extends AeSdkMethods {
.signAllNamesDelegationToContract(contractAddress, options);
}

/**
* @deprecated use AeSdkBase:signDelegation in Ceres
* @param contractAddress - Contract address
* @param oracleQueryId - Oracle query id
* @param options - Options
*/
async signOracleQueryDelegationToContract(
contractAddress: Encoded.ContractAddress,
oracleQueryId: Encoded.OracleQueryId,
{ onAccount, ...options }: { onAccount?: OnAccount }
& Parameters<AccountBase['signOracleQueryDelegationToContract']>[2] = {},
): Promise<Encoded.Signature> {
options.networkId ??= this.selectedNodeName !== null
? await this.api.getNetworkId() : undefined;
options.consensusProtocolVersion ??= this.selectedNodeName !== null
? (await this.api.getNodeInfo()).consensusProtocolVersion : undefined;
return this._resolveAccount(onAccount)
.signOracleQueryDelegationToContract(contractAddress, oracleQueryId, options);
}

/**
* Sign delegation, works only in Ceres
* @param delegation - Delegation to sign
Expand Down
32 changes: 0 additions & 32 deletions src/account/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,38 +150,6 @@ export default abstract class AccountBase {
throw new NotImplementedError('signAllNamesDelegationToContract method');
}

/**
* Sign delegation of oracle query to a contract
*
* Warning! Implementations needs to ensure that decoded oracle query id is not equal to decoded
* current account address unless https://github.com/aeternity/aesophia/issues/475 is fixed.
*
* Warning! Implementations needs to ensure that oracle query and contract exists unless
* https://github.com/aeternity/aesophia/issues/474 is fixed.
*
* @param contractAddress - Address of a contract to delegate permissions to
* @param oracleQueryId - Oracle query ID to reply by a contract
* @param options - Options
* @returns Signature
* @deprecated use AccountBase:signDelegation in Ceres
*/
// TODO: make abstract in the next major release
// eslint-disable-next-line class-methods-use-this
async signOracleQueryDelegationToContract(
/* eslint-disable @typescript-eslint/no-unused-vars */
contractAddress: Encoded.ContractAddress,
oracleQueryId: Encoded.OracleQueryId,
options?: {
networkId?: string;
consensusProtocolVersion?: ConsensusProtocolVersion;
aeppOrigin?: string;
aeppRpcClientId?: string;
},
/* eslint-enable @typescript-eslint/no-unused-vars */
): Promise<Encoded.Signature> {
throw new NotImplementedError('signOracleQueryDelegationToContract method');
}

/**
* Sign data blob
* @param data - Data blob to sign
Expand Down
5 changes: 0 additions & 5 deletions src/account/Generalized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ export default class AccountGeneralized extends AccountBase {
throw new NotImplementedError('signing delegation to contract using generalized account');
}

// eslint-disable-next-line class-methods-use-this
override async signOracleQueryDelegationToContract(): Promise<Encoded.Signature> {
throw new NotImplementedError('signing delegation to contract using generalized account');
}

// eslint-disable-next-line class-methods-use-this
override async signDelegation(): Promise<Encoded.Signature> {
throw new NotImplementedError('signing delegation using generalized account');
Expand Down
5 changes: 0 additions & 5 deletions src/account/Ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ export default class AccountLedger extends AccountBase {
throw new NotImplementedError('signing delegation to contract using Ledger HW');
}

// eslint-disable-next-line class-methods-use-this
override async signOracleQueryDelegationToContract(): Promise<Encoded.Signature> {
throw new NotImplementedError('signing delegation to contract using Ledger HW');
}

// eslint-disable-next-line class-methods-use-this
override async signDelegation(): Promise<Encoded.Signature> {
throw new NotImplementedError('signing delegation using Ledger HW');
Expand Down
30 changes: 0 additions & 30 deletions src/account/Memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,36 +174,6 @@ export default class AccountMemory extends AccountBase {
return encode(signature, Encoding.Signature);
}

override async signOracleQueryDelegationToContract(
contractAddress: Encoded.ContractAddress,
oracleQueryId: Encoded.OracleQueryId,
{ networkId, consensusProtocolVersion }: {
networkId?: string;
consensusProtocolVersion?: ConsensusProtocolVersion;
} = {},
): Promise<Encoded.Signature> {
if (consensusProtocolVersion === ConsensusProtocolVersion.Ceres) {
const delegation = packDelegation({
tag: DelegationTag.OracleResponse, queryId: oracleQueryId, contractAddress,
});
return this.signDelegation(delegation, { networkId });
}
const oracleQueryIdDecoded = decode(oracleQueryId);
const addressDecoded = decode(this.address);
// TODO: remove after fixing https://github.com/aeternity/aesophia/issues/475
if (oracleQueryIdDecoded.compare(addressDecoded) === 0) {
throw new ArgumentError('oracleQueryId', 'not equal to account address', oracleQueryId);
}
if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);
const payload = concatBuffers([
Buffer.from(networkId),
oracleQueryIdDecoded,
decode(contractAddress),
]);
const signature = await this.sign(payload);
return encode(signature, Encoding.Signature);
}

override async signDelegation(
delegation: Encoded.Bytearray,
{ networkId }: { networkId?: string } = {},
Expand Down
14 changes: 0 additions & 14 deletions src/account/Rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,6 @@ export default class AccountRpc extends AccountBase {
throw new NotImplementedError('');
}

override async signOracleQueryDelegationToContract(
contractAddress: Encoded.ContractAddress,
oracleQueryId: Encoded.OracleQueryId,
{ consensusProtocolVersion }: { consensusProtocolVersion?: ConsensusProtocolVersion } = {},
): Promise<Encoded.Signature> {
if (consensusProtocolVersion === ConsensusProtocolVersion.Ceres) {
const delegation = packDelegation({
tag: DelegationTag.OracleResponse, queryId: oracleQueryId, contractAddress,
});
return this.signDelegation(delegation);
}
throw new NotImplementedError('');
}

override async signDelegation(delegation: Encoded.Bytearray): Promise<Encoded.Signature> {
const { signature } = await this._rpcClient.request(
METHODS.signDelegation,
Expand Down
21 changes: 16 additions & 5 deletions src/tx/builder/delegation/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ export enum DelegationTag {
AensName = 2,
AensPreclaim = 3,
Oracle = 4,
/**
* Delegation of oracle query to a contract
*/
OracleResponse = 5,
}

const oracleAddressField = address(Encoding.OracleAddress);
/**
* Oracle query ID to reply by a contract
*/
const queryIdField = {
serialize(value: Encoded.OracleQueryId): Buffer {
return oracleAddressField.serialize(encode(decode(value), Encoding.OracleAddress));
Expand All @@ -27,35 +33,40 @@ const queryIdField = {
},
} as const;

/**
* Address of a contract to delegate permissions to
*/
const contractAddress = address(Encoding.ContractAddress);

/**
* @see {@link https://github.com/aeternity/protocol/blob/8a9d1d1206174627f6aaef86159dc9c643080653/contracts/fate.md#from-ceres-serialized-signature-data}
*/
export const schemas = [{
tag: shortUIntConst(DelegationTag.AensWildcard),
version: shortUIntConst(1, true),
accountAddress: address(Encoding.AccountAddress),
contractAddress: address(Encoding.ContractAddress),
contractAddress,
}, {
tag: shortUIntConst(DelegationTag.AensName),
version: shortUIntConst(1, true),
accountAddress: address(Encoding.AccountAddress),
nameId,
contractAddress: address(Encoding.ContractAddress),
contractAddress,
}, {
tag: shortUIntConst(DelegationTag.AensPreclaim),
version: shortUIntConst(1, true),
accountAddress: address(Encoding.AccountAddress),
contractAddress: address(Encoding.ContractAddress),
contractAddress,
}, {
tag: shortUIntConst(DelegationTag.Oracle),
version: shortUIntConst(1, true),
accountAddress: address(Encoding.AccountAddress),
contractAddress: address(Encoding.ContractAddress),
contractAddress,
}, {
tag: shortUIntConst(DelegationTag.OracleResponse),
version: shortUIntConst(1, true),
queryId: queryIdField,
contractAddress: address(Encoding.ContractAddress),
contractAddress,
}] as const;

type Schemas = SchemaTypes<typeof schemas>;
Expand Down

0 comments on commit f948492

Please sign in to comment.