Skip to content

Fix/dual package hazard symbol hasinstance #990

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ module.exports = {
'@typescript-eslint/no-redeclare': ['error'],
'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['error'],
'no-underscore-dangle': [
'error',
{
allow: [
'_isAlgosdkAddress',
'_isAlgosdkTransaction',
'_isAlgosdkSignedTransaction',
'_isAlgosdkLogicSig',
'_isAlgosdkLogicSigAccount',
'_isAlgosdkAtomicTransactionComposer',
'_isAlgosdkABIContract',
'_isAlgosdkABIUintType',
'_isAlgosdkABIUfixedType',
'_isAlgosdkABIAddressType',
'_isAlgosdkABIBoolType',
'_isAlgosdkABIByteType',
'_isAlgosdkABIStringType',
'_isAlgosdkABIArrayStaticType',
'_isAlgosdkABIArrayDynamicType',
'_isAlgosdkABITupleType',
],
},
],
Comment on lines +44 to +66
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could just allow all leading _ here. Is that ok for this repo?

},
overrides: [
{
Expand Down
126 changes: 126 additions & 0 deletions src/abi/abi_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ export abstract class ABIType {
export class ABIUintType extends ABIType {
bitSize: number;

/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkABIUintType = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is an ABIUintType, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(instance && instance._isAlgosdkABIUintType === true);
}

constructor(size: number) {
super();
if (size % 8 !== 0 || size < 8 || size > 512) {
Expand Down Expand Up @@ -181,6 +195,20 @@ export class ABIUfixedType extends ABIType {
bitSize: number;
precision: number;

/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkABIUfixedType = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is an ABIUfixedType, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(instance && instance._isAlgosdkABIUfixedType === true);
}

constructor(size: number, denominator: number) {
super();
if (size % 8 !== 0 || size < 8 || size > 512) {
Expand Down Expand Up @@ -239,6 +267,20 @@ export class ABIUfixedType extends ABIType {
}

export class ABIAddressType extends ABIType {
/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkABIAddressType = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is an ABIAddressType, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(instance && instance._isAlgosdkABIAddressType === true);
}

toString() {
return 'address';
}
Expand Down Expand Up @@ -285,6 +327,20 @@ export class ABIAddressType extends ABIType {
}

export class ABIBoolType extends ABIType {
/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkABIBoolType = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is an ABIBoolType, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(instance && instance._isAlgosdkABIBoolType === true);
}

toString() {
return 'bool';
}
Expand Down Expand Up @@ -327,6 +383,20 @@ export class ABIBoolType extends ABIType {
}

export class ABIByteType extends ABIType {
/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkABIByteType = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is an ABIByteType, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(instance && instance._isAlgosdkABIByteType === true);
}

toString() {
return 'byte';
}
Expand Down Expand Up @@ -366,6 +436,20 @@ export class ABIByteType extends ABIType {
}

export class ABIStringType extends ABIType {
/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkABIStringType = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is an ABIStringType, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(instance && instance._isAlgosdkABIStringType === true);
}

toString() {
return 'string';
}
Expand Down Expand Up @@ -433,6 +517,20 @@ export class ABIArrayStaticType extends ABIType {
childType: ABIType;
staticLength: number;

/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkABIArrayStaticType = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is an ABIArrayStaticType, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(instance && instance._isAlgosdkABIArrayStaticType === true);
}

constructor(argType: ABIType, arrayLength: number) {
super();
if (arrayLength < 0) {
Expand Down Expand Up @@ -493,6 +591,20 @@ export class ABIArrayStaticType extends ABIType {
export class ABIArrayDynamicType extends ABIType {
childType: ABIType;

/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkABIArrayDynamicType = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is an ABIArrayDynamicType, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(instance && instance._isAlgosdkABIArrayDynamicType === true);
}

constructor(argType: ABIType) {
super();
this.childType = argType;
Expand Down Expand Up @@ -548,6 +660,20 @@ export class ABIArrayDynamicType extends ABIType {
export class ABITupleType extends ABIType {
childTypes: ABIType[];

/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkABITupleType = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is an ABITupleType, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(instance && instance._isAlgosdkABITupleType === true);
}

constructor(argTypes: ABIType[]) {
super();
if (argTypes.length >= MAX_LEN) {
Expand Down
14 changes: 14 additions & 0 deletions src/abi/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ export class ABIContract {
/** [ARC-28](https://arc.algorand.foundation/ARCs/arc-0028) events that MAY be emitted by this contract */
public readonly events?: ARC28Event[];

/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkABIContract = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is an ABIContract, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(instance && instance._isAlgosdkABIContract === true);
}

constructor(params: ABIContractParams) {
if (
typeof params.name !== 'string' ||
Expand Down
18 changes: 17 additions & 1 deletion src/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ export class AtomicTransactionComposer {
/** The maximum size of an atomic transaction group. */
static MAX_GROUP_SIZE: number = 16;

/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkAtomicTransactionComposer = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is an AtomicTransactionComposer, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(
instance && instance._isAlgosdkAtomicTransactionComposer === true
);
}

private status = AtomicTransactionComposerStatus.BUILDING;
private transactions: TransactionWithSigner[] = [];
private methodCalls: Map<number, ABIMethod> = new Map();
Expand Down Expand Up @@ -632,7 +648,7 @@ export class AtomicTransactionComposer {
*
* @param client - An Algodv2 client
* @param request - SimulateRequest with options in simulation.
* If provided, the request's transaction group will be overrwritten by the composer's group,
* If provided, the request's transaction group will be overwritten by the composer's group,
* only simulation related options will be used.
*
* @returns A promise that, upon success, resolves to an object containing an
Expand Down
14 changes: 14 additions & 0 deletions src/encoding/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ export class Address {
*/
public readonly publicKey: Uint8Array;

/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkAddress = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is an Address, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(instance && instance._isAlgosdkAddress === true);
}

/**
* Create a new Address object from its binary form.
* @param publicKey - The binary form of the address. Must be 32 bytes.
Expand Down
28 changes: 28 additions & 0 deletions src/logicsig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ export class LogicSig implements encoding.Encodable {
])
);

/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkLogicSig = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is a LogicSig, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(instance && instance._isAlgosdkLogicSig === true);
}

logic: Uint8Array;
args: Uint8Array[];
sig?: Uint8Array;
Expand Down Expand Up @@ -268,6 +282,20 @@ export class LogicSigAccount implements encoding.Encodable {
])
);

/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkLogicSigAccount = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is a LogicSigAccount, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(instance && instance._isAlgosdkLogicSigAccount === true);
}

lsig: LogicSig;
sigkey?: Uint8Array;

Expand Down
14 changes: 14 additions & 0 deletions src/signedTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ export class SignedTransaction implements Encodable {
])
);

/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkSignedTransaction = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is a SignedTransaction, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(instance && instance._isAlgosdkSignedTransaction === true);
}

/**
* The transaction that was signed
*/
Expand Down
14 changes: 14 additions & 0 deletions src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,20 @@ export class Transaction implements encoding.Encodable {
])
);

/**
* Unique property marker for Symbol.hasInstance compatibility across module boundaries
*/
private readonly _isAlgosdkTransaction = true;

/**
* Custom Symbol.hasInstance to handle dual package hazard
* @param instance - The instance to check
* @returns true if the instance is a Transaction, regardless of which module loaded it
*/
static [Symbol.hasInstance](instance: any): boolean {
return !!(instance && instance._isAlgosdkTransaction === true);
}

/** common */
public readonly type: TransactionType;
public readonly sender: Address;
Expand Down
Loading