Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,8 @@
"webpack-deadcode-plugin": "^0.1.17",
"webpack-dev-server": "^4.7.4",
"webpack-merge": "^5.8.0"
},
"dependencies": {
"@hexagon/base64": "^2.0.4"
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { base64 } from "@hexagon/base64";
import {
EVMAccountAddress,
EVMContractAddress,
Expand All @@ -14,7 +15,7 @@ import {
} from "@snickerdoodlelabs/objects";
import { ethers } from "ethers";
import { injectable } from "inversify";
import { ok, Result, ResultAsync } from "neverthrow";
import { err, ok, Result, ResultAsync } from "neverthrow";

import { BaseContract } from "@contracts-sdk/implementations/BaseContract.js";
import { IEthersContractError } from "@contracts-sdk/implementations/BlockchainErrorMapper.js";
Expand Down Expand Up @@ -99,8 +100,37 @@ export class SnickerdoodleWalletContract
public generateAddP256KeyWithP256KeyChallenge(
newKeyId: WebauthnCredentialId,
newP256PublicKey: P256PublicKeyComponents,
): Result<string, InvalidParametersError> {
return ok(newKeyId + newP256PublicKey.x + newP256PublicKey.y);
): Result<Uint8Array, InvalidParametersError> {
// Convert keyid to Uint8Array (UTF-8 encoding)
const uint8keyId = new TextEncoder().encode(newKeyId);

// Convert qx and qy from hex string to Uint8Array
const uint8qx = new Uint8Array(
newP256PublicKey.x
.slice(2)
.match(/.{1,2}/g)
?.map((byte) => parseInt(byte, 16)) ?? [],
);
const uint8qy = new Uint8Array(
newP256PublicKey.y
.slice(2)
.match(/.{1,2}/g)
?.map((byte) => parseInt(byte, 16)) ?? [],
);

if (uint8qx.length == 0 || uint8qy.length == 0) {
return err(new InvalidParametersError("Invalid P256PublicKeyComponents"));
}

// Combine all Uint8Arrays into a single Uint8Array
const totalLength = uint8keyId.length + uint8qx.length + uint8qy.length;
const payload = new Uint8Array(totalLength);

payload.set(uint8keyId, 0);
payload.set(uint8qx, uint8keyId.length);
payload.set(uint8qy, uint8keyId.length + uint8qx.length);

return ok(payload);
}

public addEVMAddressWithP256Key(
Expand Down Expand Up @@ -132,8 +162,9 @@ export class SnickerdoodleWalletContract

public generateAddEVMAddressWithP256KeyChallenge(
evmAccountAddress: EVMAccountAddress,
): Result<string, InvalidParametersError> {
return ok(evmAccountAddress);
): Result<Uint8Array, InvalidParametersError> {
// Remove 0x, convert to Uint8Array

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should check this out, and make sure it works with both 0x123 and just 123. I think that .encode will handle both versions, you should test that.

return ok(new TextEncoder().encode(evmAccountAddress.slice(2)));
}

public addEVMAccountWithEVMAccount(
Expand Down Expand Up @@ -281,4 +312,11 @@ export class SnickerdoodleWalletContract
): SnickerdoodleWalletContractError {
return new SnickerdoodleWalletContractError(msg, e, transaction);
}

private isoBase64fromBuffer(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This method isn't needed now, should remove it, along with the import

buffer: Uint8Array,
to: "base64" | "base64url" = "base64url",
): string {
return base64.fromArrayBuffer(buffer, to === "base64url");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface ISnickerdoodleWalletContract extends IBaseContract {
generateAddP256KeyWithP256KeyChallenge(
newKeyId: WebauthnCredentialId,
newP256PublicKey: P256PublicKeyComponents,
): Result<string, InvalidParametersError>;
): Result<Uint8Array, InvalidParametersError>;

addEVMAddressWithP256Key(
keyId: WebauthnCredentialId,
Expand All @@ -60,7 +60,7 @@ export interface ISnickerdoodleWalletContract extends IBaseContract {

generateAddEVMAddressWithP256KeyChallenge(
evmAccountAddress: EVMAccountAddress,
): Result<string, InvalidParametersError>;
): Result<Uint8Array, InvalidParametersError>;

addEVMAccountWithEVMAccount(
evmAccount: EVMAccountAddress | EVMContractAddress,
Expand Down
62 changes: 62 additions & 0 deletions packages/node-utils/test/unit/CryptoUtils4.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "reflect-metadata";
import { base64 } from "@hexagon/base64";
import {
P256SignatureComponentArrayBuffer,
P256PublicKeyPointX,
Expand Down Expand Up @@ -133,4 +134,65 @@ describe("CryptoUtils Tests 4", () => {
);
expect(result.challenge).toEqual(expectedParsedClientJSONData.challenge);
});

test("testing UTF 8 encoding() Closed Loop", async () => {
// Arrange
const mocks = new CryptoUtilsMocks();
const utils = mocks.factoryCryptoUtils();

const randomUint8 = new Uint8Array([
48, 69, 2, 32, 42, 228, 24, 140, 75, 246, 148, 250, 48, 159, 109, 5, 20,
84, 8, 181, 119, 68, 250, 126, 223, 173, 250, 18, 1, 67, 248, 44, 136,
135, 221, 69, 2, 33, 0, 163, 0, 154, 199, 217, 26, 153, 69, 164, 84, 1,
30, 196, 229, 197, 104, 165, 178, 7, 39, 227, 252, 139, 128, 65, 66, 253,
161, 217, 24, 242, 137,
]);

// our return value
const base64URLString = isoBase64fromBuffer(randomUint8);

const restoredRandomUint8 = base64URLStringToBuffer(base64URLString);

expect(randomUint8.buffer).toEqual(restoredRandomUint8);
});
});

function base64URLStringToBuffer(base64URLString: string): ArrayBuffer {
// Convert from Base64URL to Base64
const base64 = base64URLString.replace(/-/g, "+").replace(/_/g, "/");
/**
* Pad with '=' until it's a multiple of four
* (4 - (85 % 4 = 1) = 3) % 4 = 3 padding
* (4 - (86 % 4 = 2) = 2) % 4 = 2 padding
* (4 - (87 % 4 = 3) = 1) % 4 = 1 padding
* (4 - (88 % 4 = 0) = 4) % 4 = 0 padding
*/
const padLength = (4 - (base64.length % 4)) % 4;
const padded = base64.padEnd(base64.length + padLength, "=");
// Convert to a binary string
const binary = atob(padded);
// Convert binary string to buffer
const buffer = new ArrayBuffer(binary.length);
const bytes = new Uint8Array(buffer);
for (let i = 0; i < binary.length; i++) {
bytes[i] = binary.charCodeAt(i);
}
return buffer;
}

function bufferToBase64URLString(buffer: ArrayBuffer): string {
const bytes = new Uint8Array(buffer);
let str = "";
for (const charCode of bytes) {
str += String.fromCharCode(charCode);
}
const base64String = btoa(str);
return base64String.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
}

function isoBase64fromBuffer(
buffer: Uint8Array,
to: "base64" | "base64url" = "base64url",
): string {
return base64.fromArrayBuffer(buffer, to === "base64url");
}
14 changes: 11 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3957,6 +3957,13 @@ __metadata:
languageName: node
linkType: hard

"@hexagon/base64@npm:^2.0.4":
version: 2.0.4
resolution: "@hexagon/base64@npm:2.0.4"
checksum: dab3e8c068916c5bec881ef4d28c05afb052c50445d320dbd77dbf8c1c3c2460972b1f4cf9ef393b59d5ada90c2a9b9b2e2a864d7b1bd291343465fa2722b4c2
languageName: node
linkType: hard

"@hot-loader/react-dom@npm:^17.0.2":
version: 17.0.2
resolution: "@hot-loader/react-dom@npm:17.0.2"
Expand Down Expand Up @@ -21181,7 +21188,7 @@ __metadata:
"ds-test@github:dapphub/ds-test":
version: 1.0.0
resolution: "ds-test@https://github.com/dapphub/ds-test.git#commit=e282159d5170298eb2455a6c05280ab5a73a4ef0"
checksum: 1b88c755f3bfd1b90fc413a475d0bf94cb1e4002dbdeaff49c1b98249776722c965111c7d944f92022b7747fcfe288ea2bdd8a9937975feb75406278ea8e222c
checksum: 8f36e20dde868d062841c790fc43c9dd18b93d6180995f378bedaee1f24444950838843c0f2ffa5ac3b8a21b4c29fd97a60725e29e8ff71c9cf28f837614d96f
languageName: node
linkType: hard

Expand Down Expand Up @@ -42239,6 +42246,7 @@ __metadata:
"@cucumber/pretty-formatter": ^1.0.0
"@glazed/devtools": ^0.2.0
"@google-cloud/storage": ^6.7.0
"@hexagon/base64": ^2.0.4
"@jest/types": ^29.0.3
"@layerzerolabs/lz-evm-oapp-v2": ^2.3.33
"@nomicfoundation/hardhat-chai-matchers": ^2.0.0
Expand Down Expand Up @@ -43916,7 +43924,7 @@ __metadata:
"sync-promise@git+https://github.com/brettz9/sync-promise.git#full-sync-missing-promise-features":
version: 1.0.1
resolution: "sync-promise@https://github.com/brettz9/sync-promise.git#commit=25845a49a00aa2d2c985a5149b97c86a1fcdc75a"
checksum: 65b406160c33ab72eee9b784f155bb1dbc1f742ec8385721c39bd70fe3fbb14f929e565c967a789589578280c7d9ea3c52d6e91f7eb7ddca7f8d60e210979343
checksum: f536c50c270ef2ec28511af3b90ba10b8e2b3b51b3e4079136d428150ccc9592f47d02e2cf41ba02135e4a81f59fb472d642794d807bacf8c55a20f85ff57c8a
languageName: node
linkType: hard

Expand Down Expand Up @@ -47906,7 +47914,7 @@ __metadata:
dependenciesMeta:
sqlite3:
optional: true
checksum: 08f18e16271f0f94ed48075b1f005d4b01d7ad4d515b845688a9af35be5f65f35497fadd2399a9969808132c13e393c4ac75f8ffd02d92f3f5e3a57cd8bb81c8
checksum: 60d7fea6d974cf5df4361a0cdf9e7b6bca17cd59028fa2a7a72754f34e54242ef6e85aa09b97a8898566baa452c3700cf30f8d8cfbc230a2b9b7f514ce99a469
languageName: node
linkType: hard

Expand Down