public Task Initialize(IServiceProvider serviceProvider, IConfigurationSection configuration) { byte versionByte = byte.Parse(configuration["version_byte"]); this.keyEncoder = new KeyEncoder(versionByte); P2pkhSubject[] adminAddresses = configuration .GetSection("admin_addresses") .GetChildren() .Select(key => key.Value) .Select(address => new P2pkhSubject(new[] { address }, 1, keyEncoder)) .ToArray(); List <Acl> pathPermissions = new List <Acl>() { // Admins have full rights new Acl(adminAddresses, LedgerPath.Parse("/"), true, StringPattern.MatchAll, PermissionSet.AllowAll) }; if (bool.Parse(configuration["allow_third_party_assets"])) { this.staticPermissionProviders.Add(new P2pkhIssuanceImplicitLayout(keyEncoder)); } if (bool.Parse(configuration["allow_p2pkh_accounts"])) { this.staticPermissionProviders.Add(new P2pkhImplicitLayout(keyEncoder)); } this.staticPermissionProviders.Add(new StaticPermissionLayout(pathPermissions)); return(Task.FromResult(0)); }
/// <summary> /// Parses a permission set from a JSON string. /// </summary> /// <param name="json">The JSON string to parse.</param> /// <param name="path">The path on which these permissions apply.</param> /// <param name="keyEncoder">The key encoder to use in the parsed <see cref="Acl"/> objects.</param> /// <returns>The parsed list of <see cref="Acl"/> objects.</returns> public static IReadOnlyList<Acl> Parse(string json, LedgerPath path, KeyEncoder keyEncoder) { JArray document = JArray.Parse(json); return ((IEnumerable<JToken>)document).Select(root => new Acl( ((JArray)root["subjects"]).Children().Select(subject => new P2pkhSubject(((JArray)subject["addresses"]).Select(key => (string)key), (int)subject["required"], keyEncoder)), path, (bool?)root["recursive"] ?? true, new StringPattern((string)root["record_name"] ?? string.Empty, (PatternMatchingStrategy)Enum.Parse(typeof(PatternMatchingStrategy), (string)root["record_name_matching"] ?? "Prefix")), new PermissionSet( accountNegative: Parse(root["permissions"]["account_negative"]), accountSpend: Parse(root["permissions"]["account_spend"]), accountModify: Parse(root["permissions"]["account_modify"]), accountCreate: Parse(root["permissions"]["account_create"]), dataModify: Parse(root["permissions"]["data_modify"])))) .ToList(); }
/// <summary> /// Parses a permission set from a JSON string. /// </summary> /// <param name="json">The JSON string to parse.</param> /// <param name="path">The path on which these permissions apply.</param> /// <param name="keyEncoder">The key encoder to use in the parsed <see cref="Acl"/> objects.</param> /// <returns>The parsed list of <see cref="Acl"/> objects.</returns> public static IReadOnlyList <Acl> Parse(string json, LedgerPath path, KeyEncoder keyEncoder) { JArray document = JArray.Parse(json); return(((IEnumerable <JToken>)document).Select(root => new Acl( ((JArray)root["subjects"]).Children().Select(subject => new P2pkhSubject(((JArray)subject["addresses"]).Select(key => (string)key), (int)subject["required"], keyEncoder)), path, (bool?)root["recursive"] ?? true, new StringPattern((string)root["record_name"] ?? string.Empty, (PatternMatchingStrategy)Enum.Parse(typeof(PatternMatchingStrategy), (string)root["record_name_matching"] ?? "Prefix")), new PermissionSet( accountNegative: Parse(root["permissions"]["account_negative"]), accountSpend: Parse(root["permissions"]["account_spend"]), accountModify: Parse(root["permissions"]["account_modify"]), accountCreate: Parse(root["permissions"]["account_create"]), dataModify: Parse(root["permissions"]["data_modify"])))) .ToList()); }
public P2pkhIssuanceImplicitLayout(KeyEncoder keyEncoder) { this.keyEncoder = keyEncoder; }
public P2pkhImplicitLayout(KeyEncoder keyEncoder) { this.keyEncoder = keyEncoder; }
public P2pkhSubject(IEnumerable<string> addresses, int signaturesRequired, KeyEncoder keyEncoder) { this.Addresses = addresses.ToList().AsReadOnly(); this.SignaturesRequired = signaturesRequired; this.keyEncoder = keyEncoder; }
public P2pkhSubject(IEnumerable <string> addresses, int signaturesRequired, KeyEncoder keyEncoder) { this.Addresses = addresses.ToList().AsReadOnly(); this.SignaturesRequired = signaturesRequired; this.keyEncoder = keyEncoder; }
public DynamicPermissionLayout(IStorageEngine store, KeyEncoder keyEncoder) { this.store = store; this.keyEncoder = keyEncoder; }