Skip to content

Commit 350c4a9

Browse files
authored
Merge pull request #181 from KeystoneHQ/prerelease
Prerelease
2 parents 2ba7f90 + b772e59 commit 350c4a9

File tree

9 files changed

+2232
-2563
lines changed

9 files changed

+2232
-2563
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# BC-UR-Registry-Avalanche
2+
3+
This repository is the Avalanche extension of [bc-ur-registry](https://github.com/KeystoneHQ/ur-registry)
4+
5+
## Installing
6+
7+
To install, run:
8+
9+
```bash
10+
yarn add @keystonehq/bc-ur-registry-avalanche
11+
```
12+
13+
```bash
14+
npm install --save @keystonehq/bc-ur-registry-avalanche
15+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @ts-nocheck
2+
3+
import { StellarSignRequest, SignType, AvalancheSignRequest } from "../src";
4+
import { CryptoKeypath, PathComponent } from "../src";
5+
import * as uuid from "uuid";
6+
7+
describe("avalanche-sign-request", () => {
8+
it("test should generate avalanche-sign-reqeust", () => {
9+
const avalancheData = Buffer.from(
10+
"00000000000000000001ed5f38341e436e5d46e2bb00b45d62ae97d1b050c64bc634ae10626739e35c4b0000000121e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff00000007000000000089544000000000000000000000000100000001512e7191685398f00663e12197a3d8f6012d9ea300000001db720ad6707915cc4751fb7e5491a3af74e127a1d81817abe9438590c0833fe10000000021e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff000000050000000000989680000000010000000000000000",
11+
"hex"
12+
);
13+
14+
const avalancheSignRequest =
15+
AvalancheSignRequest.constructAvalancheRequest(avalancheData);
16+
17+
expect(avalancheSignRequest.toUR().cbor.toString("hex")).toBe(
18+
"58de00000000000000000001ed5f38341e436e5d46e2bb00b45d62ae97d1b050c64bc634ae10626739e35c4b0000000121e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff00000007000000000089544000000000000000000000000100000001512e7191685398f00663e12197a3d8f6012d9ea300000001db720ad6707915cc4751fb7e5491a3af74e127a1d81817abe9438590c0833fe10000000021e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff000000050000000000989680000000010000000000000000"
19+
);
20+
});
21+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
["@babel/preset-env", { targets: { node: "current" } }],
4+
"@babel/preset-typescript",
5+
],
6+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "@keystonehq/bc-ur-registry-avalanche",
3+
"version": "0.0.2",
4+
"description": "bc-ur-registry extension for Avalanche",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"directories": {
8+
"lib": "src",
9+
"test": "__tests__"
10+
},
11+
"files": [
12+
"src",
13+
"dist"
14+
],
15+
"scripts": {
16+
"clean": "rm -rf ./dist",
17+
"start": "tsdx watch",
18+
"build": "tsdx build",
19+
"test": "jest --passWithNoTests"
20+
},
21+
"publishConfig": {
22+
"access": "public"
23+
},
24+
"author": "[email protected]",
25+
"license": "ISC",
26+
"dependencies": {
27+
"@keystonehq/bc-ur-registry": "^0.6.4",
28+
"uuid": "^8.3.2"
29+
},
30+
"devDependencies": {
31+
"@babel/preset-typescript": "^7.15.0",
32+
"@types/uuid": "^8.3.1",
33+
"tsdx": "^0.14.1",
34+
"typescript": "^4.6.2"
35+
}
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { DataItem, RegistryItem } from "@keystonehq/bc-ur-registry";
2+
import { ExtendedRegistryTypes } from "./RegistryType";
3+
import * as uuid from "uuid";
4+
5+
type signRequestProps = {
6+
requestId?: Buffer;
7+
data: Buffer;
8+
};
9+
10+
export class AvalancheSignRequest extends RegistryItem {
11+
private requestId?: Buffer;
12+
private data: Buffer;
13+
14+
getRegistryType = () => ExtendedRegistryTypes.AVALANCHE_SIGN_REQUEST;
15+
16+
constructor(args: signRequestProps) {
17+
super();
18+
this.requestId = args.requestId;
19+
this.data = args.data;
20+
}
21+
22+
public getRequestId = () => this.requestId;
23+
public getSignData = () => this.data;
24+
25+
public toDataItem = () => {
26+
return new DataItem(this.data);
27+
};
28+
29+
public static constructAvalancheRequest(data: Buffer, uuidString?: string) {
30+
return new AvalancheSignRequest({
31+
data,
32+
requestId: uuidString
33+
? Buffer.from(uuid.parse(uuidString) as Uint8Array)
34+
: undefined,
35+
});
36+
}
37+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { RegistryType } from "@keystonehq/bc-ur-registry";
2+
3+
export const ExtendedRegistryTypes = {
4+
AVALANCHE_SIGN_REQUEST: new RegistryType("avax-sign-request", 8301),
5+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { patchTags } from "@keystonehq/bc-ur-registry";
2+
import { ExtendedRegistryTypes } from "./RegistryType";
3+
export * from "@keystonehq/bc-ur-registry";
4+
5+
patchTags(
6+
Object.values(ExtendedRegistryTypes)
7+
.filter((rt) => !!rt.getTag())
8+
.map((rt) => rt.getTag()) as number[]
9+
);
10+
11+
export { AvalancheSignRequest } from "./AvalancheSignRequest";
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["src"],
4+
"compilerOptions": {
5+
"noImplicitAny": true,
6+
"strictNullChecks": true,
7+
"rootDir": "./",
8+
"baseUrl": "./",
9+
"paths": {
10+
"*": ["src/*", "node_modules/*"]
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)