Skip to content

Commit

Permalink
Merge pull request #181 from KeystoneHQ/prerelease
Browse files Browse the repository at this point in the history
Prerelease
  • Loading branch information
soralit authored Jan 2, 2025
2 parents 2ba7f90 + b772e59 commit 350c4a9
Show file tree
Hide file tree
Showing 9 changed files with 2,232 additions and 2,563 deletions.
15 changes: 15 additions & 0 deletions packages/ur-registry-avalanche/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# BC-UR-Registry-Avalanche

This repository is the Avalanche extension of [bc-ur-registry](https://github.com/KeystoneHQ/ur-registry)

## Installing

To install, run:

```bash
yarn add @keystonehq/bc-ur-registry-avalanche
```

```bash
npm install --save @keystonehq/bc-ur-registry-avalanche
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @ts-nocheck

import { StellarSignRequest, SignType, AvalancheSignRequest } from "../src";
import { CryptoKeypath, PathComponent } from "../src";
import * as uuid from "uuid";

describe("avalanche-sign-request", () => {
it("test should generate avalanche-sign-reqeust", () => {
const avalancheData = Buffer.from(
"00000000000000000001ed5f38341e436e5d46e2bb00b45d62ae97d1b050c64bc634ae10626739e35c4b0000000121e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff00000007000000000089544000000000000000000000000100000001512e7191685398f00663e12197a3d8f6012d9ea300000001db720ad6707915cc4751fb7e5491a3af74e127a1d81817abe9438590c0833fe10000000021e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff000000050000000000989680000000010000000000000000",
"hex"
);

const avalancheSignRequest =
AvalancheSignRequest.constructAvalancheRequest(avalancheData);

expect(avalancheSignRequest.toUR().cbor.toString("hex")).toBe(
"58de00000000000000000001ed5f38341e436e5d46e2bb00b45d62ae97d1b050c64bc634ae10626739e35c4b0000000121e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff00000007000000000089544000000000000000000000000100000001512e7191685398f00663e12197a3d8f6012d9ea300000001db720ad6707915cc4751fb7e5491a3af74e127a1d81817abe9438590c0833fe10000000021e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff000000050000000000989680000000010000000000000000"
);
});
});
6 changes: 6 additions & 0 deletions packages/ur-registry-avalanche/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
],
};
36 changes: 36 additions & 0 deletions packages/ur-registry-avalanche/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@keystonehq/bc-ur-registry-avalanche",
"version": "0.0.2",
"description": "bc-ur-registry extension for Avalanche",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"directories": {
"lib": "src",
"test": "__tests__"
},
"files": [
"src",
"dist"
],
"scripts": {
"clean": "rm -rf ./dist",
"start": "tsdx watch",
"build": "tsdx build",
"test": "jest --passWithNoTests"
},
"publishConfig": {
"access": "public"
},
"author": "[email protected]",
"license": "ISC",
"dependencies": {
"@keystonehq/bc-ur-registry": "^0.6.4",
"uuid": "^8.3.2"
},
"devDependencies": {
"@babel/preset-typescript": "^7.15.0",
"@types/uuid": "^8.3.1",
"tsdx": "^0.14.1",
"typescript": "^4.6.2"
}
}
37 changes: 37 additions & 0 deletions packages/ur-registry-avalanche/src/AvalancheSignRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { DataItem, RegistryItem } from "@keystonehq/bc-ur-registry";
import { ExtendedRegistryTypes } from "./RegistryType";
import * as uuid from "uuid";

type signRequestProps = {
requestId?: Buffer;
data: Buffer;
};

export class AvalancheSignRequest extends RegistryItem {
private requestId?: Buffer;
private data: Buffer;

getRegistryType = () => ExtendedRegistryTypes.AVALANCHE_SIGN_REQUEST;

constructor(args: signRequestProps) {
super();
this.requestId = args.requestId;
this.data = args.data;
}

public getRequestId = () => this.requestId;
public getSignData = () => this.data;

public toDataItem = () => {
return new DataItem(this.data);
};

public static constructAvalancheRequest(data: Buffer, uuidString?: string) {
return new AvalancheSignRequest({
data,
requestId: uuidString
? Buffer.from(uuid.parse(uuidString) as Uint8Array)
: undefined,
});
}
}
5 changes: 5 additions & 0 deletions packages/ur-registry-avalanche/src/RegistryType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { RegistryType } from "@keystonehq/bc-ur-registry";

export const ExtendedRegistryTypes = {
AVALANCHE_SIGN_REQUEST: new RegistryType("avax-sign-request", 8301),
};
11 changes: 11 additions & 0 deletions packages/ur-registry-avalanche/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { patchTags } from "@keystonehq/bc-ur-registry";
import { ExtendedRegistryTypes } from "./RegistryType";
export * from "@keystonehq/bc-ur-registry";

patchTags(
Object.values(ExtendedRegistryTypes)
.filter((rt) => !!rt.getTag())
.map((rt) => rt.getTag()) as number[]
);

export { AvalancheSignRequest } from "./AvalancheSignRequest";
13 changes: 13 additions & 0 deletions packages/ur-registry-avalanche/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"rootDir": "./",
"baseUrl": "./",
"paths": {
"*": ["src/*", "node_modules/*"]
}
}
}
Loading

0 comments on commit 350c4a9

Please sign in to comment.