Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature deputy access : 2.7.0-alpha1 #105

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itheum/sdk-mx-data-nft",
"version": "2.6.3",
"version": "2.7.0-alpha1",
"description": "SDK for Itheum's Data NFT Technology on MultiversX Blockchain",
"main": "out/index.js",
"types": "out/index.d.js",
Expand Down
26 changes: 25 additions & 1 deletion src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export function validateSpecificParamsViewData(params: {
fwdHeaderMapLookup?: any;
nestedIdxToStream?: number | undefined;
_fwdHeaderMapLookupMustContainBearerAuthHeader?: boolean | undefined;
asDeputyOnAppointerAddr?: string | undefined;
_mandatoryParamsList: string[]; // a pure JS fallback way to validate mandatory params, as typescript rules for mandatory can be bypassed by client app
}): {
allPassed: boolean;
Expand Down Expand Up @@ -390,6 +391,28 @@ export function validateSpecificParamsViewData(params: {
}
}

// asDeputyOnAppointerAddr test
let asDeputyOnAppointerAddrIsValid = true;

if (
params.asDeputyOnAppointerAddr !== undefined ||
params._mandatoryParamsList.includes('asDeputyOnAppointerAddr')
) {
asDeputyOnAppointerAddrIsValid = false;

if (
params.asDeputyOnAppointerAddr !== undefined &&
typeof params.asDeputyOnAppointerAddr === 'string' &&
params.asDeputyOnAppointerAddr.trim() !== '' &&
params.asDeputyOnAppointerAddr.length > 10
) {
asDeputyOnAppointerAddrIsValid = true;
} else {
validationMessages +=
'[asDeputyOnAppointerAddr needs to be a multiversx smart contract address in an string. e.g. erd1qqqqqqqqqqqqqpgqd2y9zvaehkn4arsjwxp8vs3rjmdwyffafsxsgjkdw8]';
}
}

if (
!signedMessageValid ||
!signableMessageValid ||
Expand All @@ -399,7 +422,8 @@ export function validateSpecificParamsViewData(params: {
!fwdHeaderMapLookupIsValid ||
!mvxNativeAuthMaxExpirySecondsValid ||
!mvxNativeAuthOriginsIsValid ||
!nestedIdxToStreamValid
!nestedIdxToStreamValid ||
!asDeputyOnAppointerAddrIsValid
) {
allPassed = false;
}
Expand Down
14 changes: 14 additions & 0 deletions src/datanft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export class DataNft implements DataNftType {
* @param fwdHeaderKeys [optional] Forward only selected headers to the Origin Data Stream server. Has priority over fwdAllHeaders param. A comma separated lowercase string with less than 5 items. e.g. cookie,authorization
* @param fwdHeaderMapLookup [optional] Used with fwdHeaderKeys to set a front-end client side lookup map of headers the SDK uses to setup the forward. e.g. { cookie : "xyz", authorization : "Bearer zxy" }. Note that these are case-sensitive and need to match fwdHeaderKeys exactly.
* @param nestedIdxToStream [optional] If you are accessing a "nested stream", this is the index of the nested item you want drill into and fetch
* @param asDeputyOnAppointerAddr [optional] Put caller in the "deputy persona" of this deputy appointer address (which should be a smart contract that holds the Data NFT Id)
*/
async viewData(p: {
signedMessage: string;
Expand All @@ -313,6 +314,7 @@ export class DataNft implements DataNftType {
[key: string]: any;
};
nestedIdxToStream?: number;
asDeputyOnAppointerAddr?: string;
}): Promise<ViewDataReturnType> {
DataNft.ensureNetworkConfigSet();
if (!this.dataMarshal) {
Expand All @@ -334,6 +336,7 @@ export class DataNft implements DataNftType {
fwdHeaderKeys: p.fwdHeaderKeys,
fwdHeaderMapLookup: p.fwdHeaderMapLookup,
nestedIdxToStream: p.nestedIdxToStream,
asDeputyOnAppointerAddr: p.asDeputyOnAppointerAddr,
_mandatoryParamsList: ['signedMessage', 'signableMessage']
});

Expand Down Expand Up @@ -409,6 +412,10 @@ export class DataNft implements DataNftType {
});
}
}

if (typeof p.asDeputyOnAppointerAddr !== 'undefined') {
url += `&asDeputyOnAppointerAddr=${p.asDeputyOnAppointerAddr}`;
}
// E: append optional params...

const response = await fetch(url, fetchConfig);
Expand Down Expand Up @@ -451,6 +458,7 @@ export class DataNft implements DataNftType {
* @param fwdAllHeaders [optional] Forward all request headers to the Origin Data Stream server.
* @param stream [optional] Instead of auto-downloading if possible, request if data should always be streamed or not.i.e true=stream, false/undefined=default behavior
* @param nestedIdxToStream [optional] If you are accessing a "nested stream", this is the index of the nested item you want drill into and fetch
* @param asDeputyOnAppointerAddr [optional] Put caller in the "deputy persona" of this deputy appointer address (which should be a smart contract that holds the Data NFT Id)
*/
async viewDataViaMVXNativeAuth(p: {
mvxNativeAuthOrigins: string[];
Expand All @@ -462,6 +470,7 @@ export class DataNft implements DataNftType {
fwdAllHeaders?: boolean;
stream?: boolean;
nestedIdxToStream?: number;
asDeputyOnAppointerAddr?: string;
}): Promise<ViewDataReturnType> {
try {
// S: run any format specific validation
Expand All @@ -473,6 +482,7 @@ export class DataNft implements DataNftType {
fwdAllHeaders: p.fwdAllHeaders,
stream: p.stream,
nestedIdxToStream: p.nestedIdxToStream,
asDeputyOnAppointerAddr: p.asDeputyOnAppointerAddr,
_fwdHeaderMapLookupMustContainBearerAuthHeader: true,
_mandatoryParamsList: [
'mvxNativeAuthOrigins',
Expand Down Expand Up @@ -570,6 +580,10 @@ export class DataNft implements DataNftType {
});
}
}

if (typeof p.asDeputyOnAppointerAddr !== 'undefined') {
url += `&asDeputyOnAppointerAddr=${p.asDeputyOnAppointerAddr}`;
}
// E: append optional params...

const response = await fetch(url, fetchConfig);
Expand Down
Loading