Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6acef0d
WIP update snickerdoodlewallet in contracts sdk
seansing Oct 7, 2024
16831ba
Merge branch 'feature/new-contracts-package' into feature/update-cont…
seansing Oct 8, 2024
e3ea980
Merge branch 'feature/new-contracts-package' into feature/update-cont…
seansing Oct 8, 2024
d37d18f
Merge branch 'feature/new-contracts-package' into feature/update-cont…
seansing Oct 8, 2024
531b8a2
Merge branch 'feature/new-contracts-package' into feature/update-cont…
seansing Oct 8, 2024
c84f9e7
Merge branch 'feature/new-contracts-package' into feature/update-cont…
seansing Oct 8, 2024
342ff40
complete contracts-sdk update for Snickerdoodle wallet and factory
seansing Oct 8, 2024
08d3741
Merge branch 'feature/new-contracts-package' into feature/update-cont…
seansing9 Oct 10, 2024
b3aae7a
update objects
seansing9 Oct 10, 2024
1d9df85
WIP update contracts-sdk and crypto utils
seansing9 Oct 18, 2024
b448258
Merge branch 'feature/new-contracts-package' into feature/update-cont…
seansing9 Oct 22, 2024
3ff8ed2
update contracts-sdk
seansing9 Oct 22, 2024
713b88e
Merge branch 'feature/new-contracts-package' into feature/update-cont…
seansing9 Oct 22, 2024
5a361d5
updated signature components
seansing9 Oct 22, 2024
098ed88
updated cryptoutils, included unit test
seansing9 Oct 23, 2024
fc37861
update function name
seansing9 Oct 23, 2024
0269fee
clean up
seansing9 Oct 23, 2024
fe478bc
fix from comments
seansing9 Oct 24, 2024
807ed06
fix from discussion
seansing9 Oct 25, 2024
3a17a16
rename AuthenticatorData to P256VerificationData
seansing9 Oct 25, 2024
66fcf4e
Fixed methods for generating challenges.
SnickerChar Oct 25, 2024
93f2259
Publish node-utils
SnickerChar Oct 25, 2024
0dc9e89
implement generate challenge
seansing9 Oct 28, 2024
3a2e049
Merge branch 'feature/new-contracts-package' into feature/update-cont…
seansing9 Oct 28, 2024
bf3f410
update contracts sdk with latest functions
seansing9 Oct 28, 2024
a68e54c
Merge branch 'feature/new-contracts-package' into feature/update-cont…
seansing9 Oct 28, 2024
a283e3d
Change challenge methods to static
SnickerChar Oct 28, 2024
5dc0003
update generate challenge functions, add @hexagon/base64, add unit test
seansing9 Oct 28, 2024
1e9b311
update version, fix interface
seansing9 Oct 28, 2024
80f754e
normalize evm address before generating challenge
seansing9 Oct 28, 2024
ab4fafe
Added contract addresses to chain information.
SnickerChar Oct 30, 2024
7a330e8
Change ChainInformation because the idea of different info only for t…
SnickerChar Oct 30, 2024
9d4b85f
Removed unnecessary msgPayload parameter from parseRawP256Signature
SnickerChar Oct 30, 2024
2ab2efa
Merge branch 'feature/new-contracts-package' into feature/update-cont…
seansing9 Oct 31, 2024
3a3efab
updated contracts sdk functions and abi
seansing9 Oct 31, 2024
dcc50ec
include operator gateway proxy deployment, updated dockerfiles, remov…
seansing9 Oct 31, 2024
d0495ac
merged feature/new-contracts-package
seansing9 Oct 31, 2024
3189707
updated addresses in chains config, add scripts to contracts-sdk pack…
seansing9 Nov 5, 2024
39a3817
Fix non-export of BlockchainErrorMapper
SnickerChar Nov 6, 2024
c8feeec
Merge branch 'feature/update-contracts-sdk-with-snickerdoodle-wallet'…
SnickerChar Nov 6, 2024
3322b8e
update contracts sdk
seansing9 Nov 14, 2024
76d8b87
add asn1 prefix to parsing p256 public key
seansing9 Nov 14, 2024
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
1 change: 1 addition & 0 deletions packages/contracts-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"!dist/tsconfig.tsbuildinfo",
"!test",
"!src",
"!src-new",
"!tsconfig.json"
],
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import {
EVMAccountAddress,
EVMContractAddress,
BlockchainCommonErrors,
OperatorGatewayContractError,
PasskeyId,
P256PublicKeyComponents,
P256SignatureComponents,
LayerZeroEndpointId,
OperatorDomain,
TokenAmount,
} from "@snickerdoodlelabs/objects";
import { ethers } from "ethers";
import { injectable } from "inversify";
import { ResultAsync } from "neverthrow";

