Skip to content

Commit

Permalink
Add SignData
Browse files Browse the repository at this point in the history
  • Loading branch information
Basket123123 committed Aug 20, 2024
1 parent dff3b51 commit 81dd6bc
Show file tree
Hide file tree
Showing 23 changed files with 1,382 additions and 2,183 deletions.
10 changes: 5 additions & 5 deletions src/__tests__/attestation/attestation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ describe('Serializes and deserializes attestation request', () => {
challenge: {
challenge_id: "iMqzCkWdebC19xbjkLfVdDkkGP9Ni1oxoN",
requested_access: [
new RequestedPermission("", IDENTITY_VIEW.vdxfid),
new RequestedPermission("", PROFILE_DATA_VIEW_REQUEST.vdxfid),
new RequestedPermission("", LOGIN_CONSENT_PERSONALINFO_WEBHOOK_VDXF_KEY.vdxfid),
new RequestedPermission(IDENTITY_VIEW.vdxfid, ""),
new RequestedPermission(PROFILE_DATA_VIEW_REQUEST.vdxfid, ""),
new RequestedPermission(LOGIN_CONSENT_PERSONALINFO_WEBHOOK_VDXF_KEY.vdxfid, ""),
],
redirect_uris: [],
subject: [new Subject(
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('Serializes and deserializes attestation request', () => {
},
challenge: {
challenge_id: "iKNufKJdLX3Xg8qFru9AuLBvivAEJ88PW4",
requested_access: [new RequestedPermission("", IDENTITY_VIEW.vdxfid)],
requested_access: [new RequestedPermission(IDENTITY_VIEW.vdxfid, "")],
session_id: "iRQZGW36o3RcVR1xyVT1qWdAKdxp3wUyrh",
redirect_uris: [
new RedirectUri(
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('Serializes and deserializes attestation request', () => {
},
challenge: {
challenge_id: "iKNufKJdLX3Xg8qFru9AuLBvivAEJ88PW4",
requested_access: [new RequestedPermission("", IDENTITY_VIEW.vdxfid)],
requested_access: [new RequestedPermission(IDENTITY_VIEW.vdxfid, "")],
session_id: "iRQZGW36o3RcVR1xyVT1qWdAKdxp3wUyrh",
redirect_uris: [
new RedirectUri(
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/vdxf/loginconsent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Serializes and deserializes signature objects properly', () => {
},
challenge: {
challenge_id: "iKNufKJdLX3Xg8qFru9AuLBvivAEJ88PW4",
requested_access: [new RequestedPermission("", IDENTITY_VIEW.vdxfid)],
requested_access: [new RequestedPermission(IDENTITY_VIEW.vdxfid, "")],
subject: [
new Subject(
"fully.qualified.name",
Expand Down Expand Up @@ -230,7 +230,7 @@ describe('Serializes and deserializes signature objects properly', () => {
},
challenge: {
challenge_id: "iKNufKJdLX3Xg8qFru9AuLBvivAEJ88PW4",
requested_access: [new RequestedPermission("", IDENTITY_VIEW.vdxfid)],
requested_access: [new RequestedPermission(IDENTITY_VIEW.vdxfid, "")],
session_id: "iRQZGW36o3RcVR1xyVT1qWdAKdxp3wUyrh",
redirect_uris: [
new RedirectUri(
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/vdxf/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('Parses VDXF objects correctly', () => {
},
challenge: {
challenge_id: "iKNufKJdLX3Xg8qFru9AuLBvivAEJ88PW4",
requested_access: [new RequestedPermission("", IDENTITY_VIEW.vdxfid)],
requested_access: [new RequestedPermission(IDENTITY_VIEW.vdxfid, "")],
subject: [
new Subject(
"fully.qualified.name",
Expand Down
4 changes: 3 additions & 1 deletion src/api/ApiPrimitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IdentityDefinition } from "../identity/IdentityDefinition";
import { OfferForMaking } from "../offers/OfferForMaking";
import { ListedOffer } from "../offers/OfferList";
import { RawTransaction } from "../transaction/RawTransaction";
import { signDataArgs } from "./classes/SignData/SignDataRequest";

export type ApiPrimitive =
| string
Expand All @@ -15,7 +16,8 @@ export type ApiPrimitive =
| Array<ApiPrimitive>
| IdentityDefinition
| BlockInfo
| RawTransaction;
| RawTransaction
| signDataArgs;

export type ApiPrimitiveJson = { [key: string]: ApiPrimitive | undefined };

Expand Down
55 changes: 55 additions & 0 deletions src/api/classes/SignData/SignDataRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { ApiRequest } from "../../ApiRequest";
import { ApiPrimitiveJson, RequestParams } from "../../ApiPrimitive";
import { SIGN_DATA } from "../../../constants/cmds";
import { DataDescriptor } from "../../../utils/types/DataDescriptor";
import { SignData } from "../../../utils/types/SignData";

export type signDataArgs = {
address?: string;
filename?: string;
message?: string;
messagehex?: string;
messsagebase64?: string;
datahash?: string;
vdxfdata?: string;
mmrdata?: Array<DataDescriptor | SignData>;
mmrsalt?: Array<string>;
mmrhashtype?: string;
priormmr?: Array<string>;
vdxfkeys?: Array<string>;
vdxfkeynames?: Array<string>;
boundhahses?: Array<string>;
hashtype?: string;
signature?: string;
encrypttoaddress?: string;
createmmr?: boolean;
}

export class SignDataRequest extends ApiRequest {
data: signDataArgs;

constructor(chain: string, signableItems: signDataArgs) {
super(chain, SIGN_DATA);
this.data = signableItems;
}

getParams(): RequestParams {
const params = [this.data];

return params.filter((x) => x != null);
}

static fromJson(object: ApiPrimitiveJson): SignDataRequest {
return new SignDataRequest(
object.chain as string,
object.data as signDataArgs
);
}

toJson(): ApiPrimitiveJson {
return {
chain: this.chain,
data: this.data,
};
}
}
24 changes: 24 additions & 0 deletions src/api/classes/SignData/SignDataResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ApiResponse } from "../../ApiResponse";
import { Signature } from "../../../utils/types/Signature";
import { mmrDescriptorParameters } from "../../../utils/types/MmrDescriptor";
import { DataDescriptor } from "../../../utils/types/DataDescriptor";

export class SignDataResponse extends ApiResponse {
result: {
mmrdescriptor_encrypted: mmrDescriptorParameters;
mmrdescriptor: mmrDescriptorParameters;
signature: string;
signaturedata_encrypted: DataDescriptor;
signaturedata_ssk: string;
signaturedata: Signature;
system: string;
systemid: string;
hashtype: string;
mmrhashtype: string;
hash: string;
identity: string;
canonicalname: string;
address: string;
signatureheight: number;
};
}
6 changes: 6 additions & 0 deletions src/api/classes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { SendRawTransactionRequest } from './SendRawTransaction/SendRawTransacti
import { SendRawTransactionResponse } from './SendRawTransaction/SendRawTransactionResponse'
import { SignMessageRequest } from './SignMessage/SignMessageRequest'
import { SignMessageResponse } from './SignMessage/SignMessageResponse'
import { SignDataRequest } from './SignData/SignDataRequest'
import { SignDataResponse } from './SignData/SignDataResponse'
import { VerifyMessageRequest } from './VerifyMessage/VerifyMessageRequest'
import { VerifyMessageResponse } from './VerifyMessage/VerifyMessageResponse'
import { GetAddressMempoolResponse } from './GetAddressMempool/GetAddressMempoolResponse'
Expand Down Expand Up @@ -70,6 +72,8 @@ export {
VerifyMessageResponse,
SignMessageRequest,
SignMessageResponse,
SignDataRequest,
SignDataResponse,
SendCurrencyRequest,
SendCurrencyResponse,
FundRawTransactionRequest,
Expand Down Expand Up @@ -98,6 +102,7 @@ export type RpcRequest =
| typeof GetRawTransactionRequest
| typeof VerifyMessageRequest
| typeof SignMessageRequest
| typeof SignDataRequest
| typeof SendCurrencyRequest
| typeof FundRawTransactionRequest
| typeof GetCurrencyConvertersRequest
Expand All @@ -120,6 +125,7 @@ export type RpcResponse =
| typeof GetRawTransactionResponse
| typeof VerifyMessageResponse
| typeof SignMessageResponse
| typeof SignDataResponse
| typeof SendCurrencyResponse
| typeof FundRawTransactionResponse
| typeof GetCurrencyConvertersResponse
Expand Down
1 change: 1 addition & 0 deletions src/constants/cmds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const GET_ADDRESS_MEMPOOL = 'getaddressmempool'
export const SEND_RAW_TRANSACTION = 'sendrawtransaction'
export const GET_ADDRESS_UTXOS = 'getaddressutxos'
export const SIGN_MESSAGE = 'signmessage'
export const SIGN_DATA = 'signdata'
export const VERIFY_MESSAGE = 'verifymessage'
export const FUND_RAW_TRANSACTION = 'fundrawtransaction'
export const SEND_CURRENCY = 'sendcurrency'
Expand Down
Loading

0 comments on commit 81dd6bc

Please sign in to comment.