import { IEthersContractError } from "@contracts-sdk/implementations/BlockchainErrorMapper.js";
import { ERC7529Contract } from "@contracts-sdk/implementations/ERC7529Contract.js";
import {
ContractOverrides,
WrappedTransactionResponse,
IOperatorGatewayContract,
} from "@contracts-sdk/interfaces/index.js";
import {
AuthenticatorData,
ContractsAbis,
} from "@contracts-sdk/interfaces/objects/index.js";

@injectable()
export class OperatorGatewayContract
extends ERC7529Contract<OperatorGatewayContractError>
implements IOperatorGatewayContract
{
constructor(
protected providerOrSigner: ethers.Provider | ethers.Signer,
protected contractAddress: EVMContractAddress,
) {
super(
providerOrSigner,
contractAddress,
ContractsAbis.OperatorGatewayAbi.abi,
);
}

public deployWallets(
usernames: string[],
p256Keys: P256PublicKeyComponents[][],
evmAccounts: EVMContractAddress[][] | EVMAccountAddress[][],
overrides?: ContractOverrides,
): ResultAsync<
WrappedTransactionResponse,
OperatorGatewayContractError | BlockchainCommonErrors
> {
return this.writeToContract(
"deployWallets",
[usernames, p256Keys, evmAccounts],
overrides,
);
}

public reserveWalletsOnDestinationChain(
destinationLayerZeroEndpointId: LayerZeroEndpointId,
usernames: string[],
gas: bigint,
nativeTokenFee: bigint, // Required fee calculated from the quote function to be sent with the transaction to pay for the LayerZero _lzReceive() call
overrides?: ContractOverrides,
): ResultAsync<
WrappedTransactionResponse,
BlockchainCommonErrors | OperatorGatewayContractError
> {
// If there are no overrides provided, create an empty object
const overridesWithFee = overrides ? overrides : ({} as ContractOverrides);

// include the fee in the overrides object
overridesWithFee.value = nativeTokenFee;

return this.writeToContract(
"reserveWalletsOnDestinationChain",
[destinationLayerZeroEndpointId, usernames, gas],
overrides,
);
}

public quoteAuthorizeOperatorGatewayOnDestinationChain(
destinationLayerZeroEndpointId: LayerZeroEndpointId,
domain: OperatorDomain,
gas: bigint,
): ResultAsync<
TokenAmount,
OperatorGatewayContractError | BlockchainCommonErrors
> {
return ResultAsync.fromPromise(
this.contract.quoteAuthorizeOperatorGatewayOnDestinationChain(
destinationLayerZeroEndpointId,
domain,
gas,
) as Promise<TokenAmount[]>,
(e) => {
return this.generateError(
e,
"Unable to call quoteAuthorizeOperatorGatewayOnDestinationChain()",
);
},
).map((quotedFee) => {
// The quoted fee is returned as fee in [native token, layer zero token]
// We only need the native token fee amount
return quotedFee[0];
});
}

public authorizeWalletOnDestinationChain(
destinationLayerZeroEndpointId: LayerZeroEndpointId,
username: string,
gas: bigint,
nativeTokenFee: bigint, // Required fee calculated from the quoteAuthorizeWalletOnDestinationChain function to be sent with the transaction to pay for the LayerZero _lzReceive() call
overrides?: ContractOverrides,
): ResultAsync<
WrappedTransactionResponse,
BlockchainCommonErrors | OperatorGatewayContractError
> {
// If there are no overrides provided, create an empty object
const overridesWithFee = overrides ? overrides : ({} as ContractOverrides);

// include the fee in the overrides object
overridesWithFee.value = nativeTokenFee;

return this.writeToContract(
"authorizeWalletOnDestinationChain",
[destinationLayerZeroEndpointId, username, gas],
overrides,
);
}

public addP256KeysWithP256Keys(
evmAccounts: EVMContractAddress[] | EVMAccountAddress[],
keyIds: PasskeyId[],
authenticatorDatas: AuthenticatorData[],
newP256Keys: P256PublicKeyComponents[],
p256Signatures: P256SignatureComponents[],
overrides?: ContractOverrides,
): ResultAsync<
WrappedTransactionResponse,
BlockchainCommonErrors | OperatorGatewayContractError
> {
return this.writeToContract(
"addP256KeyWithP256Key",
[evmAccounts, keyIds, authenticatorDatas, newP256Keys, p256Signatures],
overrides,
);
}

protected generateContractSpecificError(
msg: string,
e: IEthersContractError,
transaction: ethers.Transaction | null,
): OperatorGatewayContractError {
return new OperatorGatewayContractError(msg, e, transaction);
}
}
Loading